Skip to content

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.

fix(desktop): Cmd-N starts from the default branch, not the pane's (#217)

Dee9e39bd66657f
diff --git a/desktop/design/new-harness-entry-rules.md b/desktop/design/new-harness-entry-rules.md
index 3c6262370..eaeda38fe 100644
--- a/desktop/design/new-harness-entry-rules.md
+++ b/desktop/design/new-harness-entry-rules.md
@@ -53,8 +53,10 @@ in the repository's main checkout, so Cmd-N from a worktree pane starts beside
it rather than inside it. Worktrees Start made are never offered as recent
projects.
-**Branch** starts on the branch of the pane New Harness was opened from, and
-otherwise on the default branch (Worktree on) or the folder's own branch (off).
+**Branch** starts on the default branch with Worktree on, and on the folder's
+own branch with it off. It does not follow the pane New Harness was opened from:
+New Harness is new work, and another agent's branch is one pick away. The Start
+button reads **Start Harness** on every New Harness, whatever the rows say.
The picker names local branches; a remote branch is listed only when no local
branch has its name.
@@ -67,7 +69,7 @@ own: the default or current branch gets a new branch named after the session
(`onboarding-experience`);
another local branch is checked out as it is; a remote branch nobody has
locally becomes a local branch of the same name tracking it; a branch that
-already has a worktree opens there, and Start reads **Start in Worktree**. The
+already has a worktree opens there, as the Branch row's tooltip says. The
project folder's own branch cannot be checked out twice. Typing a name no
branch has offers **Create branch**: a new branch in a new worktree, from the
default branch. Spaces become `-` and anything Git refuses in a name is
@@ -84,8 +86,8 @@ A picked or created branch keeps its name. The worktree is checked out in
repository's `.worktreeinclude` (gitignore syntax, e.g. `.env`) are copied in.
With `[ ]`, **Branch** is the branch the folder itself is on; only local
-branches are selectable. A branch with a worktree of its own opens there
-(**Start in Worktree**). Typing a name no branch has offers **Create branch**:
+branches are selectable. A branch with a worktree of its own opens there.
+Typing a name no branch has offers **Create branch**:
a new branch from the folder's branch, keeping its uncommitted changes.
Switching or creating needs no harness working in the folder, and switching
also needs nothing uncommitted. No changes are forced,
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 5b2495b34..13baa75c3 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -1303,9 +1303,10 @@ class _SwarmScreenState extends State<SwarmScreen> {
projectName != null || agent == null || id != focused?.machineId
? null
: machine?.projectOf(agent);
+ // Another one of these: its agent, machine and folder — not its branch.
+ // New Harness is new work; another agent's branch is one pick away, and
+ // joins its worktree rather than being where Start begins.
final initialFolder = folder ?? paneProject?.cwd;
- // Another one of these: on the branch the pane is on, as well as its folder.
- final initialBranch = folder == null ? paneProject?.branch : null;
if (id == null) {
await _dialog(
() => showSwarmLinkDialog(context, app, keymap: _keymap),
@@ -1332,7 +1333,6 @@ class _SwarmScreenState extends State<SwarmScreen> {
// ⌘⇧T is how a shell is made; New Harness from a shell means an agent.
engine: engine ?? (isTerminalEngine(inherited) ? null : inherited),
folder: initialFolder,
- branch: initialBranch,
projectName: projectName,
autoProject:
projectName == null &&
@@ -1417,7 +1417,6 @@ class _SwarmScreenState extends State<SwarmScreen> {
required String machineId,
String? engine,
String? folder,
- String? branch,
String? projectName,
bool autoProject = false,
String? task,
@@ -1496,7 +1495,6 @@ class _SwarmScreenState extends State<SwarmScreen> {
machineId: machineId,
engine: engine,
folder: folder,
- branch: branch,
projectName: projectName,
task: task,
draft: resumed,
diff --git a/desktop/lib/state/new_harness.dart b/desktop/lib/state/new_harness.dart
index 3874054d2..e4c66fd2c 100644
--- a/desktop/lib/state/new_harness.dart
+++ b/desktop/lib/state/new_harness.dart
@@ -379,7 +379,6 @@ class NewHarnessController extends ChangeNotifier {
required String machineId,
String? engine,
String? folder,
- String? branch,
String? projectName,
bool autoProject = false,
DateTime Function()? now,
@@ -392,7 +391,6 @@ class NewHarnessController extends ChangeNotifier {
String? home,
Random? random,
}) : _random = random ?? Random(),
- _paneBranch = branch,
placement =
placement ?? (split == null ? HarnessPlacement.currentTab : null),
_targetId = swarmId ?? app.activeSwarmId,
@@ -496,9 +494,6 @@ class NewHarnessController extends ChangeNotifier {
NewHarnessProject get project => _project;
final Random _random;
- /// The branch the pane New Harness was opened from is on: Branch starts
- /// there, for that pane's project only.
- String? _paneBranch;
bool? _worktree;
String? _branchRef, _branchName, _placeholder;
GitProjectInfo _gitProject = const GitProjectInfo();
@@ -561,6 +556,8 @@ class NewHarnessController extends ChangeNotifier {
/// The Branch row: what was picked, or the new branch typed there.
String get branchRowLabel {
+ // Its worktree is where the harness starts, not the project folder.
+ if (opensWorktree) return '$branchLabel · in its worktree';
final plan = worktreePlan;
if (plan != null &&
plan.kind == WorktreeStart.newBranch &&
@@ -623,7 +620,6 @@ class NewHarnessController extends ChangeNotifier {
_branchRef = null;
_branchName = null;
_placeholder = null;
- _paneBranch = null;
_gitProject = const GitProjectInfo();
}
_gitKey = key;
@@ -663,12 +659,6 @@ class NewHarnessController extends ChangeNotifier {
);
}
_gitProject = info;
- // Another one of the pane it came from: on that pane's branch, if it is
- // still a local branch here.
- if (_branchRef == null &&
- info.branches.any((b) => !b.remote && b.name == _paneBranch)) {
- _branchRef = 'refs/heads/$_paneBranch';
- }
// A name made up before the branches were known may already be taken.
if (_placeholder != null &&
info.branches.any((branch) => branch.name == _placeholder)) {
@@ -870,8 +860,9 @@ class NewHarnessController extends ChangeNotifier {
// ---- what the line says -------------------------------------------------
- String get createLabel =>
- opensWorktree ? 'Start in Worktree' : 'Start Harness';
+ /// The same on every New Harness: where Start goes is said by the Branch row,
+ /// not by a button that changes its name.
+ String get createLabel => 'Start Harness';
String get agentLabel => labelOf(_engine);
String labelOf(String id) => currentHarnessName(
diff --git a/desktop/lib/widgets/new_harness_box.dart b/desktop/lib/widgets/new_harness_box.dart
index 5e985b018..7a6d8888b 100644
--- a/desktop/lib/widgets/new_harness_box.dart
+++ b/desktop/lib/widgets/new_harness_box.dart
@@ -915,10 +915,10 @@ class _NewHarnessBoxState extends State<NewHarnessBox> {
_segment(
NewHarnessField.branch,
box.branchRowLabel,
- tooltip: box.worktree
+ tooltip: box.opensWorktree
+ ? '${box.branchLabel} is checked out in a worktree of its own: the harness starts there, beside what is working in it.'
+ : box.worktree
? 'What the worktree works from, brought up to date with its remote at Start. The default branch gets a new branch named after the session; another is checked out as it is. Type a name to create one.'
- : box.opensWorktree
- ? '${box.branchLabel} has a worktree of its own: the harness starts there.'
: 'The branch the project folder is on.',
),
if (box.isGitProject || box.checkingGit || box.gitError != null)
diff --git a/desktop/test/harness_placement_test.dart b/desktop/test/harness_placement_test.dart
index 9e82a6610..83693ae35 100644
--- a/desktop/test/harness_placement_test.dart
+++ b/desktop/test/harness_placement_test.dart
@@ -993,4 +993,72 @@ void main() {
},
);
}
+
+ testWidgets(
+ 'Cmd-N starts from the default branch, not the pane\'s, which is one pick away',
+ (tester) async {
+ newHarnessOpensInBox = true;
+ addTearDown(() => newHarnessOpensInBox = false);
+ final app = createApp();
+ addTearDown(app.dispose);
+ app.gitProjectReaderForTest = (_, _) async => {
+ 'isGit': true,
+ 'root': '/work/project',
+ 'branch': 'main',
+ 'defaultRef': 'refs/remotes/origin/main',
+ 'branches': [
+ {
+ 'ref': 'refs/heads/main',
+ 'name': 'main',
+ 'worktree': '/work/project',
+ },
+ {
+ 'ref': 'refs/heads/feature/pay',
+ 'name': 'feature/pay',
+ 'worktree': '/wt/pay',
+ },
+ {
+ 'ref': 'refs/remotes/origin/main',
+ 'name': 'origin/main',
+ 'remote': true,
+ },
+ ],
+ };
+ // The focused agent works on a branch of its own, in its own worktree.
+ app.machineStates['m']!.agents[0] = Agent(
+ id: 'a0',
+ name: 'Payments',
+ engine: 'codex',
+ terminalAvailable: true,
+ project: const AgentProject(
+ name: 'project',
+ cwd: '/work/project',
+ root: '/work/project',
+ branch: 'feature/pay',
+ ),
+ );
+ app.adoptSessionForTest(terminal('a0', []));
+ await app.addAgentToSwarm('m', 'a0');
+ await mount(tester, app);
+ await chord(tester, LogicalKeyboardKey.keyN);
+ await tester.pump();
+ await tester.pump();
+ final box = tester
+ .widget<NewHarnessBox>(find.byType(NewHarnessBox))
+ .controller;
+ expect(
+ box.engine,
+ 'codex',
+ reason: 'The pane\'s agent, machine and folder carry over.',
+ );
+ expect(box.project.folder, '/work/project');
+ expect(box.branchRef, 'refs/heads/main', reason: 'New work, from main.');
+ expect(box.createLabel, 'Start Harness');
+ box.focusField(NewHarnessField.branch);
+ box.accept(box.options.firstWhere((row) => row.title == 'feature/pay'));
+ expect(box.opensWorktree, true);
+ expect(box.createLabel, 'Start Harness');
+ await tester.pumpWidget(const SizedBox());
+ },
+ );
}
diff --git a/desktop/test/new_harness_git_test.dart b/desktop/test/new_harness_git_test.dart
index dafd5a94b..beeaa5241 100644
--- a/desktop/test/new_harness_git_test.dart
+++ b/desktop/test/new_harness_git_test.dart
@@ -422,7 +422,8 @@ void main() {
});
pick('feature/pay');
expect(box.opensWorktree, true);
- expect(box.createLabel, 'Start in Worktree');
+ expect(box.opensWorktree, true);
+ expect(box.createLabel, 'Start Harness');
expect(box.projectFolderRequest!.payload, {
'projectSource': 'branch',
'gitSource': '/repo',
@@ -466,7 +467,13 @@ void main() {
'branchRef': 'refs/heads/main',
});
pick('feature/pay');
- expect(box.createLabel, 'Start in Worktree');
+ expect(box.opensWorktree, true);
+ expect(
+ box.branchRowLabel,
+ 'feature/pay · in its worktree',
+ reason: 'The row says where Start goes; the button never changes.',
+ );
+ expect(box.createLabel, 'Start Harness');
},
);
@@ -518,35 +525,6 @@ void main() {
expect(branchNameFrom('~^:'), '');
});
- test('Branch starts on the branch of the pane it was opened from', () async {
- final connection = _Connection()..answers['/repo'] = rich;
- final app = createApp(connectionForTest: (_) => connection);
- addTearDown(app.dispose);
- Future<NewHarnessController> from(String? branch) async {
- final box = NewHarnessController(
- app,
- machineId: 'm',
- engine: 'codex',
- folder: '/repo',
- branch: branch,
- );
- addTearDown(box.dispose);
- await settle();
- return box;
- }
-
- final feature = await from('feature');
- expect(feature.branchRef, 'refs/heads/feature');
- expect(feature.worktreePlan!.kind, WorktreeStart.existingBranch);
- final pay = await from('feature/pay');
- expect(pay.opensWorktree, true, reason: 'Another agent on that branch.');
- expect(pay.createLabel, 'Start in Worktree');
- final gone = await from('deleted-branch');
- expect(gone.branchRef, 'refs/heads/main', reason: 'The default instead.');
- final none = await from(null);
- expect(none.branchRef, 'refs/heads/main');
- });
-
test('Create branch cleans up a typed name', () async {
final connection = _Connection()..answers['/repo'] = rich;
final app = createApp(connectionForTest: (_) => connection);