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
Phone New project opens on a Swarm that takes work; paused Swarms last (Dee) (#2469)
0xken15f237993429b9
diff --git a/mobile/lib/swarm/swarm_new_project_sheet.dart b/mobile/lib/swarm/swarm_new_project_sheet.dartindex c4a975264..f1526c57e 100644--- a/mobile/lib/swarm/swarm_new_project_sheet.dart+++ b/mobile/lib/swarm/swarm_new_project_sheet.dart@@ -41,6 +41,27 @@ bool swarmMayCreateProject(SwarmInbox inbox, String swarmId) {swarmCanWrite(reader);}+/// Whether Swarm [swarmId] is paused: it takes no new work, so a project+/// made there could not start its Product Manager.+bool swarmNewProjectPaused(SwarmInbox inbox, String swarmId) =>+ inbox.reader(swarmId)?.snapshot?.paused ?? false;++/// The Swarm New project opens on, of [writable] (those that take work+/// first): the one Home showed ([openedFrom]) unless it is paused, else the+/// first that is not (Dee, 11-01: it opened on an old paused Swarm, Create+/// off). All paused: the one Home showed, else the first.+String? swarmNewProjectSwarm(+ List<String> writable, {+ String? openedFrom,+ required bool Function(String swarmId) paused,+}) {+ final from = writable.contains(openedFrom) ? openedFrom : null;+ if (from != null && !paused(from)) return from;+ return writable.where((id) => !paused(id)).firstOrNull ??+ from ??+ writable.firstOrNull;+}+/// The engines a Product Manager runs on, in the order one is chosen/// (Desktop's `kLeadEngines`).const swarmLeadEngines = ['claude', 'codex'];@@ -933,8 +954,10 @@ class SwarmNewProjectRow extends StatelessWidget {/// A project New project made: the Swarm, and the project.typedef SwarmNewProject = ({String swarmId, String projectId});-/// New project, from Swarm Home: which Swarm (only when Home shows several,-/// and only those of [swarmIds] the person may write in), the brief, the+/// New project, from Swarm Home: which Swarm (only when there are several,+/// and only those of [swarmIds] the person may write in; it opens on+/// [openedFrom], the Swarm Home shows, unless that one is paused+/// ([swarmNewProjectSwarm]), and paused ones come last), the brief, the/// visibility, the repository and the machine its Product Manager runs on,/// then Create. Answers the project once it is made and its Product Manager/// asked to start; null when closed. The Swarm taken away, the person's@@ -947,6 +970,7 @@ Future<SwarmNewProject?> showSwarmNewProjectSheet(BuildContext context, {required SwarmSession session,required List<String> swarmIds,+ String? openedFrom,DateTime Function() now = DateTime.now,}) {// The sheet reads no status bar of its own (the route takes it away).@@ -959,6 +983,7 @@ Future<SwarmNewProject?> showSwarmNewProjectSheet(builder: (_) => SwarmNewProjectSheet(session: session,swarmIds: swarmIds,+ openedFrom: openedFrom,now: now,topInset: top,),@@ -971,12 +996,17 @@ class SwarmNewProjectSheet extends StatefulWidget {super.key,required this.session,required this.swarmIds,+ this.openedFrom,this.now = DateTime.now,this.topInset = 0,});final SwarmSession session;final List<String> swarmIds;++ /// The Swarm Home showed when it opened, if one: chosen first unless it is+ /// paused.+ final String? openedFrom;final DateTime Function() now;/// The phone's status bar: with the keyboard up the sheet reaches it.@@ -1027,13 +1057,25 @@ class _SwarmNewProjectSheetState extends State<SwarmNewProjectSheet> {/// rather than send through either.late final Map<String, SwarmReader?> _readers;- List<String> get _writable => [- for (final id in widget.swarmIds)- if (_readers[id] case final reader?- when identical(_inbox.reader(id), reader) &&- swarmMayCreateProject(_inbox, id))- id,- ];+ /// The Swarms it offers: those that take work first, then the paused,+ /// each in Home's order.+ List<String> get _writable {+ final writable = [+ for (final id in widget.swarmIds)+ if (_readers[id] case final reader?+ when identical(_inbox.reader(id), reader) &&+ swarmMayCreateProject(_inbox, id))+ id,+ ];+ return [+ for (final id in writable)+ if (!_paused(id)) id,+ for (final id in writable)+ if (_paused(id)) id,+ ];+ }++ bool _paused(String id) => swarmNewProjectPaused(_inbox, id);/// The steps the Swarm picked holds, if any.SwarmNewProjectSteps? get _steps => switch (_readers[_swarmId]) {@@ -1053,7 +1095,11 @@ class _SwarmNewProjectSheetState extends State<SwarmNewProjectSheet> {(id) => SwarmNewProjectSteps.heldBy(_readers[id]!)?.sent ?? false,).firstOrNull ??- writable.firstOrNull;+ swarmNewProjectSwarm(+ writable,+ openedFrom: widget.openedFrom,+ paused: _paused,+ );if (_steps case final steps?) _resume(steps);if (_swarmId case final id?) unawaited(_readModelList(id));}@@ -1393,6 +1439,7 @@ class _SwarmNewProjectSheetState extends State<SwarmNewProjectSheet> {key: const ValueKey('swarm-new-project-swarm'),label: 'Swarm',value: swarmName,+ detail: snapshot.paused ? 'Paused' : null,onTap: sent || _busy? null: () => setState(() => _picking = _Pick.swarm),@@ -1442,6 +1489,9 @@ class _SwarmNewProjectSheetState extends State<SwarmNewProjectSheet> {detail: repository == null? null: swarmRepositoryKey(repository),+ // A link is a choice in its list: said here while none is+ // chosen, so it is found (Dee, 11-01; Lead: no line otherwise).+ hint: repository == null ? 'Or enter a link' : null,onTap: startSent || _busy? null: () => setState(() => _picking = _Pick.repository),@@ -1682,6 +1732,8 @@ class _SwarmNewProjectSheetState extends State<SwarmNewProjectSheet> {key: ValueKey('swarm-new-project-pick-swarm-$id'),leading: SwarmProjectTile(_swarmName(id)),title: _swarmName(id),+ // Still choosable: it may resume before Create.+ detail: _paused(id) ? 'Paused' : null,trailing: id == swarmId ? tick() : null,onTap: () => setState(() {_picking = null;@@ -1926,11 +1978,15 @@ class _Field extends StatelessWidget {required this.label,required this.value,this.detail,+ this.hint,required this.onTap,});final String label, value;final String? detail;++ /// A faint line under it all: what else a tap offers.+ final String? hint;final VoidCallback? onTap;@override@@ -1940,7 +1996,7 @@ class _Field extends StatelessWidget {return Semantics(button: true,enabled: enabled,- label: '$label: $value',+ label: ['$label: $value', ?detail, ?hint].join(', '),excludeSemantics: true,child: Material(color: Colors.transparent,@@ -1990,6 +2046,19 @@ class _Field extends StatelessWidget {),),],+ if (hint case final hint?) ...[+ const SizedBox(height: 3),+ Text(+ hint,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ textAlign: TextAlign.end,+ style: AppType.caption(+ color: AppPalette.textFaint,+ height: 1.35,+ ),+ ),+ ],],),),diff --git a/mobile/lib/swarm/swarm_page.dart b/mobile/lib/swarm/swarm_page.dartindex bbe928ce8..b858888a1 100644--- a/mobile/lib/swarm/swarm_page.dart+++ b/mobile/lib/swarm/swarm_page.dart@@ -600,9 +600,10 @@ class _SwarmPageState extends State<SwarmPage> {];}- /// + New project: its sheet over Home, for the Swarms [shown]; the project- /// it made opens, unless Home or the account changed meanwhile, or the- /// project is no longer Home's to list.+ /// + New project: its sheet over Home, for every Swarm listed, opening on+ /// the one [shown] if Home shows one and it is not paused (Dee, 11-01);+ /// the project it made opens, unless Home or the account changed+ /// meanwhile, or the project is no longer Home's to list.Future<void> _newProject(SwarmSession session,List<SwarmListing> shown,@@ -610,7 +611,8 @@ class _SwarmPageState extends State<SwarmPage> {final made = await showSwarmNewProjectSheet(context,session: session,- swarmIds: [for (final swarm in shown) swarm.id],+ swarmIds: [for (final swarm in session.inbox.swarms) swarm.id],+ openedFrom: shown.length == 1 ? shown.single.id : null,now: widget.now,);if (made == null || !mounted || _session != session) return;diff --git a/mobile/test/swarm/swarm_new_project_fixture.dart b/mobile/test/swarm/swarm_new_project_fixture.dartindex a8b8024cd..07af7dd3d 100644--- a/mobile/test/swarm/swarm_new_project_fixture.dart+++ b/mobile/test/swarm/swarm_new_project_fixture.dart@@ -134,6 +134,9 @@ class NewProjectSwarm {/// Its reads fail, as a Swarm that does not answer.bool unreadable = false;+ /// New work is paused in it.+ bool paused = false;+/// The person's access to it is taken away: every read is refused.bool revoked = false;@@ -167,7 +170,10 @@ class NewProjectSwarm {return {...firstLoad(tabId: id,- head: headData(id: id, name: name, projects: projects),+ head: {+ ...headData(id: id, name: name, projects: projects),+ 'paused': paused,+ },machines: machines,),'members': [part(me, 1, person(me, role: role))],diff --git a/mobile/test/swarm/swarm_new_project_shots_test.dart b/mobile/test/swarm/swarm_new_project_shots_test.dartindex 207b19f2c..aa267c0cf 100644--- a/mobile/test/swarm/swarm_new_project_shots_test.dart+++ b/mobile/test/swarm/swarm_new_project_shots_test.dart@@ -294,4 +294,101 @@ void main() {AppTheme.palette.value = HarnessPalette.graphite;AppTheme.brightness.value = Brightness.dark;}, skip: shots == null);++ testWidgets('a paused Swarm first: the sheet opens on one that takes work, '+ 'the paused one last and marked; a Swarm with no repository hints at '+ 'a link (Dee, 11-01), on a 390 point phone in both themes', (+ tester,+ ) async {+ await tester.binding.setSurfaceSize(const Size(390, 844));+ tester.view.physicalSize = const Size(1170, 2532);+ tester.view.devicePixelRatio = 3;+ tester.view.padding = const FakeViewPadding(top: 141, bottom: 102);+ for (final palette in [HarnessPalette.graphite, HarnessPalette.paper]) {+ final brightness = palette.brightness;+ AppTheme.palette.value = palette;+ AppTheme.brightness.value = brightness;+ final swarms = [+ NewProjectSwarm(name: 'Swarm review verification')..paused = true,+ NewProjectSwarm(+ id: 'tab-2',+ name: 'autonomous.ai',+ machines: [leadPool('mac-studio', name: 'Studio.local', slots: 3)],+ ),+ NewProjectSwarm(+ id: 'tab-3',+ name: 'Lamp Swarm',+ projects: [swarmProject('project-3', 'Ideas')],+ ),+ ];+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm};+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => me,+ account: account,+ request: newProjectBackend(swarms).request,+ notices: SilentSystemNotices(),+ features: features,+ readMarks: MemoryKeyValueStore(),+ )..foreground = false;+ final boundary = GlobalKey();+ await tester.pumpWidget(+ RepaintBoundary(+ key: boundary,+ child: MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: buildAppTheme(brightness: brightness),+ builder: (_, child) => SwarmScope(notifier: host, child: child!),+ onGenerateRoute: (_) => CupertinoPageRoute<void>(+ builder: (_) => SwarmPage(now: () => newProjectNow),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ Future<void> capture(String name) => tester.runAsync(() async {+ final image =+ await (boundary.currentContext!.findRenderObject()!+ as RenderRepaintBoundary)+ .toImage(pixelRatio: 3);+ final png = await image.toByteData(format: ui.ImageByteFormat.png);+ await File('$shots/new-project-390-$name-${brightness.name}.png')+ .writeAsBytes(png!.buffer.asUint8List());+ image.dispose();+ });+ Finder key(String value) => find.byKey(ValueKey(value));+ Future<void> tap(String k) async {+ await tester.ensureVisible(key(k));+ await tester.pumpAndSettle();+ await tester.tap(key(k));+ await tester.pumpAndSettle();+ }++ // Home shows the paused Swarm alone, as Dee's did.+ host.session!.home.show(tab);+ await tester.pumpAndSettle();+ await tap('swarm-new-project');+ await tap('swarm-new-project-machine');+ await tap('swarm-new-project-pick-machine-mac-studio');+ await capture('paused-default');+ await tap('swarm-new-project-swarm');+ await capture('paused-list');+ await tap('swarm-new-project-pick-swarm-$tab');+ await capture('paused-chosen');+ await tap('swarm-new-project-swarm');+ await tap('swarm-new-project-pick-swarm-tab-3');+ await capture('link-hint');+ await tap('swarm-new-project-close');++ await tester.pumpWidget(const SizedBox());+ await tester.pump(const Duration(seconds: 30));+ host.dispose();+ account.dispose();+ }+ await tester.binding.setSurfaceSize(null);+ tester.view.reset();+ AppTheme.palette.value = HarnessPalette.graphite;+ AppTheme.brightness.value = Brightness.dark;+ }, skip: shots == null);}diff --git a/mobile/test/swarm/swarm_new_project_test.dart b/mobile/test/swarm/swarm_new_project_test.dartindex dc5ab1d41..eba365d7d 100644--- a/mobile/test/swarm/swarm_new_project_test.dart+++ b/mobile/test/swarm/swarm_new_project_test.dart@@ -11,12 +11,46 @@ import 'package:harness_mobile/swarm/swarm_page.dart';import 'package:harness_mobile/swarm/swarm_reader.dart';import 'package:harness_mobile/swarm/swarm_request.dart';import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:harness_mobile/swarm/swarm_style.dart' show SwarmButton;import '../voice_fakes.dart';import 'swarm_fixture.dart';import 'swarm_new_project_fixture.dart';void main() {+ group('swarmNewProjectSwarm', () {+ String? pick(+ List<String> writable, {+ String? from,+ Set<String> paused = const {},+ }) => swarmNewProjectSwarm(+ writable,+ openedFrom: from,+ paused: paused.contains,+ );++ test('none paused: the Swarm Home shows, else the first', () {+ expect(pick(['a', 'b'], from: 'b'), 'b');+ expect(pick(['a', 'b']), 'a');+ });++ test('opened from a paused Swarm: the first that takes work', () {+ expect(pick(['b', 'a'], from: 'a', paused: {'a'}), 'b');+ expect(pick(['a', 'b'], paused: {'a'}), 'b');+ });++ test('all paused: the Swarm Home shows, else the first', () {+ expect(pick(['a', 'b'], from: 'b', paused: {'a', 'b'}), 'b');+ expect(pick(['a', 'b'], paused: {'a', 'b'}), 'a');+ });++ test('a Swarm Home shows that it may not offer is never picked', () {+ expect(pick(['a'], from: 'gone'), 'a');+ expect(pick(['a'], from: 'gone', paused: {'a'}), 'a');+ expect(pick(const []), isNull);+ });+ });+group('swarmLeadMachines', () {List<SwarmLeadMachine> machines(List<Map<String, dynamic>> pools, {@@ -889,6 +923,232 @@ void main() {expect(key('swarm-new-project-swarm'), findsNothing);});+ group('a paused Swarm (Dee, 11-01)', () {+ /// The Swarm the sheet opened on, by the name on its Swarm row.+ void opensOn(String name) => expect(+ find.descendant(+ of: key('swarm-new-project-swarm'),+ matching: find.text(name),+ ),+ findsOneWidget,+ );++ /// The Swarm list's rows, top to bottom.+ List<String> listed(WidgetTester tester, List<String> ids) {+ final rows = [+ for (final id in ids)+ if (key('swarm-new-project-pick-swarm-$id').evaluate().isNotEmpty)+ id,+ ];+ rows.sort(+ (a, b) => tester+ .getTopLeft(key('swarm-new-project-pick-swarm-$a'))+ .dy+ .compareTo(+ tester.getTopLeft(key('swarm-new-project-pick-swarm-$b')).dy,+ ),+ );+ return rows;+ }++ /// Why Create is off, if it says.+ String note(WidgetTester tester) =>+ key('swarm-new-project-note').evaluate().isEmpty+ ? ''+ : tester.widget<Text>(key('swarm-new-project-note')).data!;++ Finder pausedOn(String id) => find.descendant(+ of: key('swarm-new-project-pick-swarm-$id'),+ matching: find.text('Paused'),+ );++ testWidgets('none paused: it opens on the first, and none says Paused', (+ tester,+ ) async {+ await pump(tester, [+ NewProjectSwarm(),+ NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm'),+ ]);+ await tap(tester, 'swarm-new-project');+ opensOn('Phone Swarm');+ expect(note(tester), isNot(contains(swarmLeadSwarmPaused)));+ await tap(tester, 'swarm-new-project-swarm');+ expect(listed(tester, [tab, 'tab-2']), [tab, 'tab-2']);+ expect(find.text('Paused'), findsNothing);+ });++ testWidgets('on All Swarms with the first paused it opens on one that '+ 'takes work; the paused one is listed last, marked, and still '+ 'choosable', (tester) async {+ await pump(tester, [+ NewProjectSwarm(name: 'Swarm review verification')..paused = true,+ NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm'),+ ]);+ await tap(tester, 'swarm-new-project');+ opensOn('Lamp Swarm');+ expect(note(tester), isNot(contains(swarmLeadSwarmPaused)));+ await pickMachine(tester, 'mac-1');+ expect(+ tester.widget<SwarmButton>(key('swarm-new-project-create')).onPressed,+ isNotNull,+ reason: 'Create is on',+ );++ await tap(tester, 'swarm-new-project-swarm');+ expect(listed(tester, [tab, 'tab-2']), ['tab-2', tab]);+ expect(pausedOn(tab), findsOneWidget);+ expect(pausedOn('tab-2'), findsNothing);+ await tap(tester, 'swarm-new-project-pick-swarm-$tab');+ opensOn('Swarm review verification');+ expect(+ find.descendant(+ of: key('swarm-new-project-swarm'),+ matching: find.text('Paused'),+ ),+ findsOneWidget,+ );+ expect(note(tester), contains(swarmLeadSwarmPaused));+ });++ testWidgets('opened from a paused Swarm Home shows, it opens on the '+ 'first that takes work, never on one the person only views', (+ tester,+ ) async {+ final host = await pump(tester, [+ NewProjectSwarm(id: 'tab-viewed', name: 'Viewed', role: 'viewer'),+ NewProjectSwarm(name: 'Swarm review verification')..paused = true,+ NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm'),+ ]);+ host.session!.home.show(tab);+ await tester.pumpAndSettle();+ await tap(tester, 'swarm-new-project');+ opensOn('Lamp Swarm');+ await tap(tester, 'swarm-new-project-swarm');+ expect(listed(tester, [tab, 'tab-2', 'tab-viewed']), ['tab-2', tab]);+ expect(pausedOn(tab), findsOneWidget);+ expect(+ find.descendant(+ of: key('swarm-new-project-sheet'),+ matching: find.text('Viewed'),+ ),+ findsNothing,+ );+ });++ testWidgets('opened from a Swarm that takes work, not the first, it '+ 'opens on that one', (tester) async {+ final host = await pump(tester, [+ NewProjectSwarm(),+ NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm'),+ ]);+ host.session!.home.show('tab-2');+ await tester.pumpAndSettle();+ await tap(tester, 'swarm-new-project');+ opensOn('Lamp Swarm');+ });++ testWidgets('all paused: it opens on the Swarm Home shows, says why, '+ 'and Create stays off', (tester) async {+ final host = await pump(tester, [+ NewProjectSwarm()..paused = true,+ NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm')..paused = true,+ ]);+ host.session!.home.show('tab-2');+ await tester.pumpAndSettle();+ await tap(tester, 'swarm-new-project');+ opensOn('Lamp Swarm');+ expect(note(tester), contains(swarmLeadSwarmPaused));+ expect(+ tester.widget<SwarmButton>(key('swarm-new-project-create')).onPressed,+ isNull,+ );+ await tap(tester, 'swarm-new-project-swarm');+ expect(listed(tester, [tab, 'tab-2']), [tab, 'tab-2']);+ expect(pausedOn(tab), findsOneWidget);+ expect(pausedOn('tab-2'), findsOneWidget);+ });++ testWidgets('paused while it is open: it stays on the Swarm chosen, '+ 'marked, and Create goes off', (tester) async {+ final lamp = NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm');+ final host = await pump(tester, [NewProjectSwarm(), lamp]);+ host.session!.home.show('tab-2');+ await tester.pumpAndSettle();+ await tap(tester, 'swarm-new-project');+ await pickMachine(tester, 'mac-1');+ lamp.paused = true;+ await host.session!.inbox.reader('tab-2')!.refresh();+ await tester.pumpAndSettle();+ opensOn('Lamp Swarm');+ expect(+ find.descendant(+ of: key('swarm-new-project-swarm'),+ matching: find.text('Paused'),+ ),+ findsOneWidget,+ );+ expect(+ tester.widget<SwarmButton>(key('swarm-new-project-create')).onPressed,+ isNull,+ );+ });++ testWidgets('access to the Swarm it opened on, past a paused one, '+ 'taken away while open closes it', (tester) async {+ final lamp = NewProjectSwarm(id: 'tab-2', name: 'Lamp Swarm');+ final host = await pump(tester, [+ NewProjectSwarm()..paused = true,+ lamp,+ ]);+ host.session!.home.show(tab);+ await tester.pumpAndSettle();+ await tap(tester, 'swarm-new-project');+ opensOn('Lamp Swarm');+ lamp.revoked = true;+ await host.session!.inbox.reader('tab-2')!.refresh();+ await tester.pumpAndSettle();+ expect(find.byType(BottomSheet), findsNothing);+ expect(find.text('Lamp Swarm'), findsNothing);+ });+ });++ testWidgets('the repository row says a link can be entered while none '+ 'is chosen, and a tap reaches it; once one is, it says no more', (+ tester,+ ) async {+ Finder hint() => find.descendant(+ of: key('swarm-new-project-repository'),+ matching: find.text('Or enter a link'),+ );+ await pump(tester, [+ NewProjectSwarm(projects: [swarmProject(project, 'Mobile')]),+ ]);+ await tap(tester, 'swarm-new-project');+ expect(hint(), findsOneWidget);+ await tap(tester, 'swarm-new-project-repository');+ await tap(tester, 'swarm-new-project-pick-link');+ await tester.enterText(+ key('swarm-new-project-link'),+ 'https://github.com/owner/name',+ );+ await tap(tester, 'swarm-new-project-link-use');+ expect(hint(), findsNothing);+ });++ testWidgets('a Swarm with a repository: no hint, and no line added', (+ tester,+ ) async {+ await pump(tester, [NewProjectSwarm()]);+ await tap(tester, 'swarm-new-project');+ expect(+ find.descendant(+ of: key('swarm-new-project-repository'),+ matching: find.text('Or enter a link'),+ ),+ findsNothing,+ );+ });+testWidgets('the repository is the most recently active project\'s, ''others and a link a tap away; a link the server would refuse is ''not taken', (tester) async {