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.

Make New Harness ready for immediate keyboard creation

dee98fc7606add8
diff --git a/desktop/lib/widgets/new_agent_dialog.dart b/desktop/lib/widgets/new_agent_dialog.dart
index 9571eab41..012e8f171 100644
--- a/desktop/lib/widgets/new_agent_dialog.dart
+++ b/desktop/lib/widgets/new_agent_dialog.dart
@@ -153,6 +153,9 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
// answer lands, so nothing blanks.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
+ // The modal's fallback focus can win autofocus. Claim the first
+ // actionable control once the route and its focus tree are mounted.
+ _folderFocus.requestFocus();
unawaited(_probeEngines(initialProbe: widget.initialEngineProbe));
unawaited(_loadAgentPreference());
}
@@ -357,6 +360,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
// over there, so the agent would fail to start in a folder the user watched
// themselves select. That case keeps the in-app browser, which walks the
// remote filesystem over the `fs_list_dir` RPC.
+ var acceptedFolder = false;
setState(() => _picking = true);
final pickingRevision = _machineRevision;
try {
@@ -376,6 +380,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
pickingRevision == _machineRevision) {
_folder = picked;
_error = null;
+ acceptedFolder = true;
}
});
} catch (error) {
@@ -391,8 +396,16 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted &&
!_choicesLocked &&
+ !_picking &&
pickingRevision == _machineRevision) {
- _folderFocus.requestFocus();
+ // A confirmed folder makes the primary action the next step.
+ // Cancellation/failure keeps Enter on browsing, and a pending
+ // account choice must not focus a disabled submit button.
+ if (acceptedFolder && !_waitingForCodexProfile) {
+ _actionFocus.requestFocus();
+ } else {
+ _folderFocus.requestFocus();
+ }
}
});
}
@@ -552,13 +565,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
style: TextButton.styleFrom(
foregroundColor: grid.AppPalette.textSecondary,
),
- child: Text(
- _confirmationPending
- ? 'Close'
- : widget.offerBackToSearch
- ? 'Back to Search'
- : 'Back to Search',
- ),
+ child: Text(_confirmationPending ? 'Close' : 'Back to Search'),
),
if (widget.offerFindExisting &&
_confirmationPending &&
diff --git a/desktop/test/first_workspace_test.dart b/desktop/test/first_workspace_test.dart
index 94318a120..b886d262b 100644
--- a/desktop/test/first_workspace_test.dart
+++ b/desktop/test/first_workspace_test.dart
@@ -457,7 +457,7 @@ void main() {
}
testWidgets(
- 'new agent is keyboard accessible without hidden focus stops',
+ 'new harness supports immediate keyboard creation',
(tester) async {
final app = _FirstUseApp();
app.machineStates['m']!.engines.replace(const [
@@ -471,36 +471,11 @@ void main() {
await chord(tester, LogicalKeyboardKey.keyN);
await tester.pump();
- bool fieldFocused(String key) => tester
- .widget<InkWell>(
- find.descendant(
- of: find.byKey(Key(key)),
- matching: find.byType(InkWell),
- ),
- )
- .focusNode!
- .hasPrimaryFocus;
-
- expect(find.byKey(const Key('new-agent-machine-field')), findsNothing);
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
- expect(
- Focus.of(
- tester.element(
- find.descendant(
- of: find.byType(AlertDialog),
- matching: find.text('Clone repository'),
- ),
- ),
- ).hasPrimaryFocus,
- isTrue,
- );
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
final folder = tester.widget<InkWell>(
find.byKey(const Key('new-agent-folder')),
);
expect(folder.focusNode!.hasPrimaryFocus, isTrue);
+ expect(picker.opened, 0);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
expect(picker.opened, 1);
@@ -508,57 +483,22 @@ void main() {
picker.pending!.complete('/work/my-project');
await tester.pump();
await tester.pump();
- expect(folder.focusNode!.hasPrimaryFocus, isTrue);
expect(find.text('/work/my-project'), findsOneWidget);
-
- for (final id in ['codex', 'claude', 'cursor']) {
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
- expect(
- Focus.of(
- tester.element(
- find.descendant(
- of: find.byKey(ValueKey('new-agent-quick-$id')),
- matching: find.byType(Text),
- ),
- ),
- ).hasPrimaryFocus,
- isTrue,
- );
- }
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
- expect(fieldFocused('new-agent-engine-field'), isTrue);
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
- expect(
- Focus.of(tester.element(find.text('Advanced'))).hasPrimaryFocus,
- isTrue,
- );
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
- expect(
- Focus.of(tester.element(find.text('Back to Search'))).hasPrimaryFocus,
- isTrue,
- );
- await tester.sendKeyEvent(LogicalKeyboardKey.tab);
- await tester.pump();
- expect(
- Focus.of(
- tester.element(
- find.descendant(
- of: find.byKey(const ValueKey('create-agent-submit')),
- matching: find.text('Create Harness'),
- ),
- ),
- ).hasPrimaryFocus,
- isTrue,
+ final submit = tester.widget<FilledButton>(
+ find.byKey(const ValueKey('create-agent-submit')),
);
+ expect(submit.focusNode!.hasPrimaryFocus, isTrue);
expect(app.launches, isEmpty);
+ expect(find.text('Cancel'), findsNothing);
+ expect(find.text('Back to Search'), findsNothing);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
expect(app.launches.single.folder, '/work/my-project');
+ expect(find.byType(AlertDialog), findsNothing);
expect(app.input, isEmpty);
+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
+ await tester.pump();
+ expect(app.input.single.bytes, [27, 91, 66]);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
app.dispose();
@@ -566,10 +506,57 @@ void main() {
variant: const TargetPlatformVariant({
TargetPlatform.macOS,
TargetPlatform.linux,
- TargetPlatform.windows,
}),
);
+ for (final outcome in ['cancel', 'error']) {
+ testWidgets('keyboard folder $outcome restores the chooser, not submit', (
+ tester,
+ ) async {
+ final app = _FirstUseApp();
+ app.machineStates['m']!.engines.replace(const [
+ EngineAvailability(engine: 'claude', installed: true),
+ ]);
+ final oldPicker = FileSelectorPlatform.instance;
+ final picker = _FolderPicker();
+ FileSelectorPlatform.instance = picker;
+ addTearDown(() => FileSelectorPlatform.instance = oldPicker);
+ await mount(tester, app);
+ await chord(tester, LogicalKeyboardKey.keyN);
+ final field = find.byKey(const Key('new-agent-folder'));
+ await tester.tap(field);
+ await tester.pump();
+ await tester.pump();
+ expect(find.text('/work/my-project'), findsOneWidget);
+ final folder = tester.widget<InkWell>(field).focusNode!;
+ folder.requestFocus();
+ await tester.pump();
+ picker.pending = Completer<String?>();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ expect(picker.opened, 2);
+ if (outcome == 'error') {
+ picker.pending!.completeError(StateError('Picker unavailable'));
+ } else {
+ picker.pending!.complete(null);
+ }
+ await tester.pump();
+ await tester.pump();
+ expect(folder.hasPrimaryFocus, isTrue);
+ expect(find.text('/work/my-project'), findsOneWidget);
+ expect(app.launches, isEmpty);
+ picker.pending = Completer<String?>();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ expect(picker.opened, 3, reason: 'Enter retries browsing, not creation');
+ expect(app.launches, isEmpty);
+ picker.pending!.complete(null);
+ await tester.pump();
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ });
+ }
+
testWidgets('fresh workspace reaches an agent with an installed default', (
tester,
) async {
diff --git a/desktop/test/new_agent_codex_profile_test.dart b/desktop/test/new_agent_codex_profile_test.dart
index 6dcf0c5e6..de60fd46b 100644
--- a/desktop/test/new_agent_codex_profile_test.dart
+++ b/desktop/test/new_agent_codex_profile_test.dart
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/core/config.dart';
@@ -236,10 +237,7 @@ void main() {
find.byKey(const Key('new-agent-machine-field')),
);
expect(machineField.options.single.label, 'This Mac — Remote');
- expect(
- find.widgetWithText(FilledButton, 'New Harness'),
- findsOneWidget,
- );
+ expect(find.widgetWithText(FilledButton, 'New Harness'), findsOneWidget);
expect(
find.text(
'This harness will run on This Mac. Its folders are browsed through '
@@ -292,14 +290,25 @@ void main() {
final notifier = _Notifier(const ['/custom/work-login'])
..pending = Completer<void>();
await open(tester, notifier: notifier);
- await tester.tap(find.text('Browse…'));
+ final folderFocus = tester
+ .widget<InkWell>(find.byKey(const Key('new-agent-folder')))
+ .focusNode!;
+ folderFocus.requestFocus();
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
final createButton = find.widgetWithText(FilledButton, 'New Harness');
expect(tester.widget<FilledButton>(createButton).onPressed, isNull);
+ expect(folderFocus.hasPrimaryFocus, isTrue);
expect(notifier.calls, isEmpty);
notifier.pending!.complete();
await tester.pumpAndSettle();
expect(tester.widget<FilledButton>(createButton).onPressed, isNotNull);
+ expect(
+ folderFocus.hasPrimaryFocus,
+ isTrue,
+ reason: 'A late account lookup must not steal keyboard focus',
+ );
await tester.tap(createButton);
await tester.pumpAndSettle();
expect(notifier.calls.single['codexHome'], '/custom/work-login');
diff --git a/docs/harness-agent-first-tabs.md b/docs/harness-agent-first-tabs.md
index 06f8db7fd..483478794 100644
--- a/docs/harness-agent-first-tabs.md
+++ b/docs/harness-agent-first-tabs.md
@@ -33,6 +33,11 @@ no Back to Search button in creation, and no stacked dialog on dismissal.
The creation dialog title and CTA are **New Harness**. Cancel is removed; Escape
and clicking outside dismiss it. Launch-in-progress and uncertain-outcome states
retain their existing safeguards and recovery actions.
+The folder control receives initial keyboard focus, so Enter opens its chooser.
+A successful keyboard folder choice focuses the enabled New Harness action;
+cancellation or failure returns focus to the folder control. If a required Codex
+account lookup is still pending, focus stays on the folder instead of a disabled
+submit action. Completing that lookup does not steal focus.
The Open popup keeps its full-width **Find a harness** field, single-choice
results and 90% black backdrop. Only the highlighted row shows **Open Harness**,