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
Desktop: New Project places the Product Manager only where its engine can run, and says why when none can (#2208)
0xken15fedb831e3ab2
diff --git a/desktop/lib/state/harness_launch_integration.dart b/desktop/lib/state/harness_launch_integration.dartindex a4bedbeb9..f1baa10cc 100644--- a/desktop/lib/state/harness_launch_integration.dart+++ b/desktop/lib/state/harness_launch_integration.dart@@ -86,7 +86,11 @@ class HarnessLaunchIntegration {/// With [leadMachines]: the Swarm's model list for its engine and model.LeadModelList? leadModels;- final Future<String> Function(String machineId, String task) prepare;++ /// Before anything is created: the prompt for [task], which a destination+ /// may refuse for [machineId] and [engine], the engine about to start.+ final Future<String> Function(String machineId, String task, String engine)+ prepare;final Future<void> Function(String machineId, String harnessId) complete;final Future<void> Function(String machineId, String creationId) beforeSubmit;Future<void> Function()? resume;diff --git a/desktop/lib/state/lead_placement.dart b/desktop/lib/state/lead_placement.dartindex 3c85b9286..268c3da96 100644--- a/desktop/lib/state/lead_placement.dart+++ b/desktop/lib/state/lead_placement.dart@@ -14,6 +14,7 @@ class LeadMachine {this.own = true,this.native = true,this.team = false,+ this.engineRefusals = const {},});final String id, name;final bool online;@@ -50,12 +51,76 @@ class LeadMachine {/// Why the Product Manager cannot start here whatever its state, or null.final String? unavailable;+ /// Why an engine cannot run a Product Manager here (not offered to the+ /// Swarm, not installed or signed in, no quota left, suspended), by engine.+ /// An engine not in it runs.+ final Map<String, String> engineRefusals;++ bool runs(String engine) => !engineRefusals.containsKey(engine);++ /// The Product Manager engines it runs, in [kLeadEngines] order.+ List<String> get leadEngines => [+ for (final engine in kLeadEngines)+ if (runs(engine)) engine,+ ];+bool has(String? repository) {final key = leadRepositoryKey(repository);return key != null && repositories.contains(key);}- bool get startable => unavailable == null && online && (freeAgents ?? 1) > 0;+ /// It can start a Product Manager now, with one of [leadEngines].+ bool get startable =>+ unavailable == null &&+ online &&+ (freeAgents ?? 1) > 0 &&+ leadEngines.isNotEmpty;+}++/// The engines a Product Manager runs on: routing reads quota for these two.+const kLeadEngines = ['claude', 'codex'];++/// A Product Manager engine's name as people read it.+String leadEngineLabel(String engine) =>+ const {'claude': 'Claude Code', 'codex': 'Codex'}[engine] ?? engine;++/// Why each of [kLeadEngines] cannot run a Product Manager on a machine, from+/// what the Swarm reads of it: the engines it offers the Swarm ([offered],+/// null when not reported), each engine's install and sign-in as its host+/// reported them ([readiness], null for not known), its subscription windows'+/// use ([usedPercents], absent when unread) and the engines the server+/// suspended there after failed starts ([suspended], with why). What is not+/// known does not rule an engine out, as the route does not.+Map<String, String> leadEngineRefusals({+ Set<String>? offered,+ Map<String, ({bool? installed, bool? signedIn})> readiness = const {},+ Map<String, List<num>> usedPercents = const {},+ Map<String, String> suspended = const {},+}) => {+ for (final engine in kLeadEngines)+ engine: ?_engineRefusal(+ leadEngineLabel(engine),+ offered: offered == null || offered.contains(engine),+ readiness: readiness[engine],+ used: usedPercents[engine] ?? const [],+ suspended: suspended[engine],+ ),+};++String? _engineRefusal(+ String label, {+ required bool offered,+ required ({bool? installed, bool? signedIn})? readiness,+ required List<num> used,+ required String? suspended,+}) {+ if (!offered) return '$label isn’t offered here';+ if (readiness?.installed == false) return '$label isn’t installed';+ if (readiness?.signedIn == false) return '$label isn’t signed in';+ if (used.any((percent) => percent >= 100)) {+ return '$label has no quota left until it resets';+ }+ return suspended;}/// One repository however its remote is spelled: `host/owner/name`, lower@@ -86,7 +151,7 @@ List<LeadMachine> rankLeadMachines() {int tier(LeadMachine m) => m.startable? 0- : m.unavailable == null && m.online+ : m.unavailable == null && m.online && m.leadEngines.isNotEmpty? 1: m.online? 2@@ -119,10 +184,42 @@ LeadMachine? bestLeadMachine(repository,).where((m) => m.startable).firstOrNull;+/// Where the Product Manager starts and with which engine, or null when no+/// machine can start it now. Never a machine that cannot run the engine it+/// proposes. Your own machines come first: among them the best that runs+/// [engine], else the best with another engine, unless the person chose+/// [engine] ([engineChosen]); then a teammate's the same way.+({LeadMachine machine, String engine})? bestLeadPlacement(+ Iterable<LeadMachine> machines,+ String? repository, {+ required String engine,+ bool engineChosen = false,+}) {+ final ready = rankLeadMachines(+ machines,+ repository,+ ).where((m) => m.startable).toList();+ for (final own in [true, false]) {+ final group = ready.where((m) => m.own == own);+ if (group.where((m) => m.runs(engine)).firstOrNull case final machine?) {+ return (machine: machine, engine: engine);+ }+ final other = engineChosen ? null : group.firstOrNull;+ if (other != null) {+ return (machine: other, engine: other.leadEngines.first);+ }+ }+ return null;+}+/// A machine's row detail, in words, so colour is never the only signal.String leadMachineDetail(LeadMachine machine, String? repository) {if (machine.unavailable case final why?) return why;if (!machine.online) return 'Offline';+ if (machine.leadEngines.isEmpty) {+ return 'Can’t run a Product Manager: '+ '${[for (final engine in kLeadEngines) ?machine.engineRefusals[engine]].join(', ')}';+ }final free = machine.freeAgents;if (free == null) return 'Online · Not in this Swarm';return [diff --git a/desktop/lib/state/new_harness.dart b/desktop/lib/state/new_harness.dartindex a8228b7b8..89ff34063 100644--- a/desktop/lib/state/new_harness.dart+++ b/desktop/lib/state/new_harness.dart@@ -1594,15 +1594,49 @@ class NewHarnessController extends ChangeNotifier {machines.isNotEmpty &&machines.every((m) => m.unavailable == kLeadSwarmPaused);+ /// The person chose the Product Manager's engine under Advanced: placement+ /// keeps it rather than switching to one a machine runs.+ bool _leadEngineChosen = false;++ /// Where the Product Manager starts and with which engine, or null.+ ({LeadMachine machine, String engine})? _leadPlacement(+ List<LeadMachine> machines,+ ) => bestLeadPlacement(+ machines,+ cloudRepository,+ engine: _engine,+ engineChosen: _leadEngineChosen,+ );++ /// [machine] could take the Product Manager once it is online and has room.+ bool _leadWaitsFor(LeadMachine machine) =>+ machine.unavailable == null &&+ (_leadEngineChosen+ ? machine.runs(_engine)+ : machine.leadEngines.isNotEmpty);++ bool _leadUnplaced(List<LeadMachine> machines) =>+ _swarmLeadMachine == null &&+ leadMachine?.startable != true &&+ !_paused(machines) &&+ _leadPlacement(machines) == null;+/// No machine can take the Product Manager now: New Project asks the/// Swarm to start it on the first one that frees up.bool get leadQueued {final machines = integration?.leadMachines;return machines != null &&- _swarmLeadMachine == null &&- leadMachine?.startable != true &&- !_paused(machines) &&- bestLeadMachine(machines, cloudRepository) == null;+ _leadUnplaced(machines) &&+ machines.any(_leadWaitsFor);+ }++ /// No machine could run the Product Manager even with room: each is+ /// another person's, or runs no engine it can start with.+ bool get leadNone {+ final machines = integration?.leadMachines;+ return machines != null &&+ _leadUnplaced(machines) &&+ !machines.any(_leadWaitsFor);}/// The Swarm starts the Product Manager, on [leadSwarmMachine] or the first@@ -1625,8 +1659,7 @@ class NewHarnessController extends ChangeNotifier {null => null,};- /// The Product Manager line: where it starts, its engine and model, and a- /// repo cloned there first.+ /// The Product Manager line: where it starts, its engine and model.String get leadLine {if (leadQueued) {return 'All Swarm machines are busy. The project starts on the first '@@ -1638,16 +1671,17 @@ class NewHarnessController extends ChangeNotifier {: target.team? '${target.name}’s Team account': target.name;+ return ['Product Manager on $name', agentLabel, leadModelLabel].join(' · ');+ }++ /// Under [leadLine]: the repo that machine clones first, or null.+ String? get leadCloneNote {+ if (leadQueued || _leadRepositoryName == null) return null;+ final target = leadMachine;final clones = leadThroughSwarm? target != null && !target.has(leadRepositoryUrl): _project.repository != null;- return [- 'Product Manager: $name',- agentLabel,- leadModelLabel,- if (clones && _leadRepositoryName != null)- '$_leadRepositoryName will be cloned there',- ].join(' · ');+ return clones ? 'Clones $_leadRepositoryName there first' : null;}/// Why New Project cannot start its Product Manager now, or null.@@ -1657,10 +1691,16 @@ class NewHarnessController extends ChangeNotifier {if (_paused(machines)) {return '$kLeadSwarmPaused. New Project can start once it resumes.';}+ if (leadNone) return 'No machine can run the Product Manager now.';if (leadMachine?.startable != true && !leadQueued) {final name = leadMachine?.name ?? machineLabel;return '$name cannot start the Product Manager. Choose another machine.';}+ final refusal = leadQueued ? null : leadMachine?.engineRefusals[_engine];+ if (refusal != null) {+ return '${leadMachine!.name} can’t run $agentLabel: $refusal. '+ 'Choose another engine under Advanced.';+ }if (leadThroughSwarm) {if (leadRepositoryUrl == null) {return 'Choose a repo with a remote, so the Swarm can clone it for '@@ -1674,14 +1714,27 @@ class NewHarnessController extends ChangeNotifier {return _leadModelListRefusal;}- /// Moves the Product Manager to the best machine the Swarm lists, unless- /// it is already there; with none free, it waits ([leadQueued]).+ /// Moves the Product Manager to the best machine the Swarm lists with an+ /// engine it runs there, unless it is already so placed; with none free,+ /// it waits ([leadQueued]).void placeLead() {final machines = integration?.leadMachines;if (machines == null || locked) return;- final best = bestLeadMachine(machines, cloudRepository);- if (best == null || best.id == leadMachine?.id) return;- chooseLeadMachine(best.id);+ final placed = _leadPlacement(machines);+ if (placed == null) return;+ if (placed.engine != _engine) _placeLeadEngine(placed.engine);+ if (placed.machine.id != leadMachine?.id) {+ chooseLeadMachine(placed.machine.id);+ } else {+ notifyListeners();+ }+ }++ /// The engine placement picked, as a choice the person did not make.+ void _placeLeadEngine(String engine) {+ final touched = _selectionTouched;+ _selectEngine(engine);+ _selectionTouched = touched;}/// Starts the Product Manager on [id], a machine the list can start it on@@ -1692,6 +1745,11 @@ class NewHarnessController extends ChangeNotifier {final listed = integration?.leadMachines?.where((m) => m.id == id).firstOrNull;+ // The machine chosen last wins over an engine it cannot run.+ if (listed != null && listed.startable && !listed.runs(_engine)) {+ _leadEngineChosen = false;+ _placeLeadEngine(listed.leadEngines.first);+ }if (listed != null && listed.startable && !listed.native) {error = null;_swarmLeadMachine = id;@@ -2532,6 +2590,10 @@ class NewHarnessController extends ChangeNotifier {}case NewHarnessField.agent:_selectEngine(option.id);+ if (placesLead) {+ _leadEngineChosen = true;+ if (leadMachine?.runs(_engine) == false) placeLead();+ }case NewHarnessField.model:_model = option.model;_modelTouched = true;@@ -4161,6 +4223,9 @@ class NewHarnessController extends ChangeNotifier {);}if (isCloud) return _createCloud();+ // Whoever starts it, New Project never starts a Product Manager the+ // placement says cannot run.+ if (placesLead && leadBlocked != null) return _fail(leadBlocked!);if (leadThroughSwarm) return _startInSwarm();if (!checking) {_syncGitProject();@@ -4327,7 +4392,7 @@ class NewHarnessController extends ChangeNotifier {if (integration case final destination?) {try {launchMessage = destination.preparedPrompt ??= await destination- .prepare(_machineId, firstMessage);+ .prepare(_machineId, firstMessage, base);} catch (failure) {return _fail(failure.toString());}diff --git a/desktop/lib/super_tabs/launch.dart b/desktop/lib/super_tabs/launch.dartindex d2c791f9b..37b47f601 100644--- a/desktop/lib/super_tabs/launch.dart+++ b/desktop/lib/super_tabs/launch.dart@@ -18,6 +18,7 @@ import 'machine_icon.dart';import 'machine_status.dart';import 'model.dart';import 'launch_prompt.dart';+import 'identity.dart' show superTabPersonName;/// Captures a conversation before opening New Harness. Its journal survives a/// closed form or process; a recovered launch only reads the native receipt.@@ -111,7 +112,11 @@ class SuperTabLaunch {// its answer decides, not a fresh check.if (start.machineId case final machine?when saved['leadStartRequest'] == null) {- await launch.recheckLeadMachine(integration, machine);+ await launch.recheckLeadMachine(+ integration,+ machine,+ engine: start.engine,+ );}await launch.startInSwarm(start);} on SuperTabFailure catch (failure) {@@ -155,9 +160,13 @@ class SuperTabLaunch {projectVisibilityLocked:saved['projectPrepared'] == true ||saved['creationRequest'] != null,- prepare: (machine, task) async {+ prepare: (machine, task, engine) async {if (integration.leadMachines != null) {- await launch.recheckLeadMachine(integration, machine);+ await launch.recheckLeadMachine(+ integration,+ machine,+ engine: engine,+ );}if (integration.roles != null) {final chosen = integration.roles!@@ -323,6 +332,41 @@ class SuperTabLaunch {final running = observation['runningHarnessIds'];final max = reading['maxAgents'];final checkouts = part(observation['readiness'])['checkouts'];+ final engineRefusals = leadEngineRefusals(+ offered: switch (reading['engines']) {+ final List engines => engines.whereType<String>().toSet(),+ _ => null,+ },+ readiness: {+ for (final raw+ in part(observation['readiness'])['engines'] as List? ?? const [])+ if (part(raw) case {'engine': final String engine} && final row)+ engine: (+ installed: row['installed'] as bool?,+ signedIn: row['signedIn'] as bool?,+ ),+ },+ usedPercents: {+ for (final raw in observation['quotas'] as List? ?? const [])+ if (part(raw) case {+ 'engine': final String engine,+ 'known': true,+ 'windows': final List windows,+ })+ engine: [+ for (final window in windows)+ if (part(window)['usedPercent'] case final num used) used,+ ],+ },+ // Read by servers with engine health (#2192); absent before.+ suspended: {+ for (final source in [pool, reading])+ if (source['suspendedEngines'] case final Map raw)+ for (final MapEntry(:key, :value) in raw.entries)+ if ((key, value) case (final String engine, final String why))+ engine: why,+ },+ );final device = part(observation['resources'])['deviceType'];return LeadMachine(id: id,@@ -370,6 +414,7 @@ class SuperTabLaunch {own: own,native: own && connected,team: team,+ engineRefusals: engineRefusals,unavailable: snapshot.paused? kLeadSwarmPaused: own@@ -379,8 +424,15 @@ class SuperTabLaunch {? null: 'Not connected to this computer'): !team- ? '$name has no Harness Team account yet, so it runs only its '- 'owner’s projects.'+ ? switch (snapshot.people+ .where((person) => person.id == pool['contributorId'])+ .firstOrNull) {+ final person? =>+ '${superTabPersonName(person.email)}’s personal account: '+ 'runs only ${superTabPersonName(person.email)}’s '+ 'projects. $_yoursNeed',+ null => '$name runs only its owner’s projects. $_yoursNeed',+ }: switch (reading['teamWork']) {{'allowed': false, 'reason': final String reason} => reason,_ when !capable =>@@ -410,6 +462,18 @@ class SuperTabLaunch {freeAgents: null,inSwarm: false,unavailable: snapshot.paused ? kLeadSwarmPaused : null,+ // The Swarm reads nothing of it: this computer's own probe says+ // which engines are there. One that installs on Create runs.+ engineRefusals: leadEngineRefusals(+ readiness: {+ for (final engine in kLeadEngines)+ if (state.engines[engine] case final known?)+ engine: (+ installed: known.installed || known.installable,+ signedIn: known.signedIn,+ ),+ },+ ),),], null);}@@ -433,8 +497,9 @@ class SuperTabLaunch {/// With no fresh read nothing is created, since the machine is unchecked.Future<void> recheckLeadMachine(HarnessLaunchIntegration integration,- String machine,- ) async {+ String machine, {+ String? engine,+ }) async {final name =integration.leadMachines?.where((m) => m.id == machine)@@ -460,7 +525,7 @@ class SuperTabLaunch {}checkAccount();integration.leadMachines = leadMachinesOf(fresh);- checkLeadMachine(integration.leadMachines!, machine);+ checkLeadMachine(integration.leadMachines!, machine, engine: engine);}/// The upload a Swarm-started Product Manager's files take, in tests.@@ -584,7 +649,13 @@ class SuperTabLaunch {failure.statusCode != 429;/// Refuses a machine the list cannot start the Product Manager on now.- void checkLeadMachine(List<LeadMachine> machines, String machine) {+ /// Refuses [machine] when it cannot start the Product Manager now, with+ /// [engine] when it is known.+ void checkLeadMachine(+ List<LeadMachine> machines,+ String machine, {+ String? engine,+ }) {final chosen = machines.where((m) => m.id == machine).firstOrNull;if (chosen == null) {throw const SuperTabFailure(@@ -592,14 +663,21 @@ class SuperTabLaunch {'Choose one of this Swarm’s machines.',);}- if (chosen.startable) return;+ final refusal = engine == null ? null : chosen.engineRefusals[engine];+ if (chosen.startable && refusal == null) return;throw SuperTabFailure('MACHINE_UNAVAILABLE',chosen.unavailable != null? '${chosen.name}: ${chosen.unavailable}. Choose another machine.': !chosen.online? '${chosen.name} is offline. Choose another machine.'- : '${chosen.name} has no free agents. Choose another machine.',+ : chosen.leadEngines.isEmpty+ ? '${chosen.name}: ${leadMachineDetail(chosen, null)}. '+ 'Choose another machine.'+ : !chosen.startable+ ? '${chosen.name} has no free agents. Choose another machine.'+ : '${chosen.name} can’t run ${leadEngineLabel(engine!)}: $refusal. '+ 'Choose another engine under Advanced.',);}@@ -1007,3 +1085,6 @@ class SuperTabLaunch {checkAccount();}}++/// Where a teammate's project's Product Manager may run instead.+const _yoursNeed = 'Yours need your own computer or a Team account machine';diff --git a/desktop/lib/widgets/new_harness_form.dart b/desktop/lib/widgets/new_harness_form.dartindex 08abd5585..119b3e759 100644--- a/desktop/lib/widgets/new_harness_form.dart+++ b/desktop/lib/widgets/new_harness_form.dart@@ -2159,19 +2159,34 @@ class NewHarnessFormState extends State<NewHarnessForm> {textStyle: DesktopChrome.text(size: 12, medium: true),);- /// "Product Manager: Mac Studio · Claude Code · Opus 5.5 · Change", or why- /// New Project waits.+ /// "Product Manager on Mac Studio · Claude Code · Opus 5.5 Change", the+ /// repo cloned there first under it, or why New Project waits.Widget _desktopLeadLine() {final blocked = box.leadBlocked;+ final note = blocked == null ? box.leadCloneNote : null;+ final muted = DesktopChrome.text(size: 12, color: DesktopChrome.muted);return Row(key: const ValueKey('new-harness-lead-line'),children: [Flexible(- child: Text(- blocked ?? box.leadLine,- maxLines: 2,- overflow: TextOverflow.ellipsis,- style: DesktopChrome.text(size: 12, color: DesktopChrome.muted),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ blocked ?? box.leadLine,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: muted,+ ),+ if (note != null)+ Text(+ note,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: muted,+ ),+ ],),),const SizedBox(width: 4),@@ -2185,7 +2200,8 @@ class NewHarnessFormState extends State<NewHarnessForm> {onPressed: box.locked? null: () => setState(() => _leadOpen = !_leadOpen),- child: const Text('Change'),+ // With no machine able to run it, the list says why for each.+ child: Text(box.leadNone ? 'See why' : 'Change'),),),),@@ -2326,54 +2342,64 @@ class NewHarnessFormState extends State<NewHarnessForm> {selected: chosen,label: '${machine.name}, $detail',excludeSemantics: true,- child: InkWell(- onTap: enabled ? () => box.chooseLeadMachine(machine.id) : null,- mouseCursor: enabled- ? SystemMouseCursors.click- : SystemMouseCursors.basic,- borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),- hoverColor: DesktopChrome.selection,- focusColor: DesktopChrome.selection,- child: Padding(- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),- child: Row(- children: [- SuperTabMachineDot(- status: machine.online- ? SuperTabMachineStatus.live- : SuperTabMachineStatus.offline,- ),- const SizedBox(width: 10),- Expanded(- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- machine.name,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: DesktopChrome.text(- size: 13,- color: enabled- ? DesktopChrome.foreground- : DesktopChrome.muted,+ // A greyed-out machine also says why on hover; its label says it to+ // accessibility already.+ child: Tooltip(+ message: machine.startable ? '' : detail,+ excludeFromSemantics: true,+ child: InkWell(+ onTap: enabled ? () => box.chooseLeadMachine(machine.id) : null,+ mouseCursor: enabled+ ? SystemMouseCursors.click+ : SystemMouseCursors.basic,+ borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),+ hoverColor: DesktopChrome.selection,+ focusColor: DesktopChrome.selection,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),+ child: Row(+ children: [+ SuperTabMachineDot(+ status: machine.online+ ? SuperTabMachineStatus.live+ : SuperTabMachineStatus.offline,+ ),+ const SizedBox(width: 10),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ machine.name,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: DesktopChrome.text(+ size: 13,+ color: enabled+ ? DesktopChrome.foreground+ : DesktopChrome.muted,+ ),),- ),- Text(- detail,- style: DesktopChrome.text(- size: 12,- color: DesktopChrome.muted,+ Text(+ detail,+ style: DesktopChrome.text(+ size: 12,+ color: DesktopChrome.muted,+ ),),- ),- ],+ ],+ ),),- ),- if (chosen) ...[- const SizedBox(width: 8),- Icon(AppIcons.check, size: 16, color: DesktopChrome.accent),+ if (chosen) ...[+ const SizedBox(width: 8),+ Icon(+ AppIcons.check,+ size: 16,+ color: DesktopChrome.accent,+ ),+ ],],- ],+ ),),),),diff --git a/desktop/test/lead_placement_test.dart b/desktop/test/lead_placement_test.dartindex 637512cd2..e258159b7 100644--- a/desktop/test/lead_placement_test.dart+++ b/desktop/test/lead_placement_test.dart@@ -11,6 +11,8 @@ LeadMachine _machine(bool maySleep = false,String? unavailable,bool inSwarm = true,+ bool own = true,+ Map<String, String> engineRefusals = const {},}) => LeadMachine(id: id,name: id,@@ -20,8 +22,12 @@ LeadMachine _machine(maySleep: maySleep,unavailable: unavailable,inSwarm: inSwarm,+ own: own,+ engineRefusals: engineRefusals,);+const _claudeOff = {'claude': 'Claude Code isn’t offered here'};+void main() {group('leadRepositoryKey', () {test('reads HTTPS, SSH and bare remotes as one repository', () {@@ -169,4 +175,51 @@ void main() {},);});++ group('bestLeadPlacement', () {+ test('never proposes Claude Code on a machine offering only Codex', () {+ // The rig ranks first (always on, more room), but cannot run Claude.+ final rig = _machine('rig', free: 14, engineRefusals: _claudeOff);+ final laptop = _machine('laptop', free: 2, maySleep: true);+ final placed = bestLeadPlacement([rig, laptop], _repo, engine: 'claude');+ expect((placed?.machine.id, placed?.engine), ('laptop', 'claude'));+ });++ test('switches to an engine the best machine runs when none runs the '+ 'chosen one', () {+ final rig = _machine('rig', engineRefusals: _claudeOff);+ final placed = bestLeadPlacement([rig], _repo, engine: 'claude');+ expect((placed?.machine.id, placed?.engine), ('rig', 'codex'));+ });++ test('an engine the person chose stays: no machine runs it, no place', () {+ final rig = _machine('rig', engineRefusals: _claudeOff);+ expect(+ bestLeadPlacement([rig], _repo, engine: 'claude', engineChosen: true),+ isNull,+ );+ });++ test('your own machine with another engine before a teammate’s with the '+ 'chosen one', () {+ final rig = _machine('rig', engineRefusals: _claudeOff);+ final theirs = _machine('team', own: false, free: 30);+ final placed = bestLeadPlacement([theirs, rig], _repo, engine: 'claude');+ expect((placed?.machine.id, placed?.engine), ('rig', 'codex'));+ });++ test('a machine that runs no Product Manager engine is not startable', () {+ final rig = _machine(+ 'rig',+ engineRefusals: const {+ 'claude': 'Claude Code isn’t offered here',+ 'codex': 'Codex isn’t signed in',+ },+ );+ expect(rig.startable, isFalse);+ expect(rig.runs('codex'), isFalse);+ expect(bestLeadPlacement([rig], _repo, engine: 'claude'), isNull);+ expect(bestLeadMachine([rig], _repo), isNull);+ });+ });}diff --git a/desktop/test/super_tab_launch_test.dart b/desktop/test/super_tab_launch_test.dartindex df2354d2d..4aae65492 100644--- a/desktop/test/super_tab_launch_test.dart+++ b/desktop/test/super_tab_launch_test.dart@@ -4,6 +4,7 @@ import 'dart:typed_data';import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';+import 'package:harness/core/engine_availability.dart';import 'package:harness/core/first_task.dart';import 'package:harness/core/models.dart';import 'package:harness/core/project_folder.dart';@@ -560,7 +561,7 @@ void main() {),);await expectLater(- box.integration!.prepare('m', 'Start work'),+ box.integration!.prepare('m', 'Start work', box.engine),throwsA(isA<SuperTabFailure>().having((e) => e.code,@@ -824,7 +825,7 @@ void main() {('has no Team account',[machineRow('rig', '2x 4090 Rig', lead: true)],- '2x 4090 Rig has no Harness Team account yet, so it runs only its owner’s projects.',+ 'diego’s personal account: runs only diego’s projects. Yours need your own computer or a Team account machine',),('fails its Team account’s privacy check',@@ -922,6 +923,254 @@ void main() {if ((post['command'] as Map)['type'] == type) post['command'] as Map,];+ /// This computer, outside the Swarm, has neither engine installed.+ void noLocalEngines(SuperTabLaunchFixture f) =>+ f.app.machineStates['m']!.engines.replace(const [+ EngineAvailability(engine: 'claude', installed: false),+ EngineAvailability(engine: 'codex', installed: false),+ ]);++ /// [row] offering the Swarm only [engines], with what its host reported+ /// about each engine's install and sign-in.+ Map<String, dynamic> offering(+ Map<String, dynamic> row,+ List<String> engines, {+ List<Map<String, dynamic>> readiness = const [],+ List<Map<String, dynamic>> quotas = const [],+ Map<String, String>? suspended,+ }) => {+ ...row,+ 'engines': engines,+ 'suspendedEngines': ?suspended,+ 'observation': {+ ...row['observation'] as Map<String, dynamic>,+ 'readiness': {'engines': readiness},+ 'quotas': quotas,+ },+ };++ test('each machine says which Product Manager engines it cannot run, and '+ 'why', () async {+ final f = SuperTabLaunchFixture();+ f.connection.server.state['machines'] = [+ offering(+ machineRow('rig', '2x 4090 Rig', contributor: 'owner', lead: true),+ ['codex'],+ readiness: [+ {'engine': 'claude', 'installed': null, 'signedIn': null},+ {'engine': 'codex', 'installed': true, 'signedIn': false},+ ],+ ),+ offering(+ machineRow('mini', 'Office Mini', contributor: 'owner', lead: true),+ ['claude', 'codex'],+ readiness: [+ {'engine': 'claude', 'installed': false, 'signedIn': null},+ ],+ quotas: [+ {+ 'engine': 'codex',+ 'known': true,+ 'windows': [+ {'name': 'weekly', 'usedPercent': 100},+ ],+ },+ ],+ ),+ offering(+ machineRow('m', 'Mac Studio', contributor: 'owner'),+ ['claude', 'codex'],+ quotas: [+ {'engine': 'codex', 'known': false, 'windows': <Map>[]},+ ],+ suspended: {'claude': 'Claude Code failed to start 3 times here.'},+ ),+ ];+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');+ final box = await f.box(newProject: true);+ LeadMachine row(String id) =>+ box.integration!.leadMachines!.where((m) => m.id == id).single;+ expect(row('rig').engineRefusals, {+ 'claude': 'Claude Code isn’t offered here',+ 'codex': 'Codex isn’t signed in',+ });+ expect(row('rig').startable, isFalse);+ expect(row('mini').engineRefusals, {+ 'claude': 'Claude Code isn’t installed',+ 'codex': 'Codex has no quota left until it resets',+ });+ // An unread allowance does not rule Codex out: the route takes it too.+ expect(row('m').engineRefusals, {+ 'claude': 'Claude Code failed to start 3 times here.',+ });+ expect(row('m').startable, isTrue);+ });++ test(+ 'a machine offering only Codex is never proposed with Claude Code',+ () async {+ Future<NewHarnessController> place(+ List<Map<String, dynamic>> rows,+ ) async {+ final f = SuperTabLaunchFixture();+ noLocalEngines(f);+ knownRepo(f);+ f.connection.server.state['machines'] = rows;+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');+ final box = await f.box(newProject: true, engine: 'claude');+ box.placeLead();+ return box;+ }++ final rig = offering(+ machineRow('rig', '2x 4090 Rig', contributor: 'owner', lead: true),+ ['codex'],+ );+ // Alone, the rig takes the PM with Codex.+ var box = await place([rig]);+ expect((box.leadMachine?.id, box.engine), ('rig', 'codex'));+ expect(box.leadBlocked, isNull);+ // With your Mac Studio running Claude Code, Claude Code stays.+ box = await place([+ rig,+ offering(machineRow('m', 'Mac Studio', contributor: 'owner'), [+ 'claude',+ 'codex',+ ]),+ ]);+ expect((box.leadMachine?.id, box.engine), ('m', 'claude'));+ expect(box.leadBlocked, isNull);+ },+ );++ test('with no machine able to run a PM, New Project says why and how to '+ 'fix it', () async {+ final f = SuperTabLaunchFixture();+ noLocalEngines(f);+ f.connection.server.state['machines'] = [+ offering(+ machineRow('rig', '2x 4090 Rig', contributor: 'owner', lead: true),+ ['codex'],+ readiness: [+ {'engine': 'codex', 'installed': true, 'signedIn': false},+ ],+ ),+ ];+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');+ final box = await f.box(newProject: true, engine: 'claude');+ box.placeLead();+ expect(box.leadQueued, isFalse);+ expect(box.leadNone, isTrue);+ expect(box.leadBlocked, 'No machine can run the Product Manager now.');+ expect(await box.create(), NewHarnessOutcome.failed);+ });++ test('an engine chosen under Advanced moves the PM to a machine that runs '+ 'it, or says why none does', () async {+ final f = SuperTabLaunchFixture();+ noLocalEngines(f);+ f.connection.server.state['machines'] = [+ offering(+ machineRow('rig', '2x 4090 Rig', contributor: 'owner', lead: true),+ ['codex'],+ ),+ ];+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');+ knownRepo(f);+ final box = await f.box(newProject: true, engine: 'codex');+ box.placeLead();+ expect(box.leadMachine?.id, 'rig');+ box.focusField(NewHarnessField.agent);+ box.accept(box.options.where((o) => o.id == 'claude').single);+ expect(box.engine, 'claude');+ expect(+ box.leadBlocked,+ '2x 4090 Rig can’t run Claude Code: Claude Code isn’t offered here. '+ 'Choose another engine under Advanced.',+ );+ });++ for (final (what, engines, readiness, error) in [+ (+ 'its engine signed out',+ ['codex'],+ [+ {'engine': 'codex', 'installed': true, 'signedIn': false},+ ],+ '2x 4090 Rig: Can’t run a Product Manager: Claude Code isn’t offered '+ 'here, Codex isn’t signed in. Choose another machine.',+ ),+ (+ 'stopped offering its engine',+ ['claude'],+ <Map<String, dynamic>>[],+ '2x 4090 Rig can’t run Codex: Codex isn’t offered here. Choose another '+ 'engine under Advanced.',+ ),+ ]) {+ test(+ 'New Project refuses a machine that has $what since the box opened',+ () async {+ final f = SuperTabLaunchFixture();+ noLocalEngines(f);+ knownRepo(f);+ Map<String, dynamic> rig(+ List<String> engines,+ List<Map<String, dynamic>> readiness,+ ) => offering(+ machineRow('rig', '2x 4090 Rig', contributor: 'owner', lead: true),+ engines,+ readiness: readiness,+ );+ f.connection.server.state['machines'] = [+ rig(['codex'], const []),+ ];+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');+ final box = await f.box(newProject: true, engine: 'codex');+ box.placeLead();+ expect((box.leadMachine?.id, box.leadBlocked), ('rig', null));+ f.connection.server.state['machines'] = [rig(engines, readiness)];+ expect(await box.create(), NewHarnessOutcome.failed);+ expect(box.error, error);+ expect(commandsOf(f, 'project.create'), isEmpty);+ },+ );+ }++ test('New Project started by this computer refuses its machine when the '+ 'chosen engine signed out since the box opened', () async {+ final f = SuperTabLaunchFixture();+ knownRepo(f);+ // Your Mac Studio, connected to this Desktop: it starts the PM itself.+ Map<String, dynamic> studio(List<Map<String, dynamic>> readiness) =>+ offering(machineRow('m', 'Mac Studio', contributor: 'owner'), [+ 'claude',+ 'codex',+ ], readiness: readiness);+ f.connection.server.state['machines'] = [studio(const [])];+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');+ final box = await f.box(newProject: true, engine: 'codex');+ box.placeLead();+ expect((box.leadMachine?.id, box.engine), ('m', 'codex'));+ expect(box.leadMachine?.native, isTrue);+ expect(box.leadThroughSwarm, isFalse);+ expect(box.leadBlocked, isNull);+ // Codex signs out there; Claude Code still runs.+ f.connection.server.state['machines'] = [+ studio([+ {'engine': 'codex', 'installed': true, 'signedIn': false},+ ]),+ ];+ expect(await box.create(), NewHarnessOutcome.failed);+ expect(+ box.error,+ 'Mac Studio can’t run Codex: Codex isn’t signed in. Choose another '+ 'engine under Advanced.',+ );+ expect(commandsOf(f, 'project.create'), isEmpty);+ expect(f.connection.calls.where((c) => c.$1 == 'agent_create'), isEmpty);+ });+test('New Project asks the Swarm to start the PM in a teammate’s Team account',() async {diff --git a/desktop/test/super_tab_startup_recovery_test.dart b/desktop/test/super_tab_startup_recovery_test.dartindex 72d1cb585..9ca020243 100644--- a/desktop/test/super_tab_startup_recovery_test.dart+++ b/desktop/test/super_tab_startup_recovery_test.dart@@ -19,7 +19,7 @@ Future<String> legacyLaunch(}) async {if (newProject) f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Company');final box = await f.box(task: task, newProject: newProject);- await box.integration!.prepare('m', task);+ await box.integration!.prepare('m', task, box.engine);final key = f.store.values.keys.singleWhere((key) => key.startsWith('super_tab.launch.'),);diff --git a/desktop/test/swarm_creation_form_test.dart b/desktop/test/swarm_creation_form_test.dartindex b986337ad..ce1e94352 100644--- a/desktop/test/swarm_creation_form_test.dart+++ b/desktop/test/swarm_creation_form_test.dart@@ -85,7 +85,7 @@ void main() {actionLabel: 'New Project',projectVisibility: 'public',projectVisibilityLocked: visibilityLocked,- prepare: (_, task) async => task,+ prepare: (_, task, _) async => task,beforeSubmit: (_, _) async {},complete: (_, _) async {},)@@ -354,7 +354,7 @@ void main() {find.descendant(of: leadLine,matching: find.textContaining(- 'Product Manager: Mac Studio · ${box.agentLabel}',+ 'Product Manager on Mac Studio · ${box.agentLabel}',),),findsOneWidget,@@ -489,7 +489,7 @@ void main() {expect(find.descendant(of: leadLine,- matching: find.textContaining('Product Manager: Ken MacBook'),+ matching: find.textContaining('Product Manager on Ken MacBook'),),findsOneWidget,);@@ -524,7 +524,7 @@ void main() {expect(find.descendant(of: leadLine,- matching: find.textContaining('Product Manager: Ken MacBook'),+ matching: find.textContaining('Product Manager on Ken MacBook'),),findsOneWidget,);@@ -606,8 +606,12 @@ void main() {final line = find.descendant(of: leadLine, matching: find.byType(Text));expect(tester.widget<Text>(line.first).data,- 'Product Manager: Diego MacBook’s Team account · Codex · '- 'Default model · lamp-os will be cloned there',+ 'Product Manager on Diego MacBook’s Team account · Codex · '+ 'Default model',+ );+ expect(+ tester.widget<Text>(line.at(1)).data,+ 'Clones lamp-os there first',);box.setTask('Plan the launch');await tester.pump();@@ -718,7 +722,7 @@ void main() {final line = find.descendant(of: leadLine, matching: find.byType(Text));expect(tester.widget<Text>(line.first).data,- 'Product Manager: Mac Studio · Codex · Default model',+ 'Product Manager on Mac Studio · Codex · Default model',);await unmount(tester);});@@ -919,6 +923,127 @@ void main() {await unmount(tester);});+ for (final brightness in Brightness.values) {+ testWidgets(+ 'With no machine able to run a PM, the box says why and how to fix it '+ 'in ${brightness.name}',+ (tester) async {+ const signedOut = LeadMachine(+ id: 'rig',+ name: '2x 4090 Rig',+ online: true,+ freeAgents: 16,+ engineRefusals: {+ 'claude': 'Claude Code isn’t offered here',+ 'codex': 'Codex isn’t signed in',+ },+ );+ const kens = LeadMachine(+ id: 'studio',+ name: 'Mac Studio',+ online: true,+ freeAgents: 20,+ own: false,+ unavailable:+ 'ken15’s personal account: runs only ken15’s projects. Yours '+ 'need your own computer or a Team account machine',+ );+ final (box, boundary) = await mount(+ tester,+ brightness: brightness,+ leadMachines: [signedOut, kens],+ );+ expect(box.leadNone, isTrue);+ expect(+ find.descendant(+ of: leadLine,+ matching: find.text('No machine can run the Product Manager now.'),+ ),+ findsOneWidget,+ );+ expect(tester.widget<FilledButton>(_start).onPressed, isNull);+ final action = find.descendant(+ of: change,+ matching: find.text('See why'),+ );+ expect(action, findsOneWidget);+ await shot(tester, boundary, 'new-project-none-${brightness.name}');+ await tester.tap(change);+ await tester.pumpAndSettle();+ const engines =+ 'Can’t run a Product Manager: Claude Code isn’t offered here, '+ 'Codex isn’t signed in';+ for (final (id, why) in [+ ('rig', engines),+ ('studio', kens.unavailable!),+ ]) {+ final row = find.byKey(ValueKey('new-harness-lead-machine-$id'));+ // Greyed out, and says why under its name and on hover.+ expect(+ find.descendant(of: row, matching: find.text(why)),+ findsOneWidget,+ );+ expect(+ find.descendant(of: row, matching: find.byTooltip(why)),+ findsOneWidget,+ );+ expect(+ tester+ .widget<Semantics>(+ find+ .descendant(of: row, matching: find.byType(Semantics))+ .first,+ )+ .properties+ .enabled,+ isFalse,+ );+ }+ await shot(tester, boundary, 'new-project-none-${brightness.name}-why');+ expect(tester.takeException(), isNull);+ await unmount(tester);+ },+ );+ }++ testWidgets('The reasons and the clone note fit at 200% text, narrow', (+ tester,+ ) async {+ const signedOut = LeadMachine(+ id: 'rig',+ name: '2x 4090 Rig',+ online: true,+ freeAgents: 16,+ engineRefusals: {+ 'claude': 'Claude Code isn’t offered here',+ 'codex': 'Codex isn’t signed in',+ },+ );+ final (box, boundary) = await mount(+ tester,+ width: 520,+ textScale: 2,+ leadMachines: [signedOut],+ );+ expect(box.leadNone, isTrue);+ await tester.tap(change);+ await tester.pumpAndSettle();+ expect(tester.takeException(), isNull);+ await shot(tester, boundary, 'new-project-none-200');+ await unmount(tester);+ final (_, teamBoundary) = await mount(+ tester,+ width: 520,+ textScale: 2,+ leadMachines: [studioFull, diegoTeam],+ setup: agentIn,+ );+ expect(find.text('Clones lamp-os there first'), findsOneWidget);+ expect(tester.takeException(), isNull);+ await shot(tester, teamBoundary, 'new-project-team-200');+ await unmount(tester);+ });+testWidgets('A paused Swarm gives the pause as the reason', (tester) async {final (_, _) = await mount(tester,@@ -966,7 +1091,7 @@ void main() {final line = find.descendant(of: leadLine, matching: find.byType(Text));expect(tester.widget<Text>(line.first).data,- 'Product Manager: Mac Studio · Codex · Default model',+ 'Product Manager on Mac Studio · Codex · Default model',);await unmount(tester);});@@ -1004,7 +1129,7 @@ void main() {await tester.pumpAndSettle();expect(box.machineId, 'laptop');expect(box.project.folder, '/Users/ken/swarm/lamp-os');- expect(find.textContaining('will be cloned there'), findsNothing);+ expect(find.textContaining('there first'), findsNothing);await unmount(tester);});@@ -1041,7 +1166,7 @@ void main() {expect(find.descendant(of: leadLine,- matching: find.textContaining('lamp-os will be cloned there'),+ matching: find.text('Clones lamp-os there first'),),findsOneWidget,);diff --git a/desktop/test/swarm_launch_recovery_test.dart b/desktop/test/swarm_launch_recovery_test.dartindex fb057acf6..bf7de0fe2 100644--- a/desktop/test/swarm_launch_recovery_test.dart+++ b/desktop/test/swarm_launch_recovery_test.dart@@ -296,7 +296,7 @@ void main() {var created = 0;final integration = HarnessLaunchIntegration(creationId: 'file-review',- prepare: (_, task) async => task,+ prepare: (_, task, _) async => task,complete: (_, _) async {},beforeSubmit: (_, _) async {},needsAttachmentReview: () => true,@@ -377,7 +377,7 @@ void main() {folder: '/work/project',integration: HarnessLaunchIntegration(creationId: 'stage-files',- prepare: (_, task) async => task,+ prepare: (_, task, _) async => task,beforeSubmit: (_, _) async {},complete: (_, _) async {},stageAttachments: (_, _) async =>