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.

New Harness paste: fixes from the review of #2525 (#2532)

Kelvin6b45e6cf59b4
diff --git a/cli/src/lib/projectFolder.spec.ts b/cli/src/lib/projectFolder.spec.ts
index f7151f57e..2ef0dec07 100644
--- a/cli/src/lib/projectFolder.spec.ts
+++ b/cli/src/lib/projectFolder.spec.ts
@@ -4,7 +4,7 @@ import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promis
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import {
- cloneFailure, otherGitHubTransport, parseProjectFolder, prepareProjectFolder, ProjectFolderError, projectsRoot, repositoryIdentity, RepositoryAccessError,
+ cloneFailure, otherGitHubTransport, parseProjectFolder, prepareProjectFolder, ProjectFolderError, projectsRoot, repositoryIdentity, RepositoryAccessError, RepositoryHostKeyError,
} from './projectFolder.js'
/** A checkout at [folder] whose origin is [origin] (none when null), made by the real git, with no network. */
@@ -132,13 +132,24 @@ describe('project folder preparation', () => {
expect(error.code).toBe('CLONE_FAILED')
expect(error.message).toContain('GitHub access on the selected machine')
}
- for (const diagnostic of ['fatal: unable to access: Could not resolve host: github.com', 'Host key verification failed.', '']) {
+ for (const diagnostic of ['fatal: unable to access: Could not resolve host: github.com', '']) {
const error = cloneFailure(diagnostic)
expect(error, diagnostic).not.toBeInstanceOf(RepositoryAccessError)
expect(error).toMatchObject({ code: 'CLONE_FAILED', message: 'Could not clone the repository. Check the URL and connection, then retry.' })
}
})
+ it('names an untrusted host key, which is no refusal: GitHub was never asked', () => {
+ const error = cloneFailure('Host key verification failed.\nfatal: Could not read from remote repository.')
+ expect(error).toBeInstanceOf(RepositoryHostKeyError)
+ expect(error).not.toBeInstanceOf(RepositoryAccessError)
+ expect(error.code).toBe('CLONE_FAILED')
+ expect(error.message).toContain('ssh -T [email protected]')
+ // A changed key's warning mentions authentication: it is still the key, and never "No access".
+ expect(cloneFailure('@@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@\nPassword authentication is disabled to avoid man-in-the-middle attacks.\nHost key verification failed.'))
+ .toBeInstanceOf(RepositoryHostKeyError)
+ })
+
it('names the same GitHub repository over the other transport, and nothing for another address', () => {
expect(otherGitHubTransport('https://github.com/owner/repo.git')).toBe('[email protected]:owner/repo.git')
expect(otherGitHubTransport('[email protected]:owner/repo.git')).toBe('https://github.com/owner/repo.git')
@@ -272,6 +283,41 @@ describe('a clone GitHub refuses', () => {
expect(await readdir(root)).toStrictEqual([])
})
+ describe('with a host key this computer does not trust', () => {
+ const untrusted = () => new RepositoryHostKeyError('CLONE_FAILED', 'host key')
+ /** HTTPS refused, as with no credential stored; ssh to github.com stopped by its host key; an alias [reachable]. */
+ function gitWithoutKnownHost(reachable: string | null) {
+ const tried: string[] = []
+ const clone = vi.fn(async (url: string, destination: string) => {
+ tried.push(url)
+ if (url === reachable) return mkdir(destination)
+ throw url.startsWith('https://') ? refused() : untrusted()
+ })
+ return { clone, tried }
+ }
+
+ it('still tries the aliases, one of which may reach it', async () => {
+ const { clone, tried } = gitWithoutKnownHost('git@gh-a:owner/repo.git')
+ await prepareProjectFolder(remote('owner/repo'), { root, clone, cloneFallback: true, githubAliases: async () => ['gh-a'] })
+ expect(tried).toStrictEqual(['https://github.com/owner/repo.git', '[email protected]:owner/repo.git', 'git@gh-a:owner/repo.git'])
+ })
+
+ it('says so when nothing got in, rather than calling it no access', async () => {
+ const { clone, tried } = gitWithoutKnownHost(null)
+ await expect(prepareProjectFolder(remote('owner/repo'), { root, clone, cloneFallback: true, githubAliases: async () => [] }))
+ .rejects.toBeInstanceOf(RepositoryHostKeyError)
+ expect(tried).toHaveLength(2)
+ expect(await readdir(root)).toStrictEqual([])
+ })
+
+ it('says so even when a later way in was refused', async () => {
+ const refusedLast = vi.fn(async (url: string) => { throw url === '[email protected]:owner/repo.git' ? untrusted() : refused() })
+ await expect(prepareProjectFolder(remote('[email protected]:owner/repo'), { root, clone: refusedLast, cloneFallback: true, githubAliases: async () => [] }))
+ .rejects.toBeInstanceOf(RepositoryHostKeyError)
+ expect(refusedLast).toHaveBeenCalledTimes(2)
+ })
+ })
+
it('stops at a failure other than a refusal: another way in would fail the same', async () => {
for (const failure of [() => new ProjectFolderError('CLONE_TIMEOUT', 'Cloning took too long.'), () => new ProjectFolderError('CLONE_FAILED', 'Could not resolve host'), () => new Error('disk full')]) {
const { clone, tried } = git(null, failure)
diff --git a/cli/src/lib/projectFolder.ts b/cli/src/lib/projectFolder.ts
index aa09beffe..f6de4f6ce 100644
--- a/cli/src/lib/projectFolder.ts
+++ b/cli/src/lib/projectFolder.ts
@@ -236,6 +236,7 @@ export async function prepareProjectFolder(
let attempts = options.cloneFallback ? cloneAttempts(repository, []) : [repository.url]
let aliasesRead = !options.cloneFallback
let used = repository.url
+ let hostKeyFailure: RepositoryHostKeyError | undefined
for (let index = 0; ; index++) {
used = attempts[index]!
if (staging) await rm(staging, { force: true, recursive: true }).catch(() => {})
@@ -246,10 +247,13 @@ export async function prepareProjectFolder(
break
} catch (error) {
logAttempt(repository.owner, repository.name, used, error instanceof ProjectFolderError ? error instanceof RepositoryAccessError ? 'refused' : error.code : 'failed')
- // Only a refusal is worth another way in: a network failure or a timeout would fail every one of them.
- if (!(error instanceof RepositoryAccessError)) throw error
+ // Only a refusal or an untrusted host key is worth another way in: a network failure or a timeout would fail every
+ // one of them. An alias may carry its own HostKeyAlias, and https never looks at ssh's keys.
+ if (error instanceof RepositoryHostKeyError) hostKeyFailure ??= error
+ else if (!(error instanceof RepositoryAccessError)) throw error
if (!aliasesRead) { aliasesRead = true; attempts = cloneAttempts(repository, await (options.githubAliases ?? githubAliases)()) }
- if (index === attempts.length - 1) throw error
+ // What the person can act on: a machine that may have access once it trusts the key has not been refused.
+ if (index === attempts.length - 1) throw hostKeyFailure ?? error
}
}
const checkout = join(staging, 'checkout')
@@ -316,8 +320,16 @@ function cloneRepository(url: string, destination: string, gitEnv?: NodeJS.Proce
* stays CLONE_FAILED for the apps; a caller that knows another way in can tell the two apart. */
export class RepositoryAccessError extends ProjectFolderError {}
+/** CLONE_FAILED because ssh stopped before GitHub was asked: this machine does not trust the host key it was shown. Not a
+ * refusal, so the apps never call it "No access", and it may mean the key changed. Another way in checks its own key. */
+export class RepositoryHostKeyError extends ProjectFolderError {}
+
/** What git's diagnostic of a failed clone becomes. A private GitHub repository answers "not found" without access. */
export function cloneFailure(diagnostic: string): ProjectFolderError {
+ // First: ssh's warning about a changed key also says "Password authentication is disabled".
+ if (/host key verification failed/i.test(diagnostic)) {
+ return new RepositoryHostKeyError('CLONE_FAILED', "The selected machine doesn't trust GitHub's SSH host key. Check it by connecting once with ssh -T [email protected], then retry.")
+ }
return /authentication|permission denied|could not read username|repository not found/i.test(diagnostic)
? new RepositoryAccessError('CLONE_FAILED', 'Could not access this repository. Check the URL and GitHub access on the selected machine.')
: new ProjectFolderError('CLONE_FAILED', 'Could not clone the repository. Check the URL and connection, then retry.')
diff --git a/desktop/design/new-harness-entry-rules.md b/desktop/design/new-harness-entry-rules.md
index c77df9e62..366c9b050 100644
--- a/desktop/design/new-harness-entry-rules.md
+++ b/desktop/design/new-harness-entry-rules.md
@@ -304,13 +304,20 @@ included, filters the recent projects as before.
- A terminal takes no project, so it clones nothing: a link shows a disabled **A terminal
can't clone**, and changing to Terminal with a clone chosen asks for a folder or an agent.
- While it clones the line reads **Cloning owner/repo…**. A checkout of that
- repository already in the projects folder is used, not cloned, and the line
+ repository already in the projects folder (`~/harnesses`, or `~/projects` on Harness
+ OS, under any spelling of its name) is used, not cloned, and the line
stays **Starting harness…**, as it does when the computer cannot say. A clone refused
access tries the other transport, then up to three `~/.ssh/config` aliases
- leading to github.com. It moves on only after a refusal, never after a network
- failure or a timeout. Through an alias, the workspace says **Cloned via
- \<alias\>** once. Refused everywhere: **No access to owner/repo on \<computer\>**,
- with the task and choices kept.
+ leading to github.com. It moves on after a refusal or a host key ssh will not
+ trust, never after a network failure or a timeout. Through an alias, the workspace
+ says **Cloned via \<alias\>** once. Refused everywhere: **No access to owner/repo on
+ \<computer\>**, with the task and choices kept. When an untrusted host key was among
+ the failures, the line names the key and `ssh -T [email protected]` instead: GitHub
+ was not asked, and that key may have changed.
+- A remote path ending in a hidden folder is asked about by its own path, because
+ its parent's listing leaves it out; there it shows **Open**.
+- An alias `ssh -G` cannot read stays offered, and its launch says so; only an
+ answered host other than github.com is refused in the row.
## Regression coverage
diff --git a/desktop/lib/core/repository_clone.dart b/desktop/lib/core/repository_clone.dart
index c624f9c33..55cbb45d4 100644
--- a/desktop/lib/core/repository_clone.dart
+++ b/desktop/lib/core/repository_clone.dart
@@ -46,6 +46,7 @@ class RepositoryClone {
/// The `~/.ssh/config` alias the clone went through, when it needed one: a
/// second GitHub account, which later pushes from the checkout use too.
String? clonedVia;
+ bool _hostKeyUntrusted = false;
bool _cancelled = false;
bool _started = false;
@@ -148,11 +149,19 @@ class RepositoryClone {
'“${repository.name}” already exists here. Choose another destination, or open that folder.',
);
}
- if (repository.alias case final alias?
- when !isGitHubHost(await _sshHosts.resolveHost(alias))) {
- throw RepositoryCloneException(
- '$alias isn\'t a GitHub host on this computer.',
- );
+ if (repository.alias case final alias?) {
+ final host = await _sshHosts.resolveHost(alias);
+ // No answer is not "another host": ssh timed out, or is missing.
+ if (host == null) {
+ throw RepositoryCloneException(
+ 'Could not read $alias from ssh on this computer. Check that ssh works, then retry.',
+ );
+ }
+ if (!isGitHubHost(host)) {
+ throw RepositoryCloneException(
+ '$alias isn\'t a GitHub host on this computer.',
+ );
+ }
}
final checkout = await _cloneWithAccess(repository, parent);
if (await FileSystemEntity.type(destination, followLinks: false) !=
@@ -195,7 +204,8 @@ class RepositoryClone {
/// Clones through each way this computer may reach [repository] — what was
/// pasted, the other transport, then its `~/.ssh/config` GitHub aliases —
- /// moving on only when GitHub refused access. On 2026-10-30 a developer Mac
+ /// moving on only when GitHub refused access or ssh would not trust its host
+ /// key. On 2026-10-30 a developer Mac
/// with SSH keys and no HTTPS credential failed every browser link, and its
/// second account's repositories answered only through an alias.
Future<String> _cloneWithAccess(
@@ -221,11 +231,19 @@ class RepositoryClone {
i = -1;
}
}
+ // What the person can act on: a computer that may have access once it
+ // trusts the key has not been refused.
+ if (_hostKeyUntrusted) {
+ throw const RepositoryCloneException(
+ "This computer doesn't trust GitHub's SSH host key. Check it by connecting once with ssh -T [email protected], then retry.",
+ );
+ }
throw RepositoryAccessDenied(repository);
}
/// One `git clone` of [url] into a fresh staging folder: the checkout, or
- /// null when GitHub refused access. Any other failure ends the clone.
+ /// null when this way in is closed, by GitHub's refusal or an untrusted host
+ /// key ([_hostKeyUntrusted]). Any other failure ends the clone.
Future<String?> _cloneOnce(String url, String parent) async {
if (_cancelled) throw const RepositoryCloneException('Clone cancelled.');
final staging = await Directory(parent).createTemp('.harness-clone-');
@@ -273,6 +291,16 @@ class RepositoryClone {
);
}
if (code == 0) return checkout;
+ // Checked first: ssh's warning about a changed key also says "Password
+ // authentication is disabled". GitHub was never asked, so this is no
+ // refusal, but an alias may carry its own HostKeyAlias.
+ if (RegExp(
+ r'host key verification failed',
+ caseSensitive: false,
+ ).hasMatch(diagnostic)) {
+ _hostKeyUntrusted = true;
+ return null;
+ }
// A private repository answers "not found" to whoever cannot see it.
if (RegExp(
r'authentication|permission denied|could not read Username|repository not found',
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 1bb947847..08ac13e5b 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -343,6 +343,10 @@ class AgentCreationAttempt {
String? get agentId => _agentId;
String? _outcome;
String? _preparedFolder;
+
+ /// The SSH alias this attempt's own clone went through, until its harness
+ /// starts and the person is told.
+ String? _clonedVia;
ProjectFolderRequest? _projectFolder;
/// The worktree this computer made for this attempt, set only where it is
@@ -15164,12 +15168,17 @@ class AppNotifier extends ChangeNotifier {
label: label,
onClonedVia: (alias) => via = alias,
);
- if (via case final alias?) _clonedViaFolders[folder] = alias;
+ if (via case final alias?) rememberClonedVia(folder, alias);
return folder;
}
+ @visibleForTesting
+ void rememberClonedVia(String folder, String alias) =>
+ _clonedViaFolders[folder] = alias;
+
/// A folder this computer's own clone reached through an SSH alias, until
- /// its creation tells the person ([_announceClonedVia]).
+ /// its creation takes it. Kept by folder, it outlived a creation that failed,
+ /// and a later start in that folder announced a clone it never made.
final _clonedViaFolders = <String, String>{};
/// The alias a machine's own clone went through (cli launches.ts
@@ -15758,6 +15767,11 @@ class AppNotifier extends ChangeNotifier {
engineIdentity(dshId).label)
: engineIdentity(choices['engine'] as String?).label,
);
+ if (preparedBefore == null) {
+ creation._clonedVia = _clonedViaFolders.remove(
+ creation._preparedFolder,
+ );
+ }
if (preparedBefore == null && project.createsWorktree) {
creation._worktreeMadeHere = (
folder: creation._preparedFolder!,
@@ -16063,10 +16077,8 @@ class AppNotifier extends ChangeNotifier {
creation._complete(null);
if (_disposed || machineStates[machineId] != machine) return null;
creation._agentId = agent.id;
- _announceClonedVia(
- _clonedViaFolders.remove(creation._preparedFolder) ??
- _clonedViaOf(result),
- );
+ _announceClonedVia(creation._clonedVia ?? _clonedViaOf(result));
+ creation._clonedVia = null;
if (choices['prompt'] case final String prompt
when prompt.trim().isNotEmpty) {
_firstMessages[(machineId, agent.id)] = prompt;
diff --git a/desktop/lib/state/new_harness.dart b/desktop/lib/state/new_harness.dart
index a8776d613..7be3c5585 100644
--- a/desktop/lib/state/new_harness.dart
+++ b/desktop/lib/state/new_harness.dart
@@ -2743,6 +2743,9 @@ class NewHarnessController extends ChangeNotifier {
_resetProfiles();
_machineRevision++;
_listDebounce?.cancel();
+ _hiddenFolderDebounce?.cancel();
+ _hiddenFolders.clear();
+ _hiddenFolderAsked = null;
_listings.clear();
_loadingFolders.clear();
_visibleFolder = folderRefreshError = null;
@@ -3866,7 +3869,17 @@ class NewHarnessController extends ChangeNotifier {
: paths.dirname(full);
final names = parent == null ? null : _listings[parent];
if (parent != null && names == null) _requestListing(parent);
- if (!trailing && names != null && names.contains(paths.basename(full))) {
+ final name = paths.basename(full);
+ final hidden =
+ !trailing &&
+ parent != null &&
+ _machine?.isLocalMachine != true &&
+ name.startsWith('.') &&
+ name != '.' &&
+ name != '..';
+ if (hidden && !_hiddenFolders.contains(full)) _askAboutHiddenFolder(full);
+ if (!trailing &&
+ (_hiddenFolders.contains(full) || names?.contains(name) == true)) {
return NewHarnessOption(
id: pasteOpenId,
synthetic: true,
@@ -3891,14 +3904,16 @@ class NewHarnessController extends ChangeNotifier {
@visibleForTesting
SshHosts sshHosts = SshHosts();
- /// What each pasted alias stands for on this computer, '' when ssh could not
- /// say; absent while it is being read.
+ /// What each pasted alias stands for on this computer; absent until it is
+ /// asked about.
final _aliasHosts = <String, String>{};
Future<void> _resolveAlias(String alias) async {
final host = await sshHosts.resolveHost(alias);
if (_disposed) return;
- _aliasHosts[alias] = host ?? '';
+ // ssh that cannot say (a timeout, no ssh) has not called it another host:
+ // it stays offered, and the launch reads it again and says what went wrong.
+ if (host != null) _aliasHosts[alias] = host;
if (field == NewHarnessField.projectMenu ||
field == NewHarnessField.projectRepository) {
_refresh();
@@ -4090,9 +4105,9 @@ class NewHarnessController extends ChangeNotifier {
notifyListeners();
}
- /// Whether nothing is at `~/harnesses/<name>` where the harness will run.
- /// Saying nothing about a clone is less wrong than announcing one that is not
- /// happening, so false also covers a computer that cannot say.
+ /// Whether nothing is at `<projects folder>/<name>` where the harness will
+ /// run. Saying nothing about a clone is less wrong than announcing one that
+ /// is not happening, so false also covers a computer that cannot say.
Future<bool> _cloneDestinationIsFree(GitHubRepository repository) async {
final id = _machineId;
final home = await _ensureHome(id);
@@ -4108,15 +4123,64 @@ class NewHarnessController extends ChangeNotifier {
// fs_list_dir (cli fsBrowse.ts) leaves hidden folders out: `.github` would
// look free whether it is there or not.
if (repository.name.startsWith('.')) return false;
- final answer = await app.listRemoteFolder(id, root);
- // The first clone on that computer: ~/harnesses is made for it.
- if (answer['error'] == 'NOT_FOUND') return true;
- final entries = answer['entries'];
- if (answer['error'] != null || entries is! List) return false;
- final listed = entries.any(
- (entry) => entry is Map && entry['name'] == repository.name,
+ // This app is not told which folder that computer's daemon uses: Harness OS
+ // keeps its projects in ~/projects (cli projectsRoot). A case-insensitive
+ // disk holds `Repo` as `repo`, so any spelling may be the same folder.
+ final name = repository.name.toLowerCase();
+ for (final folder in [root, _pathsFor(id, home).join(home, 'projects')]) {
+ final answer = await app.listRemoteFolder(id, folder);
+ // The first clone on that computer: the folder is made for it.
+ if (answer['error'] == 'NOT_FOUND') continue;
+ final entries = answer['entries'];
+ if (answer['error'] != null ||
+ entries is! List ||
+ answer['truncated'] == true) {
+ return false;
+ }
+ final listed = entries.any(
+ (entry) =>
+ entry is Map &&
+ entry['name'] is String &&
+ (entry['name'] as String).toLowerCase() == name,
+ );
+ if (listed) return false;
+ }
+ return true;
+ }
+
+ /// Folders another computer has said are there though their parent's listing
+ /// leaves them out: fs_list_dir (cli fsBrowse.ts) hides dot folders, so each
+ /// is asked about by its own path. Not a [_listings] entry: a failed listing
+ /// is kept there as empty, and here that would read as a folder.
+ final _hiddenFolders = <String>{};
+ Timer? _hiddenFolderDebounce;
+
+ /// The folder last asked about. A refresh runs the path row again, and the
+ /// parent's listing arriving is one: without this each pushed the question
+ /// back, or asked it twice.
+ String? _hiddenFolderAsked;
+
+ void _askAboutHiddenFolder(String folder) {
+ if (_hiddenFolderAsked == folder) return;
+ _hiddenFolderAsked = folder;
+ _hiddenFolderDebounce?.cancel();
+ _hiddenFolderDebounce = Timer(
+ const Duration(milliseconds: 80),
+ () => unawaited(_readHiddenFolder(folder)),
);
- return !listed && answer['truncated'] != true;
+ }
+
+ Future<void> _readHiddenFolder(String folder) async {
+ final id = _machineId;
+ final revision = _machineRevision;
+ final answer = await app.listRemoteFolder(id, folder);
+ if (_disposed || id != _machineId || revision != _machineRevision) return;
+ if (answer['error'] != null || answer['entries'] is! List) return;
+ _hiddenFolders.add(folder);
+ if (field == NewHarnessField.project ||
+ field == NewHarnessField.projectMenu) {
+ _refresh();
+ }
}
/// Ask for [folder]'s listing. A local folder is read at once, off this
@@ -4869,6 +4933,7 @@ class NewHarnessController extends ChangeNotifier {
_appTick?.cancel();
_projectRefresh?.cancel();
_listDebounce?.cancel();
+ _hiddenFolderDebounce?.cancel();
app.removeListener(_onApp);
_modelUsage?.removeListener(_refresh);
if (_ownsModelUsage) _modelUsage?.dispose();
diff --git a/desktop/test/new_harness_project_paste_test.dart b/desktop/test/new_harness_project_paste_test.dart
index b24a34e4d..6869bd3ce 100644
--- a/desktop/test/new_harness_project_paste_test.dart
+++ b/desktop/test/new_harness_project_paste_test.dart
@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
import 'package:harness/core/ssh_hosts.dart';
import 'package:harness/state/app_state.dart';
import 'package:harness/state/new_harness.dart';
@@ -31,6 +32,10 @@ class _Connection extends WsConn {
Map<String, dynamic> harnesses = const {'error': 'NOT_FOUND'};
Completer<void>? harnessesHeld;
+ /// What this computer answers for any other folder asked about by name.
+ final folders = <String, Map<String, dynamic>>{};
+ final asked = <String>[];
+
@override
Future<Map<String, dynamic>> request(
String type, {
@@ -46,6 +51,16 @@ class _Connection extends WsConn {
};
case 'fs_list_dir':
final path = payload['path'] as String? ?? '/home/test';
+ asked.add(path);
+ if (folders[path] case final answer?) {
+ if (answer['error'] case final String code) {
+ throw WsRequestFailure(
+ responseType: 'fs_list_dir_result',
+ code: code,
+ );
+ }
+ return answer;
+ }
if (path == '/home/test/harnesses') {
await harnessesHeld?.future;
// A refusal arrives as WsConn throws it, never as a value.
@@ -190,6 +205,127 @@ void main() {
expect(box.selected!.title, 'Browse /srv/');
});
+ group('a hidden folder, which its parent does not list', () {
+ const missing = {'error': 'NOT_FOUND'};
+
+ test('opens on another computer when it is there', () async {
+ connection.folders['/srv/.config'] = {
+ 'path': '/srv/.config',
+ 'entries': const [],
+ };
+ final box = search('/srv/.config');
+ await listed();
+ expect(box.selected!.title, 'Open /srv/.config');
+ expect(box.selected!.project!.folder, '/srv/.config');
+ });
+
+ test('still browses when it is not', () async {
+ connection.folders['/srv/.config'] = missing;
+ final box = search('/srv/.config');
+ await listed();
+ expect(box.selected!.title, 'Browse /srv/');
+ });
+
+ test('a file by that name is no folder', () async {
+ connection.folders['/srv/.env'] = {'error': 'NOT_A_DIRECTORY'};
+ final box = search('/srv/.env');
+ await listed();
+ expect(box.selected!.title, 'Browse /srv/');
+ });
+
+ test('. and .. are not hidden folders', () async {
+ final box = search('/srv/..');
+ await listed();
+ expect(box.selected!.title, 'Browse /srv/');
+ expect(connection.asked, isNot(contains('/srv/..')));
+ });
+
+ test('is asked about once the typing pauses, once', () async {
+ connection.folders['/srv/.config'] = {
+ 'path': '/srv/.config',
+ 'entries': const [],
+ };
+ final box = search('/srv/.c');
+ box.setQuery('/srv/.config');
+ await listed();
+ expect(connection.asked, isNot(contains('/srv/.c')));
+ box.setQuery('/srv/.config');
+ await listed();
+ expect(
+ connection.asked.where((path) => path == '/srv/.config'),
+ hasLength(1),
+ );
+ });
+
+ test('an answer after the form closed changes nothing', () async {
+ connection.folders['/srv/.config'] = {
+ 'path': '/srv/.config',
+ 'entries': const [],
+ };
+ final box = NewHarnessController(
+ app,
+ machineId: 'm',
+ engine: 'codex',
+ folder: '/work/repo',
+ )..useDesktopChoices(true);
+ box.focusField(NewHarnessField.projectMenu);
+ box.setQuery('/srv/.config');
+ box.dispose();
+ await listed();
+ expect(connection.asked, isNot(contains('/srv/.config')));
+ });
+
+ test('another computer does not inherit the answer', () async {
+ connection.folders['/srv/.config'] = {
+ 'path': '/srv/.config',
+ 'entries': const [],
+ };
+ final box = search('/srv/.config');
+ await listed();
+ expect(box.selected!.title, 'Open /srv/.config');
+ connection.folders['/srv/.config'] = missing;
+ const studio = Machine(
+ machineId: 'n',
+ authMode: MachineAuthMode.remote,
+ name: 'Studio',
+ );
+ app.machines = [...app.machines, studio];
+ app.machineStates['n'] = MachineState(studio)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agentLoadStatus = AgentLoadStatus.loaded
+ ..agents = [];
+ box.focusField(NewHarnessField.machine);
+ box.setQuery('Studio');
+ box.accept();
+ box.focusField(NewHarnessField.projectMenu);
+ box.setQuery('/srv/.config');
+ expect(box.selected!.title, 'Browse /srv/');
+ });
+ });
+
+ test(
+ 'an alias ssh cannot read is offered, and its launch checks again',
+ () async {
+ app.machineStates['m']!.localOnly = true;
+ final answer = Completer<String?>();
+ final box = NewHarnessController(
+ app,
+ machineId: 'm',
+ engine: 'codex',
+ folder: '/work/repo',
+ )..useDesktopChoices(true);
+ box.sshHosts = _SlowHosts(answer.future);
+ addTearDown(box.dispose);
+ box.focusField(NewHarnessField.projectMenu);
+ box.setQuery('git@gh-work:org/repo.git');
+ answer.complete(null);
+ await Future<void>.delayed(Duration.zero);
+ expect(box.selected!.title, 'Clone org/repo');
+ expect(box.selected!.enabled, isTrue);
+ },
+ );
+
test('the GitHub prompt refuses the same alias', () async {
app.machineStates['m']!.localOnly = true;
final box = search('', hosts: {'gitlab-work': 'gitlab.com'});
@@ -265,6 +401,79 @@ void main() {
expect(told, ['Cloned via gh-work']);
});
+ group('Cloned via is told only for the clone of that creation', () {
+ late AppNotifier local;
+ late List<String> told;
+ String? clonedVia;
+
+ setUp(() {
+ told = [];
+ clonedVia = null;
+ local = createApp(
+ connectionForTest: (_) => connection,
+ connected: true,
+ prepareFolder: (_) async {
+ if (clonedVia case final alias?) {
+ local.rememberClonedVia('/home/test/harnesses/repo', alias);
+ }
+ return '/home/test/harnesses/repo';
+ },
+ );
+ addTearDown(local.dispose);
+ local.machineStates['m']!
+ ..agents = []
+ ..localOnly = true;
+ local.agentChangeNotice = told.add;
+ });
+
+ Future<NewHarnessOutcome> start(Map<String, dynamic> reply) async {
+ connection.createReply = null;
+ connection.creates.clear();
+ final box = NewHarnessController(
+ local,
+ machineId: 'm',
+ engine: 'codex',
+ folder: '/home/test',
+ home: '/home/test',
+ )..useDesktopChoices(true);
+ box.sshHosts = _Hosts(const {});
+ addTearDown(box.dispose);
+ box.focusField(NewHarnessField.projectMenu);
+ box.setQuery('https://github.com/org/repo');
+ box.accept();
+ final outcome = box.create();
+ await pumpEventQueue();
+ connection.createReply!.complete({
+ 'creationId': connection.creates.single['creationId'],
+ ...reply,
+ });
+ return outcome;
+ }
+
+ const created = {
+ 'state': 'created',
+ 'agent': {'id': 'a1', 'name': 'Repo', 'engine': 'codex'},
+ };
+ const failed = {
+ 'state': 'failed',
+ 'failure': {'code': 'INVALID_CWD', 'detail': 'No.'},
+ };
+
+ test('the clone that started the harness is told', () async {
+ clonedVia = 'gh-work';
+ expect(await start(created), NewHarnessOutcome.created);
+ expect(told, ['Cloned via gh-work']);
+ });
+
+ test('a later start in that folder is not told', () async {
+ clonedVia = 'gh-work';
+ expect(await start(failed), NewHarnessOutcome.failed);
+ clonedVia = null;
+ expect(await start(created), NewHarnessOutcome.created);
+ expect(told, isEmpty);
+ });
+ });
+
test('a clone says so while it runs', () async {
final box = search('https://github.com/org/repo');
box.accept();
@@ -351,6 +560,39 @@ void main() {
},
);
+ test('the same name in another case may be the same folder', () async {
+ connection.harnesses = {
+ 'path': '/home/test/harnesses',
+ 'entries': [
+ {'name': 'Repo', 'isDir': true},
+ ],
+ };
+ final box = search('https://github.com/org/repo');
+ final lines = await linesWhileCreating(box);
+ expect(lines, isNot(contains('Cloning org/repo…')));
+ });
+
+ test('a Harness OS checkout in ~/projects is used, not cloned', () async {
+ connection.folders['/home/test/projects'] = {
+ 'path': '/home/test/projects',
+ 'entries': [
+ {'name': 'repo', 'isDir': true},
+ ],
+ };
+ final box = search('https://github.com/org/repo');
+ final lines = await linesWhileCreating(box);
+ expect(lines, isNot(contains('Cloning org/repo…')));
+ });
+
+ test('a ~/projects that cannot be read cannot say', () async {
+ connection.folders['/home/test/projects'] = {
+ 'error': 'PERMISSION_DENIED',
+ };
+ final box = search('https://github.com/org/repo');
+ final lines = await linesWhileCreating(box);
+ expect(lines, isNot(contains('Cloning org/repo…')));
+ });
+
test('another folder in ~/harnesses does not stop it saying so', () async {
connection.harnesses = {
'path': '/home/test/harnesses',
diff --git a/desktop/test/repository_clone_test.dart b/desktop/test/repository_clone_test.dart
index acedca132..a39bef63d 100644
--- a/desktop/test/repository_clone_test.dart
+++ b/desktop/test/repository_clone_test.dart
@@ -293,11 +293,18 @@ void main() {
Set<String> broken = const {},
Map<String, String> hosts = const {'gh-work': 'github.com'},
List<String> aliases = const ['gh-work'],
+ Set<String> untrusted = const {},
}) => RepositoryClone(
sshHosts: _FakeSshHosts(hosts, aliases),
startProcess: (arguments, environment) {
final url = arguments[2];
tried.add(url);
+ if (untrusted.contains(url)) {
+ return Process.start('sh', [
+ '-c',
+ 'echo "Host key verification failed." >&2; exit 128',
+ ]);
+ }
if (refused.contains(url) || broken.contains(url)) {
final message = refused.contains(url)
? 'fatal: could not read Username for https://github.com'
@@ -351,6 +358,61 @@ void main() {
expect(clone.clonedVia, 'gh-work');
});
+ test('an untrusted host key still lets an alias try', () async {
+ final clone = cloner(
+ refused: {'https://github.com/owner/project.git'},
+ untrusted: {'[email protected]:owner/project.git'},
+ );
+ await clone.run(GitHubRepository.parse('owner/project')!, parent.path);
+ expect(tried.last, 'git@gh-work:owner/project.git');
+ expect(clone.clonedVia, 'gh-work');
+ });
+
+ test('an untrusted host key is named when nothing got in', () async {
+ final clone = cloner(
+ refused: {
+ 'https://github.com/owner/project.git',
+ 'git@gh-work:owner/project.git',
+ },
+ untrusted: {'[email protected]:owner/project.git'},
+ );
+ await expectLater(
+ clone.run(GitHubRepository.parse('owner/project')!, parent.path),
+ throwsA(
+ isA<RepositoryCloneException>()
+ .having(
+ (e) => e,
+ 'not a refusal',
+ isNot(isA<RepositoryAccessDenied>()),
+ )
+ .having(
+ (e) => e.message,
+ 'message',
+ contains('ssh -T [email protected]'),
+ ),
+ ),
+ );
+ expect(tried, hasLength(3));
+ });
+
+ test('an alias ssh cannot read is not called another host', () async {
+ final clone = cloner(hosts: const {}, aliases: const []);
+ await expectLater(
+ clone.run(
+ GitHubRepository.parse('git@gh-work:owner/project')!,
+ parent.path,
+ ),
+ throwsA(
+ isA<RepositoryCloneException>().having(
+ (e) => e.message,
+ 'message',
+ 'Could not read gh-work from ssh on this computer. Check that ssh works, then retry.',
+ ),
+ ),
+ );
+ expect(tried, isEmpty);
+ });
+
test('a network failure stops at once', () async {
final clone = cloner(broken: {'https://github.com/owner/project.git'});
await expectLater(
diff --git a/docs/plans/2026-10-30-new-harness-paste-path-or-repository.md b/docs/plans/2026-10-30-new-harness-paste-path-or-repository.md
index 7d85409c0..89f07715e 100644
--- a/docs/plans/2026-10-30-new-harness-paste-path-or-repository.md
+++ b/docs/plans/2026-10-30-new-harness-paste-path-or-repository.md
@@ -54,7 +54,7 @@ stopping at the first that works:
2. the same repository over the other transport (HTTPS ↔ SSH);
3. up to three SSH host aliases from the computer's SSH configuration whose host name is github.com.
-It moves to the next only when GitHub **refused access**. A network failure or a timeout stops at once.
+It moves to the next only when GitHub **refused access** or ssh would not trust its host key. A network failure or a timeout stops at once. A host key among the failures is what the person is told, not "No access": GitHub was not asked.
While it runs, the composer shows the static line **Cloning org/repo…**. A checkout that is reused is no clone, so the line stays **Starting harness…**. When an alias was used, the person
sees one short line, **Cloned via gh-<account>**. The new checkout's `origin` is the address that worked, so
later pushes go through the same account. When every way is refused, the composer shows one line, **No