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
New Harness: start in the folder of a repository with no commits (#2707)
Kelvin74b922a6536f
diff --git a/desktop/design/new-harness-entry-rules.md b/desktop/design/new-harness-entry-rules.mdindex 366c9b050..c04a42426 100644--- a/desktop/design/new-harness-entry-rules.md+++ b/desktop/design/new-harness-entry-rules.md@@ -159,8 +159,13 @@ Git projects enable Branch and Worktree. Worktree defaults to **Yes** until asuccessful Git launch remembers another global choice.The checkbox supports pointer and keyboard activation through the form's activekeymap. Its label and branch icon remain together as the form narrows.-An empty repository explains that a commit is required for a worktree and asks-for a choice. Folders without Git keep both rows disabled. Discovery runs on the selected machine+A repository with no commit yet — or a folder inside one, as `git init` in the+home folder makes `~/Downloads` — starts in the folder itself, as Claude Code's+app does: Branch and Worktree are hidden (the row form says "No commits yet"),+nothing blocks Start, and the remembered Worktree choice is left for the next+repository (`hasNoCommits`). A Swarm's Product Manager is the exception: it+never works in the person's checkout, so such a project is refused for it.+Folders without Git keep both rows disabled. Discovery runs on the selected machinewithout fetching, switching branches, or creating a worktree. A faileddiscovery offers Retry and blocks starting until the result is known.diff --git a/desktop/lib/state/new_harness.dart b/desktop/lib/state/new_harness.dartindex 7be3c5585..caea5c6d7 100644--- a/desktop/lib/state/new_harness.dart+++ b/desktop/lib/state/new_harness.dart@@ -159,8 +159,15 @@ String? currentBranchRef(GitProjectInfo info) =>? 'refs/heads/${info.branch}': null;-/// Git projects keep Worktree on; an empty repository asks for a choice.-bool worktreeByDefault(GitProjectInfo info) => info.isGit;+/// A repository with nothing to branch from: `git init` and no commit yet, or+/// a folder inside one (a `git init` in the home folder makes ~/Downloads+/// one). As in Claude Code, work starts in the folder itself, with no Worktree+/// or Branch to choose, until the first commit gives Git something to branch.+bool hasNoCommits(GitProjectInfo info) => info.isGit && info.branches.isEmpty;++/// Git projects keep Worktree on, once there is a commit to start it from.+bool worktreeByDefault(GitProjectInfo info) =>+ info.isGit && !hasNoCommits(info);/// New work starts from the branch the project calls its default/// (`origin/HEAD`), preferring the local copy; then main, for a project that@@ -256,6 +263,8 @@ ProjectFolderRequest? gitFolderRequest(required String? branchName,required String placeholder,}) {+ // Nothing to branch from: the folder is used as it is ([hasNoCommits]).+ if (hasNoCommits(info)) return null;final ref = branchRef ?? defaultBranchRef(info, worktree: worktree);if (!worktree) {if (newBranchHere(info, branchName) case final name?) {@@ -871,11 +880,17 @@ class NewHarnessController extends ChangeNotifier {DateTime? _branchesCheckedAt;bool get isGitProject => _gitProject.isGit && !_noGitSetup && !isCloud;+ /// A Git project with no commit yet starts in its folder ([hasNoCommits]).+ bool get noCommitsYet => isGitProject && hasNoCommits(_gitProject);++ /// Whether Branch is offered: a Git project with something to branch from.+ bool get choosesBranch => isGitProject && !noCommitsYet;+/// A worktree the person picked: the harness works in it, on its branch.bool get inWorktree => _project.exact && _gitProject.mainFolder != null;- bool get canUseWorktree => isGitProject && !checkingGit && !inWorktree;+ bool get canUseWorktree => choosesBranch && !checkingGit && !inWorktree;bool get worktree =>- isGitProject &&+ choosesBranch &&!inWorktree &&// A Swarm's Product Manager never edits the person's checkout.(placesLead ||@@ -896,7 +911,7 @@ class NewHarnessController extends ChangeNotifier {bool? get worktreeToRemember => placesLead? null: _recoveredWorktreePreference ??- (isGitProject && !inWorktree ? worktree : null);+ (choosesBranch && !inWorktree ? worktree : null);/// Fresh desktop work starts on the default branch, with or without a worktree. A retry/// must instead keep the branch of the folder its first attempt prepared.@@ -1024,7 +1039,7 @@ class NewHarnessController extends ChangeNotifier {locked ||checkingGit ||refreshingBranches ||- !isGitProject ||+ !choosesBranch ||_gitKey == null) {return;}@@ -1038,7 +1053,7 @@ class NewHarnessController extends ChangeNotifier {}bool get canRefreshChoices => switch (field) {- NewHarnessField.branch => isGitProject,+ NewHarnessField.branch => choosesBranch,NewHarnessField.project ||NewHarnessField.projectName => _visibleFolder != null,_ => false,@@ -1529,7 +1544,7 @@ class NewHarnessController extends ChangeNotifier {if (!asGuest || (_guestFolders?.folders.isNotEmpty ?? false))NewHarnessField.projectMenu,if (advancedOpen) ...[- if (isGitProject && !asGuest) NewHarnessField.branch,+ if (choosesBranch && !asGuest) NewHarnessField.branch,if (hasModes) NewHarnessField.mode,if (usesProfile) NewHarnessField.profile,],@@ -1542,7 +1557,7 @@ class NewHarnessController extends ChangeNotifier {value == NewHarnessField.projectName ||value == NewHarnessField.projectRepository ||value == NewHarnessField.machine ||- (value == NewHarnessField.branch && isGitProject) ||+ (value == NewHarnessField.branch && choosesBranch) ||(value == NewHarnessField.mode && _settingsModes.isNotEmpty) ||(value == NewHarnessField.profile && hasProfile);@@ -1961,17 +1976,22 @@ class NewHarnessController extends ChangeNotifier {message: 'This project is unavailable. Choose a project.',);}+ // A harness starts in the folder of a project with no commit+ // ([noCommitsYet]), but a Product Manager never works in the person's+ // checkout, and its worktree needs a commit to start from.+ if (!checkingGit && placesLead && noCommitsYet) {+ return (+ field: NewHarnessField.projectMenu,+ message: 'This project has no commits, and a Product Manager works in its own worktree. Choose a project with a commit.',+ );+ }if (!checkingGit &&- isGitProject &&- (worktree || _startsOnDefault && _gitProject.branches.isNotEmpty) &&+ choosesBranch &&+ (worktree || _startsOnDefault) &&branchRef == null) {return (- field: _gitProject.branches.isEmpty- ? NewHarnessField.projectMenu- : NewHarnessField.branch,- message: _gitProject.branches.isEmpty- ? 'This project has no commits. Choose a project or make an initial commit.'- : 'This project has no default branch. Choose a branch.',+ field: NewHarnessField.branch,+ message: 'This project has no default branch. Choose a branch.',);}if (usesProfile &&@@ -4701,7 +4721,7 @@ class NewHarnessController extends ChangeNotifier {// Working in a picked worktree says nothing about the next harness's.final launchedWorktree =_recoveredWorktreePreference ??- (isGitProject && !inWorktree ? worktree : null);+ (choosesBranch && !inWorktree ? worktree : null);// A destination's journal keeps them for a later recovery's form.// Only a real folder: a new project's or a clone's label is no path, and a// recovery that unlocks the form after a failure would send it as one.diff --git a/desktop/lib/widgets/new_harness_form.dart b/desktop/lib/widgets/new_harness_form.dartindex 40227f9de..e276b3ffa 100644--- a/desktop/lib/widgets/new_harness_form.dart+++ b/desktop/lib/widgets/new_harness_form.dart@@ -376,6 +376,7 @@ class NewHarnessFormState extends State<NewHarnessForm> {String? _blocked(_Row row) => switch (row) {_Row.branch || _Row.worktree when box.checkingGit => '',_Row.branch when box.gitError != null => box.gitError,+ _Row.branch || _Row.worktree when box.noCommitsYet => 'No commits yet',_Row.branch when !box.isGitProject => 'Not a Git repository',_Row.worktree when box.gitError != null => box.gitError,_Row.worktree when box.inWorktree => 'Already a worktree',@@ -2425,7 +2426,7 @@ class NewHarnessFormState extends State<NewHarnessForm> {),if (!box.isCloud &&!box.leadThroughSwarm &&- (box.isGitProject || box.checkingGit || box.gitError != null))+ (box.choosesBranch || box.checkingGit || box.gitError != null))_desktopField(order: 9,anchor: _desktopAnchors[_Row.branch]!,@@ -4190,7 +4191,7 @@ class NewHarnessFormState extends State<NewHarnessForm> {_activateRow(!box.isTerminal? _Row.model- : box.isGitProject+ : box.choosesBranch? _Row.branch: _Row.project,);diff --git a/desktop/test/desktop_compact_launch_test.dart b/desktop/test/desktop_compact_launch_test.dartindex bd16dd517..2015ddf49 100644--- a/desktop/test/desktop_compact_launch_test.dart+++ b/desktop/test/desktop_compact_launch_test.dart@@ -53,6 +53,7 @@ class _CompactApp extends AppNotifier {final launches = <Map<String, Object?>>[];bool missingMain = false;+ bool noCommits = false;Completer<String?>? pendingLaunch;String? launchError = 'Fixture launch declined. Try again.';@@ -69,15 +70,18 @@ class _CompactApp extends AppNotifier {String machineId,String path, {bool refresh = false,- }) async => {- 'isGit': true,- // Detached: a current branch would itself be where new work starts.- 'branch': missingMain ? null : 'main',- 'branches': [- if (!missingMain) {'ref': 'refs/heads/main', 'name': 'main'},- {'ref': 'refs/heads/feature', 'name': 'feature'},- ],- };+ }) async => noCommits+ // A folder inside a repository `git init` made and nothing committed.+ ? {'isGit': true, 'root': '/work', 'branch': 'main', 'branches': []}+ : {+ 'isGit': true,+ // Detached: a current branch would itself be where new work starts.+ 'branch': missingMain ? null : 'main',+ 'branches': [+ if (!missingMain) {'ref': 'refs/heads/main', 'name': 'main'},+ {'ref': 'refs/heads/feature', 'name': 'feature'},+ ],+ };@overrideFuture<Map<String, dynamic>> listCodexProfiles(String machineId, {@@ -185,10 +189,12 @@ Future<_CompactFixture> _mount(String machineName = 'Studio Mac',bool pending = false,bool missingMain = false,+ bool noCommits = false,String? harnessId,}) async {final app = _CompactApp(machineName: machineName);app.missingMain = missingMain;+ app.noCommits = noCommits;if (harnessId != null) {app.machineStates['m']!.dsh.replace([DshEntry(@@ -428,6 +434,29 @@ void main({bool nativeSmoke = false}) {},);+ journey(+ 'a repository with no commits starts in its folder with no Worktree or Branch',+ (tester) async {+ final fixture = await _mount(tester, noCommits: true);+ expect(fixture.box.requiredChoice, isNull);+ expect(+ find.byKey(const ValueKey('new-harness-field-worktree')),+ findsNothing,+ );+ expect(+ find.byKey(const ValueKey('new-harness-field-branch')),+ findsNothing,+ );+ expect(find.textContaining('no commits'), findsNothing);+ expect(tester.widget<FilledButton>(_start).onPressed, isNotNull);+ await key(tester, LogicalKeyboardKey.enter);+ await tester.pumpAndSettle();+ expect(fixture.app.launches, hasLength(1));+ expect(fixture.app.launches.single['folder'], '/work/repo');+ expect(fixture.app.launches.single['projectFolder'], isNull);+ },+ );+journey('an agent becoming unavailable while Start is focused preserves Escape',(tester) async {diff --git a/desktop/test/new_harness_git_test.dart b/desktop/test/new_harness_git_test.dartindex 91d0d8eb1..376b46fa1 100644--- a/desktop/test/new_harness_git_test.dart+++ b/desktop/test/new_harness_git_test.dart@@ -1171,28 +1171,73 @@ void main() {},);- test('an empty repository keeps Worktree on and requires a choice', () async {- final connection = _Connection()- ..answers['/empty'] = {'isGit': true, 'branch': 'main', 'branches': []};- final app = createApp(- connectionForTest: (_) => connection,- connected: true,- );- final box = NewHarnessController(- app,- machineId: 'm',- engine: 'codex',- folder: '/empty',+ // Claude Code's desktop app does the same: no error, no worktree, the+ // session runs in the folder that was picked.+ for (final (name, folder, root) in [+ ('an empty repository', '/empty', '/empty'),+ // `git init` in the home folder makes ~/Downloads one of these.+ ('a folder inside an empty repository', '/home/u/Downloads', '/home/u'),+ ]) {+ test(+ '$name starts in the folder itself, with no Worktree or Branch',+ () async {+ final connection = _Connection()+ ..answers[folder] = {+ 'isGit': true,+ 'root': root,+ 'branch': 'main',+ 'branches': [],+ };+ final app = createApp(+ connectionForTest: (_) => connection,+ connected: true,+ );+ final box = NewHarnessController(+ app,+ machineId: 'm',+ engine: 'codex',+ folder: folder,+ );+ addTearDown(app.dispose);+ addTearDown(box.dispose);+ await settle();+ expect(box.isGitProject, true);+ expect(box.noCommitsYet, true);+ expect(box.worktree, false);+ expect(box.canUseWorktree, false);+ expect(box.choosesBranch, false);+ expect(box.requiredChoice, isNull);+ expect(box.projectFolderRequest, isNull);+ // The person's Worktree choice is kept for the next real repository.+ expect(box.worktreeToRemember, isNull);+ box.toggleWorktree();+ expect(box.worktree, false);+ expect(await box.create(), NewHarnessOutcome.created);+ expect(connection.starts, hasLength(1));+ expect(connection.starts.single['projectSource'], isNull);+ expect(connection.starts.single['cwd'], folder);+ },);- addTearDown(app.dispose);- addTearDown(box.dispose);- await settle();- expect(box.isGitProject, true);- expect(box.worktree, true);- expect(box.requiredChoice?.message, contains('no commits'));- expect(await box.create(), NewHarnessOutcome.failed);- expect(box.worktree, true);- expect(connection.starts, isEmpty);+ }++ test('an empty repository asks for no folder preparation on any path', () {+ const info = GitProjectInfo(isGit: true, branch: 'main');+ expect(hasNoCommits(info), true);+ expect(hasNoCommits(const GitProjectInfo()), false);+ expect(worktreeByDefault(info), false);+ for (final worktree in [true, false]) {+ expect(+ gitFolderRequest(+ '/home/u/Downloads',+ info,+ worktree: worktree,+ branchRef: null,+ branchName: 'typed',+ placeholder: 'brave-otter',+ ),+ isNull,+ );+ }});testWidgets(diff --git a/desktop/test/swarm_creation_form_test.dart b/desktop/test/swarm_creation_form_test.dartindex d04ecacde..68c5831f1 100644--- a/desktop/test/swarm_creation_form_test.dart+++ b/desktop/test/swarm_creation_form_test.dart@@ -1362,4 +1362,27 @@ void main() {expect(box.worktree, isTrue);await unmount(tester);});++ // A harness starts in the folder of a repository with no commits; the+ // Product Manager never works in the person's checkout, so it is refused.+ testWidgets('The Product Manager is refused a repository with no commits', (+ tester,+ ) async {+ final (box, _) = await mount(+ tester,+ leadMachines: [studio],+ setup: (f) => f.app.gitProjectReaderForTest = (_, _) async => {+ 'isGit': true,+ 'root': '/home/u',+ 'branch': 'main',+ 'branches': [],+ },+ );+ await tester.pumpAndSettle();+ expect(box.noCommitsYet, isTrue);+ expect(box.requiredChoice?.field, NewHarnessField.projectMenu);+ expect(box.requiredChoice?.message, contains('no commits'));+ expect(box.requiredChoice?.message, contains('Product Manager'));+ await unmount(tester);+ });}