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): preserve clone cancellation and keyboard recovery

deecb92d2a94bff
diff --git a/desktop/lib/widgets/clone_repository_dialog.dart b/desktop/lib/widgets/clone_repository_dialog.dart
index b03276af3..4b73d614c 100644
--- a/desktop/lib/widgets/clone_repository_dialog.dart
+++ b/desktop/lib/widgets/clone_repository_dialog.dart
@@ -29,6 +29,8 @@ class CloneRepositoryDialog extends StatefulWidget {
class _CloneRepositoryDialogState extends State<CloneRepositoryDialog> {
final _url = TextEditingController();
+ final _actionFocus = FocusNode(debugLabel: 'Clone repository');
+ final _errorAnchor = GlobalKey(debugLabel: 'Clone error');
String? _parent, _error;
RepositoryClone? _clone;
bool _picking = false, _closing = false;
@@ -39,10 +41,12 @@ class _CloneRepositoryDialogState extends State<CloneRepositoryDialog> {
void dispose() {
_clone?.cancel();
_url.dispose();
+ _actionFocus.dispose();
super.dispose();
}
Future<void> _chooseDestination() async {
+ if (_busy || _picking || _closing) return;
setState(() => _picking = true);
try {
final folder = await getDirectoryPath(
@@ -70,7 +74,9 @@ class _CloneRepositoryDialogState extends State<CloneRepositoryDialog> {
Future<void> _submit() async {
final repository = _repository, parent = _parent;
- if (repository == null || parent == null || _busy) return;
+ if (repository == null || parent == null || _busy || _picking || _closing) {
+ return;
+ }
final clone = widget.createClone?.call() ?? RepositoryClone();
setState(() {
_clone = clone;
@@ -90,14 +96,37 @@ class _CloneRepositoryDialogState extends State<CloneRepositoryDialog> {
} finally {
if (mounted) {
setState(() => _clone = null);
- if (result != null || _closing) Navigator.pop(context, result);
+ if (_closing) {
+ // A complete checkout can win the filesystem race with cancellation.
+ // Keep it on disk, but honor Cancel instead of advancing onboarding
+ // or replacing the working folder in the parent New agent form.
+ Navigator.pop(context);
+ } else if (result != null) {
+ Navigator.pop(context, result);
+ } else {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted && ModalRoute.of(context)?.isCurrent == true) {
+ final errorContext = _errorAnchor.currentContext;
+ if (errorContext != null) {
+ Scrollable.ensureVisible(
+ errorContext,
+ alignment: 1,
+ alignmentPolicy:
+ ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
+ );
+ }
+ _actionFocus.requestFocus();
+ }
+ });
+ }
}
}
}
void _cancel() {
+ if (_closing) return;
+ setState(() => _closing = true);
if (_busy) {
- setState(() => _closing = true);
_clone!.cancel();
} else {
Navigator.pop(context);
@@ -110,96 +139,115 @@ class _CloneRepositoryDialogState extends State<CloneRepositoryDialog> {
final repository = _repository;
return PopScope(
canPop: !_busy,
- child: AlertDialog(
- title: const Text('Clone repository'),
- content: SizedBox(
- width: 520,
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- const FieldLabel('GitHub repository'),
- TextField(
- key: const ValueKey('clone-repository-url'),
- controller: _url,
- autofocus: true,
- readOnly: _busy,
- decoration: const InputDecoration(
- hintText: 'https://github.com/owner/repository',
- ),
- onChanged: (_) => setState(() => _error = null),
- onSubmitted: (_) => _submit(),
- ),
- const SizedBox(height: 6),
- Text(
- 'Use an HTTPS or SSH URL, or owner/repository.',
- style: Theme.of(context).textTheme.bodySmall,
- ),
- const SizedBox(height: 20),
- const FieldLabel('Destination on this computer'),
- OutlinedButton.icon(
- onPressed: _busy || _picking ? null : _chooseDestination,
- icon: const Icon(Icons.folder_open_outlined, size: 18),
- label: Text(
- _parent ?? 'Choose folder…',
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- ),
- style: OutlinedButton.styleFrom(
- alignment: Alignment.centerLeft,
- padding: const EdgeInsets.symmetric(
- horizontal: 12,
- vertical: 14,
+ child: Actions(
+ actions: {
+ // Escape is the keyboard equivalent of Cancel. Outside clicks still
+ // respect PopScope, so an accidental click cannot stop a clone.
+ DismissIntent: CallbackAction<DismissIntent>(
+ onInvoke: (_) {
+ _cancel();
+ return null;
+ },
+ ),
+ },
+ child: AlertDialog(
+ title: const Text('Clone repository'),
+ content: SizedBox(
+ width: 520,
+ child: SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const FieldLabel('GitHub repository'),
+ TextField(
+ key: const ValueKey('clone-repository-url'),
+ controller: _url,
+ autofocus: true,
+ readOnly: _busy,
+ decoration: const InputDecoration(
+ hintText: 'https://github.com/owner/repository',
),
- foregroundColor: grid.AppPalette.textPrimary,
+ onChanged: (_) => setState(() => _error = null),
+ onSubmitted: (_) => _submit(),
),
- ),
- if (_parent != null && repository != null) ...[
- const SizedBox(height: 8),
+ const SizedBox(height: 6),
Text(
- 'Creates ${p.join(_parent!, repository.name)}',
+ 'Use an HTTPS or SSH URL, or owner/repository.',
style: Theme.of(context).textTheme.bodySmall,
),
- ],
- if (_busy) ...[
const SizedBox(height: 20),
- const LinearProgressIndicator(minHeight: 2),
- const SizedBox(height: 8),
- Text(
- _closing ? 'Cancelling…' : 'Cloning ${repository!.name}…',
- style: Theme.of(context).textTheme.bodySmall,
- ),
- ],
- if (_error != null) ...[
- const SizedBox(height: 16),
- Semantics(
- liveRegion: true,
- child: Text(
- _error!,
- style: TextStyle(
- color: Theme.of(context).colorScheme.error,
+ const FieldLabel('Destination on this computer'),
+ OutlinedButton.icon(
+ onPressed: _busy || _picking ? null : _chooseDestination,
+ icon: const Icon(Icons.folder_open_outlined, size: 18),
+ label: Text(
+ _parent ?? 'Choose folder…',
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ ),
+ style: OutlinedButton.styleFrom(
+ alignment: Alignment.centerLeft,
+ padding: const EdgeInsets.symmetric(
+ horizontal: 12,
+ vertical: 14,
),
+ foregroundColor: grid.AppPalette.textPrimary,
),
),
+ if (_parent != null && repository != null) ...[
+ const SizedBox(height: 8),
+ Text(
+ 'Creates ${p.join(_parent!, repository.name)}',
+ style: Theme.of(context).textTheme.bodySmall,
+ ),
+ ],
+ if (_busy) ...[
+ const SizedBox(height: 20),
+ const LinearProgressIndicator(minHeight: 2),
+ const SizedBox(height: 8),
+ Semantics(
+ liveRegion: true,
+ child: Text(
+ _closing
+ ? 'Cancelling…'
+ : 'Cloning ${repository!.name}…',
+ style: Theme.of(context).textTheme.bodySmall,
+ ),
+ ),
+ ],
+ if (_error != null) ...[
+ const SizedBox(height: 16),
+ Semantics(
+ key: _errorAnchor,
+ liveRegion: true,
+ child: Text(
+ _error!,
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.error,
+ ),
+ ),
+ ),
+ ],
],
- ],
+ ),
),
),
+ actions: [
+ TextButton(
+ onPressed: _closing ? null : _cancel,
+ child: const Text('Cancel'),
+ ),
+ FilledButton(
+ focusNode: _actionFocus,
+ onPressed:
+ _busy || _picking || repository == null || _parent == null
+ ? null
+ : _submit,
+ child: const Text('Clone repository'),
+ ),
+ ],
),
- actions: [
- TextButton(
- onPressed: _closing ? null : _cancel,
- child: const Text('Cancel'),
- ),
- FilledButton(
- onPressed:
- _busy || _picking || repository == null || _parent == null
- ? null
- : _submit,
- child: const Text('Clone repository'),
- ),
- ],
),
);
}
diff --git a/desktop/test/clone_repository_dialog_test.dart b/desktop/test/clone_repository_dialog_test.dart
index f879871a5..eded67d1f 100644
--- a/desktop/test/clone_repository_dialog_test.dart
+++ b/desktop/test/clone_repository_dialog_test.dart
@@ -2,8 +2,10 @@ 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/core/repository_clone.dart';
+import 'package:harness/shared/widgets/app_dialog.dart';
import 'package:harness/widgets/clone_repository_dialog.dart';
class _Folders extends FileSelectorPlatform {
@@ -17,16 +19,129 @@ class _Folders extends FileSelectorPlatform {
class _Clone extends RepositoryClone {
final pending = Completer<String>();
bool cancelled = false;
+ int runs = 0, cancellations = 0;
@override
- Future<String> run(GitHubRepository repository, String parent) =>
- pending.future;
+ Future<String> run(GitHubRepository repository, String parent) {
+ runs++;
+ return pending.future;
+ }
+
@override
void cancel() {
cancelled = true;
+ cancellations++;
}
}
+Future<void> _openClone(
+ WidgetTester tester, {
+ required _Clone clone,
+ required void Function(String?) onResult,
+ double textScale = 1,
+}) async {
+ final original = FileSelectorPlatform.instance;
+ FileSelectorPlatform.instance = _Folders();
+ addTearDown(() => FileSelectorPlatform.instance = original);
+ await tester.pumpWidget(
+ MaterialApp(
+ builder: (context, child) => MediaQuery(
+ data: MediaQuery.of(context)
+ .copyWith(textScaler: TextScaler.linear(textScale)),
+ child: child!,
+ ),
+ home: Builder(
+ builder: (context) => TextButton(
+ onPressed: () async {
+ onResult(
+ await showAppDialog<String>(
+ context: context,
+ builder: (_) => CloneRepositoryDialog(createClone: () => clone),
+ ),
+ );
+ },
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+ await tester.enterText(
+ find.byKey(const ValueKey('clone-repository-url')),
+ 'owner/project',
+ );
+ await tester.tap(find.text('Choose folder…'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.widgetWithText(FilledButton, 'Clone repository'));
+ await tester.pump();
+}
+
void main() {
+ testWidgets('clone failure is visible with large text and keyboard retry', (
+ tester,
+ ) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(880, 560);
+ addTearDown(tester.view.reset);
+ final clone = _Clone();
+ await _openClone(tester, clone: clone, onResult: (_) {}, textScale: 2);
+ const message =
+ 'Could not access this repository. Check the URL and your GitHub access on this computer.';
+ clone.pending.completeError(const RepositoryCloneException(message));
+ await tester.pumpAndSettle();
+ expect(find.text(message).hitTestable(), findsOneWidget);
+ expect(
+ find.widgetWithText(FilledButton, 'Clone repository').hitTestable(),
+ findsOneWidget,
+ );
+ expect(tester.takeException(), isNull);
+ });
+
+ testWidgets('Cancel does not return a clone that finishes while stopping', (
+ tester,
+ ) async {
+ final clone = _Clone();
+ final results = <String?>[];
+ await _openClone(tester, clone: clone, onResult: results.add);
+ await tester.tap(find.text('Cancel'));
+ await tester.pump();
+ expect(clone.cancelled, isTrue);
+ expect(find.text('Cancelling…'), findsOneWidget);
+ expect(results, isEmpty);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ expect(clone.cancellations, 1);
+ // Git may have finished its rename when Cancel arrived. A completed folder
+ // can be kept on disk without selecting it or advancing the parent flow.
+ clone.pending.complete('/work/project');
+ await tester.pumpAndSettle();
+ expect(results, [null]);
+ expect(find.byType(CloneRepositoryDialog), findsNothing);
+ });
+
+ testWidgets('Escape cancels a clone and keeps its cleanup visible', (
+ tester,
+ ) async {
+ final clone = _Clone();
+ final results = <String?>[];
+ await _openClone(tester, clone: clone, onResult: results.add);
+ await tester.tapAt(const Offset(4, 4));
+ await tester.pump();
+ expect(clone.cancelled, isFalse);
+ expect(results, isEmpty);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ expect(clone.cancelled, isTrue);
+ expect(find.text('Cancelling…'), findsOneWidget);
+ expect(results, isEmpty);
+ clone.pending.completeError(
+ const RepositoryCloneException('Clone cancelled.'),
+ );
+ await tester.pumpAndSettle();
+ expect(results, [null]);
+ expect(find.byType(CloneRepositoryDialog), findsNothing);
+ });
+
testWidgets(
'clone failure preserves inputs; retry returns the new working folder',
(tester) async {
@@ -71,8 +186,9 @@ void main() {
expect(find.text('/work'), findsOneWidget);
expect(find.text('Please check your GitHub access.'), findsOneWidget);
clone = _Clone();
- await tester.tap(submit);
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
+ expect(clone.runs, 1);
clone.pending.complete('/work/project');
await tester.pumpAndSettle();
expect(result, '/work/project');
diff --git a/docs/harness-v2-appearance-onboarding.md b/docs/harness-v2-appearance-onboarding.md
index fccb655ef..4b7978577 100644
--- a/docs/harness-v2-appearance-onboarding.md
+++ b/docs/harness-v2-appearance-onboarding.md
@@ -119,6 +119,29 @@ Analysis has no errors/warnings and 14 existing infos; the normal arm64 Release
build succeeds. These checks use fake subprocess, browser and clipboard replies.
Real first-install, provider sign-in and time to a useful agent remain unverified.
+## Repository clone recovery
+
+The separate Clone repository dialog keeps the original repository and
+destination after a failed clone. Enter can retry immediately, and the error is
+brought into view at large text sizes while the actions remain visible.
+**Escape** performs the same cancellation as the Cancel button, showing
+**Cancelling…** until the clone service settles. Clicking outside a running clone
+continues to leave it active.
+
+If a checkout finishes just as cancellation arrives, the completed folder is
+preserved but is not returned to the parent flow. Cancelling therefore cannot
+replace the working folder in New agent or unexpectedly advance first use.
+Partial-checkout cleanup remains owned by the existing clone service.
+
+The affected workflow/render suite passes 50 checks, including three reproduced
+cancellation/keyboard regressions and an error-visibility regression found in
+the 880×560, 2× text render. Analysis and the normal arm64 Release build pass.
+A direct service check cloned public `octocat/Hello-World` from GitHub using
+isolated Git configuration, verified its HEAD and staging cleanup, then removed
+the disposable checkout. This verifies public cloning, not private repository
+authentication or the native folder chooser. Those remain part of genuine
+first-use observation.
+
## Earlier onboarding evidence and direction (historical)
| Primary source | Observed behavior | Harness adaptation |
diff --git a/docs/harness-v2-handoff.md b/docs/harness-v2-handoff.md
index 1d74eb172..eab92aec9 100644
--- a/docs/harness-v2-handoff.md
+++ b/docs/harness-v2-handoff.md
@@ -48,6 +48,13 @@ authorization succeeds, those controls disappear while the workspace restores.
Enter starts sign-in and can start again after cancellation. Live first-install
and provider sign-in still need direct observation.
+Repository cloning now treats **Escape** as Cancel, waits visibly for cleanup,
+and does not advance onboarding if a cancelled clone finishes successfully.
+Failures retain the URL and destination, reveal the error even with large text,
+and return keyboard focus to the retry action. The public GitHub clone service
+was also exercised directly in a disposable folder; private access and the
+native chooser still need first-use observation.
+
## Goal
Build the best everyday workspace for people directing persistent AI agents:
@@ -72,7 +79,18 @@ Research must lead to justified improvements, not feature accumulation.
- Continue on **`main`**, tracking `origin/main`. The user's latest instruction
is to work, commit, and push directly on main from now on. This supersedes
the earlier preference for creating a fresh feature branch after each merge.
-- The browser-sign-in recovery continuation passes 64 affected workflow checks
+- Clone recovery passes 49 affected workflow checks and one real-font render
+ check at 880×560 with normal/2× text. The original cancellation and keyboard
+ retry regressions failed before the fix; visual review then exposed the hidden
+ large-text error. Analysis has zero errors/warnings and 14 existing infos.
+ The normal arm64 Release build succeeds at
+ `/private/tmp/harness-clone-release/Build/Products/Release/Harness.app` and was
+ not launched. Logs: `/private/tmp/harness-clone-{final-tests,final-analyze,release}.log`.
+ A real public `octocat/Hello-World` clone passed with isolated Git configuration,
+ a valid checkout and no staging residue; its temporary folder was removed.
+ Log: `/private/tmp/harness-clone-public.log`. No user agent or running app was
+ started/stopped, and no benchmark ran.
+- **`b7b6075`** adds browser-sign-in recovery and passes 64 affected workflow checks
plus one real-font render check (65 total), including late process startup,
cancelled/replaced sign-ins, browser launch failure, clipboard recovery,
keyboard retry and the authorization-to-workspace boundary. Analysis has zero
@@ -523,6 +541,8 @@ that its isolated window can become active/key.
Browser reopen/copy/cancel recovery is implemented with isolated subprocess
and platform fixtures. Check the real browser handoff and provider return;
do not infer live sign-in success from fixture results.
+ Public GitHub cloning passed a direct service check in a disposable folder;
+ the native chooser and private repository access still need observation.
Creation recovery is implemented and tested with isolated replies. Verify a
deliberately delayed remote create on a disposable agent, including an older
CLI and a changed original swarm. A status check must remain read-only. A
diff --git a/docs/harness-v2-progress.md b/docs/harness-v2-progress.md
index d309aa502..e48c94701 100644
--- a/docs/harness-v2-progress.md
+++ b/docs/harness-v2-progress.md
@@ -6,6 +6,19 @@ Updated 2026-09-14 after integrating the continuation into main. This is a worki
## Continue directly on main
+- Fixed Clone repository cancellation and keyboard recovery. Escape now uses
+ Cancel and waits for cleanup; a late successful clone cannot advance a
+ cancelled flow. Outside clicks leave an active clone running. Failed clones
+ preserve the repository/destination and restore Enter on the retry action.
+ Large-text errors are brought into view beside the still-visible actions.
+ The 50 affected workflow/render checks pass, as do analysis (zero
+ errors/warnings, 14 existing infos) and the normal arm64 Release build at
+ `/private/tmp/harness-clone-release/Build/Products/Release/Harness.app`.
+ Logs: `/private/tmp/harness-clone-{final-tests,final-analyze,release}.log`.
+ A direct public GitHub clone also succeeded with isolated Git configuration
+ and complete temporary-folder cleanup (`harness-clone-public.log`). Private
+ repository access, native chooser and genuine first-install validation remain
+ open. The app was not launched and benchmarking stays deferred.
- Added browser-sign-in recovery: **Open browser** reuses the current link,
**Copy link** offers a fallback, and **Cancel** immediately restores Sign in
with keyboard focus. Cancellation before CLI startup, late authorization URLs,