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.

Desktop: Terminal as a New Harness choice, and the tile hand-over for `harness remote`

0xken158e455a52fb0b
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index c94082c17..845e606cb 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -5532,6 +5532,95 @@ class AppNotifier extends ChangeNotifier {
/// second open is a takeover — the window would fight itself and the first
/// tile would go dark with `TERMINAL_TAKEN_OVER`. [revealAgentView] is what
/// Open Harness uses for the same reason.
+ /// `harness remote`'s hand-over: the tile showing [fromAgentId] on
+ /// [fromMachineId] becomes [agentId]'s on [machineId] — the SAME tile, in
+ /// place: its slot, its pin, its cell key and so its widget all stay, only
+ /// the machine and agent it points at change and the terminal inside it is
+ /// replaced. The shell the command was typed in is then stopped, so the old
+ /// terminal is gone rather than left behind. Nothing happens when no tile
+ /// here shows that agent: the push reaches every window, and the tile is
+ /// in one.
+ ///
+ /// Not [assignAgentToPane]: that removes the tile and inserts a new one,
+ /// which remounts the cell and can slide the grid — a move should read as
+ /// the tile changing what it shows, not as one tile leaving and another
+ /// arriving.
+ ///
+ /// The new agent may not be in [machineId]'s list yet: its `agent_created`
+ /// push travels on that machine's connection, the hand-over on this one, and
+ /// the two are unordered. So the list is asked for again, and the agent is
+ /// waited for a little, before the tile is pointed at it.
+ Future<void> handoffTerminalPane(
+ String fromMachineId,
+ String fromAgentId,
+ String machineId,
+ String agentId,
+ ) async {
+ Swarm? tab;
+ TerminalPane? tile;
+ for (final swarm in swarms) {
+ for (final pane in swarm.panes) {
+ if (pane.machineId == fromMachineId && pane.agentId == fromAgentId) {
+ tab = swarm;
+ tile = pane;
+ break;
+ }
+ }
+ if (tile != null) break;
+ }
+ if (tab == null || tile == null) return;
+ final target = machineStates[machineId];
+ if (target == null) {
+ _lastError = 'The machine the terminal opened on is not in this window.';
+ _lastErrorRetryable = false;
+ notifyListeners();
+ return;
+ }
+ if (!await _awaitAgent(target, agentId)) {
+ _lastError =
+ '${target.machine.displayName} opened a terminal, but it has not appeared yet.';
+ _lastErrorRetryable = false;
+ notifyListeners();
+ return;
+ }
+ if (_disposed || !allPanes.contains(tile)) return;
+ // The old stream goes first (the cell shows "Attaching…" for the moment
+ // between), then the tile is re-pointed and the new one attached.
+ await _detachSession(tile, sendClose: true);
+ if (_disposed) return;
+ tile
+ ..machineId = machineId
+ ..agentId = agentId
+ ..sharedHarness = null
+ ..sharedOwnerName = null;
+ target.activeAgentId = agentId;
+ _dismissedLinkPrompts.remove(machineId);
+ if (tab.id != activeSwarmId) selectSwarm(tab.id);
+ if (tab == activeSwarm) selectedMachineId = machineId;
+ focusPane(tile.id, reveal: true);
+ notifyListeners();
+ _persistLayout();
+ unawaited(_attachSession(tile));
+ // The old shell: `harness remote` has exited in it, and the tile is no
+ // longer its. Ending it is what makes the switch a move, not a copy.
+ await deleteAgent(fromMachineId, fromAgentId);
+ }
+
+ /// Whether [machine] lists [agentId], asking it again and watching for the
+ /// push for a few seconds when it does not yet. The reload is not awaited:
+ /// it waits on the connection being ready, and the agent's own
+ /// `agent_created` usually lands on it first.
+ Future<bool> _awaitAgent(MachineState machine, String agentId) async {
+ bool known() => machine.agents.any((agent) => agent.id == agentId);
+ if (known()) return true;
+ unawaited(_loadMachineData(machine, force: true).catchError((_) {}));
+ for (var attempt = 0; attempt < 32 && !_disposed; attempt++) {
+ await Future<void>.delayed(const Duration(milliseconds: 250));
+ if (known()) return true;
+ }
+ return known();
+ }
+
Future<void> openAgentFromDial(String machineId, String agentId) async {
if (revealAgentView(machineId, agentId)) {
selectedMachineId = machineId;
@@ -6715,6 +6804,30 @@ class AppNotifier extends ChangeNotifier {
}
}
break;
+ case 'remote_terminal_handoff':
+ // `harness remote`, typed in one of this window's terminal tiles, opened a
+ // terminal on another machine: that tile becomes the new agent's, in
+ // place, and the shell it was typed in is ended. Pushed to every
+ // loopback client; only the window holding the tile acts.
+ final fromAgentId = payload['fromAgentId'];
+ final toMachineId = payload['machineId'];
+ final toAgentId = payload['agentId'];
+ if (fromAgentId is String &&
+ fromAgentId.isNotEmpty &&
+ toMachineId is String &&
+ toMachineId.isNotEmpty &&
+ toAgentId is String &&
+ toAgentId.isNotEmpty) {
+ unawaited(
+ handoffTerminalPane(
+ machine.machine.machineId,
+ fromAgentId,
+ toMachineId,
+ toAgentId,
+ ),
+ );
+ }
+ break;
case 'node_status':
final online = payload['online'] == true;
await _applyNodeStatus(machine, online);
diff --git a/desktop/lib/widgets/engine_identity.dart b/desktop/lib/widgets/engine_identity.dart
index 19c0fce05..51414c28d 100644
--- a/desktop/lib/widgets/engine_identity.dart
+++ b/desktop/lib/widgets/engine_identity.dart
@@ -441,14 +441,16 @@ const knownHarnessBase = <String, String>{
'autonomous/bonsai-mcp': 'codex',
};
-/// The daemon's engine id for a plain shell in a pane (⌘⇧T, New Terminal).
+/// The daemon's engine id for a plain shell in a pane (⌘⇧T, New Terminal — and
+/// the last row of New Harness's agent list, as [terminalIdentity]).
///
-/// Deliberately NOT in [_engines]: [allEngines] is what New Harness offers and
-/// what `engines_probe` asks a machine about, and a terminal is neither
-/// installable nor something to pick from that list — it is its own action.
-/// It still has a face, because a tile shows one, and the daemon swaps the
-/// tile's engine for whatever gets typed into it, so the face must come and
-/// go through the same [engineIdentity] every other mark reads.
+/// Deliberately NOT in [_engines]: [allEngines] is what `engines_probe` asks a
+/// machine about and what the Store shelves as an engine, and a terminal is
+/// neither installable nor absent — every machine has a shell. New Harness
+/// lists it on its own, after the agents. It still has a face, because a tile
+/// shows one, and the daemon swaps the tile's engine for whatever gets typed
+/// into it, so the face must come and go through the same [engineIdentity]
+/// every other mark reads.
const String kTerminalEngine = 'terminal';
const EngineIdentity _terminal = EngineIdentity(
@@ -456,9 +458,15 @@ const EngineIdentity _terminal = EngineIdentity(
label: 'Terminal',
category: 'Shell',
tagline: 'Your shell, in a tile',
+ blurb:
+ 'A plain shell on the machine, in a tile beside your agents: no engine, '
+ 'no first task, nothing to install.',
color: Color(0xffa8b0b8),
);
+/// The terminal's face, for the one list that offers it: New Harness.
+EngineIdentity get terminalIdentity => _terminal;
+
/// Whether [engine] is the shell rather than an agent.
bool isTerminalEngine(String? engine) => engine == kTerminalEngine;
diff --git a/desktop/lib/widgets/new_agent_dialog.dart b/desktop/lib/widgets/new_agent_dialog.dart
index 93411cda0..8ba82c9cc 100644
--- a/desktop/lib/widgets/new_agent_dialog.dart
+++ b/desktop/lib/widgets/new_agent_dialog.dart
@@ -221,6 +221,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final asked = widget.initialEngine;
if (asked != null &&
(isHarnessId(asked) ||
+ isTerminalEngine(asked) ||
allEngines.any((identity) => identity.id == asked))) {
// Chosen before the dialog opened: counts as the person's choice, so no
// probe or remembered preference moves it.
@@ -265,7 +266,8 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
/// this build ships a face for, or one the machine has named.
bool _knownChoice(String? id) =>
id != null &&
- (allEngines.any((identity) => identity.id == id) ||
+ (isTerminalEngine(id) ||
+ allEngines.any((identity) => identity.id == id) ||
knownHarnesses.any((identity) => identity.id == id) ||
_harness(id) != null);
@@ -287,6 +289,10 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
bool get _engineIsHarness => isHarnessId(_engine);
+ /// A shell rather than an agent: nothing to install, no task, no permission
+ /// mode, and a folder is a place to open in, not a project to prepare.
+ bool get _engineIsTerminal => isTerminalEngine(_engine);
+
/// The engine a choice actually launches: a harness runs ON one of them, and
/// that is what travels as `engine` beside the harness id.
String _baseEngine(String id) => isHarnessId(id)
@@ -381,8 +387,9 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
String _preferredInstalledEngine() {
// A harness is not in the engine probe at all; its own install state is
- // the machine's catalog, and a remembered harness stays chosen.
- if (_engineIsHarness) return _engine;
+ // the machine's catalog, and a remembered harness stays chosen. Nor is
+ // the terminal: every machine has a shell.
+ if (_engineIsHarness || _engineIsTerminal) return _engine;
final engines = widget.notifier.stateOf(_machineId)?.engines;
if (engines?.loaded != true || engines?[_engine]?.installed == true) {
return _engine;
@@ -493,11 +500,17 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
}
Future<void> _submit() async {
- final project = _preparedFolder == null ? _projectFolder : null;
+ final terminal = _engineIsTerminal;
+ // A terminal never prepares a folder: "Home" is no cwd at all, which the
+ // daemon opens at the machine's home, and a Git repository is not on
+ // offer for it.
+ final project = _preparedFolder == null && !terminal
+ ? _projectFolder
+ : null;
final folder =
_preparedFolder ??
(_folderSource == _FolderSource.local ? _folder : null);
- if ((folder == null && project == null) ||
+ if ((folder == null && project == null && !terminal) ||
_submitting ||
(!_confirmationPending && _waitingForCodexProfile)) {
return;
@@ -563,7 +576,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final error = await widget.notifier.createAgent(
_machineId,
engine: engine,
- folder: folder ?? '',
+ folder: terminal ? folder : folder ?? '',
projectFolder: project,
swarmId: widget.swarmId,
split: widget.split,
@@ -745,6 +758,9 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
'First task',
_takesTask
? 'What should your agent work on? (Optional)'
+ : _engineIsTerminal
+ ? 'A terminal opens straight on your shell; '
+ 'type there.'
: '${_labelOf(_engine)} starts without one. '
'Tell it once it opens.',
null,
@@ -895,6 +911,8 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
? 'Cloning and starting…'
: _installing
? 'Installing ${_labelOf(_engine)}…'
+ : _engineIsTerminal
+ ? 'Opening terminal…'
: 'Creating harness…',
),
),
@@ -1086,6 +1104,18 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
size: size,
),
),
+ // After every agent: a plain shell, for when none of them is
+ // wanted — the same tile ⌘⇧T opens, from here with a machine
+ // and a folder chosen. Every machine has one, so the search
+ // lists it with what the machine has (_installedIds).
+ AgentChoice(
+ id: kTerminalEngine,
+ label: terminalIdentity.label,
+ detail: terminalIdentity.tagline,
+ keywords: '${terminalIdentity.category} shell bash zsh',
+ description: terminalIdentity.blurb,
+ mark: (size) => EngineMark(engine: kTerminalEngine, size: size),
+ ),
],
onChanged: (value) {
if (_choicesLocked) return;
@@ -1096,6 +1126,15 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
_engine = value;
_codexProfile = null;
_codexProfilesBusy = true;
+ // A terminal cannot clone: a Git project chosen for an
+ // agent goes back to the default, as the project picker
+ // is about to be remounted to.
+ if (isTerminalEngine(value) &&
+ _folderSource == _FolderSource.remote) {
+ _repository = null;
+ _folder = null;
+ _folderSource = _FolderSource.newProject;
+ }
}
// The choice is kept across agents; one with no flag simply shows none (and sends
// false, see _submit), so coming back to Claude Code finds it as it was left.
@@ -1137,20 +1176,30 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
SizedBox(height: sectionGap),
_sectionHeader(
'Project',
- 'Start something new or choose an existing project.',
+ _engineIsTerminal
+ ? 'Where the shell opens: your home folder, or a project.'
+ : 'Start something new or choose an existing project.',
HarnessHelpTopic.project,
compactHeight: compactHeight,
),
PageStorage(
bucket: _projectChoices,
child: NewAgentProjectPicker(
- key: ValueKey('new-agent-projects-$_machineId'),
+ // Keyed on the kind too: a terminal's tiles differ (Home, no
+ // Git), and switching remounts the picker with them.
+ key: ValueKey(
+ 'new-agent-projects-$_machineId-'
+ '${_engineIsTerminal ? 'terminal' : 'agent'}',
+ ),
notifier: widget.notifier,
machineId: _machineId,
initialFolder: _folder,
focusNode: _folderFocus,
tileSize: tileSize,
locked: _choicesLocked,
+ // A terminal opens IN a folder, the way a terminal app does: at
+ // home when none is named, never in one prepared or cloned.
+ terminal: _engineIsTerminal,
onBrowse: _browse,
onSelected: (folder, repository) {
if (_choicesLocked) return;
@@ -1476,6 +1525,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final machine = widget.notifier.stateOf(_machineId);
if (machine == null) return null;
final name = machine.machine.displayName;
+ if (isTerminalEngine(id)) return 'Your shell on $name';
if (isHarnessId(id)) {
final entry = _harness(id);
if (entry == null) return null;
@@ -1497,6 +1547,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final machine = widget.notifier.stateOf(_machineId);
if (machine == null) return const {};
return {
+ kTerminalEngine,
for (final entry in machine.dsh.entries)
if (entry.installed && !entry.isViewerPackage) entry.id,
for (final engine in machine.engines.byEngine.values)
diff --git a/desktop/lib/widgets/new_agent_project_picker.dart b/desktop/lib/widgets/new_agent_project_picker.dart
index b122eac29..8997fb952 100644
--- a/desktop/lib/widgets/new_agent_project_picker.dart
+++ b/desktop/lib/widgets/new_agent_project_picker.dart
@@ -22,6 +22,7 @@ class NewAgentProjectPicker extends StatefulWidget {
required this.tileSize,
required this.onSelected,
required this.onBrowse,
+ this.terminal = false,
this.initialFolder,
this.locked = false,
});
@@ -31,6 +32,11 @@ class NewAgentProjectPicker extends StatefulWidget {
final FocusNode focusNode;
final Size tileSize;
final bool locked;
+
+ /// The choice is for a terminal, not an agent: the first tile is the home
+ /// folder (a shell opens there, nothing is prepared), and there is no Git
+ /// tile — a terminal does not clone.
+ final bool terminal;
final void Function(String? folder, GitHubRepository? repository) onSelected;
final Future<String?> Function() onBrowse;
@@ -209,8 +215,11 @@ class _NewAgentProjectPickerState extends State<NewAgentProjectPicker> {
key: const Key('new-agent-folder-newProject'),
size: widget.tileSize,
focusNode: widget.focusNode,
- label: 'New project',
- leading: const Icon(LucideIcons.folderPlus, size: 22),
+ label: widget.terminal ? 'Home' : 'New project',
+ leading: Icon(
+ widget.terminal ? LucideIcons.house : LucideIcons.folderPlus,
+ size: 22,
+ ),
selected: _source == _ProjectSource.newProject,
onPressed: widget.locked
? null
@@ -228,15 +237,16 @@ class _NewAgentProjectPickerState extends State<NewAgentProjectPicker> {
selected: _source == _ProjectSource.local,
onPressed: widget.locked || _browsing ? null : _browse,
),
- AppChoiceTile(
- key: const Key('new-agent-project-git'),
- size: widget.tileSize,
- label: 'Git',
- detail: _repository?.name,
- leading: const Icon(LucideIcons.gitBranch, size: 22),
- selected: _source == _ProjectSource.git,
- onPressed: widget.locked ? null : _git,
- ),
+ if (!widget.terminal)
+ AppChoiceTile(
+ key: const Key('new-agent-project-git'),
+ size: widget.tileSize,
+ label: 'Git',
+ detail: _repository?.name,
+ leading: const Icon(LucideIcons.gitBranch, size: 22),
+ selected: _source == _ProjectSource.git,
+ onPressed: widget.locked ? null : _git,
+ ),
Semantics(
selected: selectedRecent,
inMutuallyExclusiveGroup: true,
diff --git a/desktop/test/new_agent_dsh_test.dart b/desktop/test/new_agent_dsh_test.dart
index c14e29770..f70b3291e 100644
--- a/desktop/test/new_agent_dsh_test.dart
+++ b/desktop/test/new_agent_dsh_test.dart
@@ -377,13 +377,14 @@ void main() {
);
await openAgentSearch(tester);
// Nothing typed: the choice, then what the machine has — Circuit, the
- // harness it installed, ahead of Codex, an engine it has — then the
- // familiar engines, and the Store last. Robot Arm, which it lacks, is
- // not listed.
+ // harness it installed, ahead of Codex, an engine it has, and the
+ // terminal, which every machine has — then the familiar engines, and
+ // the Store last. Robot Arm, which it lacks, is not listed.
expect(agentRows(tester), [
'claude',
'autonomous/autonomous-circuit',
'codex',
+ 'terminal',
'opencode',
]);
await tester.enterText(agentSearch, 'robot');
diff --git a/desktop/test/new_agent_terminal_test.dart b/desktop/test/new_agent_terminal_test.dart
new file mode 100644
index 000000000..c870c2707
--- /dev/null
+++ b/desktop/test/new_agent_terminal_test.dart
@@ -0,0 +1,248 @@
+// A terminal in the Create dialog: the last row of the agent list, always had,
+// no task or permission mode, a Home tile in place of New project and no Git —
+// and a create that names the terminal engine with no folder at all (the daemon
+// opens it at home) or with the folder that was picked.
+import 'dart:async';
+
+import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/engine_availability.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/core/project_folder.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/pane_arrangement.dart';
+import 'package:harness/widgets/agent_picker.dart';
+import 'package:harness/widgets/engine_identity.dart';
+import 'package:harness/widgets/new_agent_dialog.dart';
+
+import 'support/agent_picker.dart';
+
+const _folder = '/work/air-monitor';
+
+class _Folders extends FileSelectorPlatform {
+ @override
+ Future<String?> getDirectoryPath({
+ String? initialDirectory,
+ String? confirmButtonText,
+ }) async => _folder;
+}
+
+/// Stands in for the machine: probes answer at once, creates are recorded.
+class _Notifier extends AppNotifier {
+ _Notifier()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+
+ final launches = <Map<String, Object?>>[];
+
+ @override
+ Future<void> probeEngines(String machineId, {bool force = false}) async {}
+
+ @override
+ Future<void> probeDsh(String machineId, {bool force = false}) async {}
+
+ @override
+ Future<Map<String, dynamic>> listCodexProfiles(
+ String machineId, {
+ Set<String> observedPaths = const {},
+ }) async => {'profiles': <dynamic>[]};
+
+ @override
+ Future<String?> createAgent(
+ String machineId, {
+ required String engine,
+ required String? folder,
+ bool bypassPermission = false,
+ String? permissionMode,
+ String? codexHome,
+ String? dsh,
+ String? prompt,
+ String? name,
+ String? agent,
+ ProjectFolderRequest? projectFolder,
+ String? swarmId,
+ PaneSplitRequest? split,
+ AgentCreationAttempt? attempt,
+ }) async {
+ launches.add({
+ 'machine': machineId,
+ 'engine': engine,
+ 'folder': folder,
+ 'project': projectFolder?.payload,
+ 'prompt': prompt,
+ 'permissionMode': permissionMode,
+ 'bypass': bypassPermission,
+ });
+ return 'Test launch refused.';
+ }
+}
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ setUp(() => FileSelectorPlatform.instance = _Folders());
+
+ const machine = Machine(
+ machineId: 'machine-1',
+ authMode: MachineAuthMode.remote,
+ name: 'harness-remote-box',
+ );
+
+ Future<_Notifier> open(WidgetTester tester) async {
+ // Wide enough for the agent search to show its preview beside the rows.
+ tester.view.physicalSize = const Size(1400, 1000);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.resetPhysicalSize);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ final notifier = _Notifier();
+ addTearDown(notifier.dispose);
+ final state = MachineState(machine)..localOnly = true;
+ state.engines.replace(const [
+ EngineAvailability(engine: 'claude', installed: true),
+ ]);
+ notifier.machineStates['machine-1'] = state;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Builder(
+ builder: (context) => Scaffold(
+ body: TextButton(
+ onPressed: () => showNewAgentDialog(
+ context,
+ notifier,
+ 'machine-1',
+ source: 'machine_row',
+ ),
+ child: const Text('open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('open'));
+ await tester.pumpAndSettle();
+ return notifier;
+ }
+
+ Future<void> create(WidgetTester tester) async {
+ await tester.ensureVisible(
+ find.byKey(const ValueKey('create-agent-submit')),
+ );
+ await tester.tap(find.byKey(const ValueKey('create-agent-submit')));
+ await tester.pump();
+ }
+
+ String engineField(WidgetTester tester) =>
+ tester.widget<AgentPicker>(find.byType(AgentPicker)).value;
+
+ testWidgets(
+ 'the terminal is listed with what the machine has, and never needs installing',
+ (tester) async {
+ await open(tester);
+ await openAgentSearch(tester);
+ final rows = agentRows(tester);
+ expect(
+ rows.where((id) => id == kTerminalEngine).length,
+ 1,
+ reason: 'listed once, among what the machine has',
+ );
+ expect(
+ rows.indexOf(kTerminalEngine),
+ lessThan(rows.indexOf('opencode')),
+ reason: 'every machine has a shell: it comes before the engines this one lacks',
+ );
+ expect(
+ rows.indexOf(kTerminalEngine),
+ greaterThan(rows.indexOf('claude')),
+ );
+ await tester.enterText(agentSearch, 'Terminal');
+ await tester.pumpAndSettle();
+ // The preview of the top match says the shell is simply there.
+ expect(find.text('Your shell on harness-remote-box'), findsOneWidget);
+ expect(find.textContaining('Installs on'), findsNothing);
+ expect(find.textContaining('Not installed'), findsNothing);
+ await tester.tap(
+ find.byKey(const ValueKey('new-agent-agent-row-terminal')),
+ );
+ await tester.pumpAndSettle();
+ expect(engineField(tester), kTerminalEngine);
+ expect(tester.takeException(), isNull);
+ },
+ );
+
+ testWidgets(
+ 'a terminal has no task or permission mode, opens at home by default, and creates as one',
+ (tester) async {
+ final app = await open(tester);
+ await chooseAgent(tester, kTerminalEngine);
+ await tester.pumpAndSettle();
+ // Home in place of New project; a terminal does not clone, so no Git.
+ expect(find.text('Home'), findsOneWidget);
+ expect(find.text('New project'), findsNothing);
+ expect(find.byKey(const Key('new-agent-project-git')), findsNothing);
+ // Nothing to tell it first, and no mode to pick.
+ expect(
+ find.textContaining('A terminal opens straight on your shell'),
+ findsOneWidget,
+ );
+ expect(
+ tester
+ .widget<TextField>(find.byKey(const Key('new-agent-task')))
+ .enabled,
+ isFalse,
+ );
+ expect(find.byKey(const Key('new-agent-permission-mode')), findsNothing);
+
+ await create(tester);
+ expect(app.launches.single, {
+ 'machine': 'machine-1',
+ 'engine': kTerminalEngine,
+ 'folder': null,
+ 'project': null,
+ 'prompt': null,
+ 'permissionMode': null,
+ 'bypass': false,
+ });
+ expect(tester.takeException(), isNull);
+ },
+ );
+
+ testWidgets('a terminal opens in the folder that was picked', (tester) async {
+ final app = await open(tester);
+ await chooseAgent(tester, kTerminalEngine);
+ await tester.pumpAndSettle();
+ final browse = find.byKey(const Key('new-agent-project-browse'));
+ await tester.ensureVisible(browse);
+ await tester.tap(browse);
+ await tester.pumpAndSettle();
+ await create(tester);
+ expect(app.launches.single['engine'], kTerminalEngine);
+ expect(app.launches.single['folder'], _folder);
+ expect(app.launches.single['project'], isNull);
+ });
+
+ testWidgets(
+ 'switching to a terminal from a Git project falls back to Home; switching back restores the tiles',
+ (tester) async {
+ await open(tester);
+ // A Git project for an agent, then the terminal: it cannot clone.
+ final git = find.byKey(const Key('new-agent-project-git'));
+ await tester.ensureVisible(git);
+ expect(git, findsOneWidget);
+ await chooseAgent(tester, kTerminalEngine);
+ await tester.pumpAndSettle();
+ expect(find.byKey(const Key('new-agent-project-git')), findsNothing);
+ expect(find.text('Home'), findsOneWidget);
+ await chooseAgent(tester, 'claude');
+ await tester.pumpAndSettle();
+ expect(find.byKey(const Key('new-agent-project-git')), findsOneWidget);
+ expect(find.text('New project'), findsOneWidget);
+ expect(find.text('Home'), findsNothing);
+ expect(tester.takeException(), isNull);
+ },
+ );
+}
diff --git a/desktop/test/remote_terminal_handoff_test.dart b/desktop/test/remote_terminal_handoff_test.dart
new file mode 100644
index 000000000..4a3a62821
--- /dev/null
+++ b/desktop/test/remote_terminal_handoff_test.dart
@@ -0,0 +1,174 @@
+// `harness remote`, typed in a terminal tile: the daemon pushes `remote_terminal_handoff` and the tile
+// becomes the new agent's on the other machine — same slot, same tab — while the shell it was typed in
+// is stopped. A window with no such tile does nothing; an agent that has not arrived yet is waited for.
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/ws/ws_conn.dart';
+
+class _Connection extends WsConn {
+ _Connection(String machineId)
+ : super(
+ wsBaseUrl: 'ws://fixture.invalid',
+ autonomousEnv: 'test',
+ machineId: machineId,
+ accessTokenProvider: (_, _) async => '',
+ onAuthFailure: (_) {},
+ onEvent: (_) {},
+ onStatus: (_) {},
+ );
+
+ final calls = <(String, Map<String, dynamic>)>[];
+ Future<Map<String, dynamic>> Function(String type, Map<String, dynamic>)?
+ answer;
+
+ @override
+ Future<Map<String, dynamic>> request(
+ String type, {
+ Map<String, dynamic> payload = const {},
+ Duration timeout = const Duration(seconds: 20),
+ }) {
+ calls.add((type, Map.of(payload)));
+ return answer?.call(type, payload) ?? Future.value({});
+ }
+}
+
+Map<String, dynamic> _agentJson(String id, {String engine = 'terminal'}) => {
+ 'id': id,
+ 'name': id,
+ 'engine': engine,
+ 'terminal': {
+ 'runtimes': [
+ {'backend': 'tmux', 'paneId': '%1'},
+ ],
+ },
+};
+
+Agent _agent(String id, {String engine = 'terminal'}) =>
+ Agent.fromJson(_agentJson(id, engine: engine));
+
+MachineState _machine(AppNotifier app, String id, List<Agent> agents) {
+ final machine = Machine(
+ machineId: id,
+ apiKey: '',
+ authMode: MachineAuthMode.remote,
+ name: id,
+ status: 'online',
+ );
+ final state = MachineState(machine)
+ ..nodeOnline =
+ false // keeps _attachSession from dialling out
+ ..agentLoadStatus = AgentLoadStatus.loaded
+ ..agents = agents;
+ app.machines = [...app.machines, machine];
+ app.machineStates[id] = state;
+ return state;
+}
+
+List<(String, String?)> _desk(AppNotifier app) => [
+ for (final p in app.panes) (p.machineId, p.agentId),
+];
+
+void main() {
+ late Map<String, _Connection> connections;
+ AppNotifier notifier() => AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ connectionForTest: (machineId) =>
+ connections.putIfAbsent(machineId, () => _Connection(machineId)),
+ );
+
+ setUp(() => connections = {});
+
+ Future<void> handoff(
+ AppNotifier app, {
+ String from = 'shell-local',
+ String machine = 'box',
+ String agent = 'shell-remote',
+ }) => app.handleEventForTest('mac', {
+ 'type': 'remote_terminal_handoff',
+ 'payload': {'fromAgentId': from, 'machineId': machine, 'agentId': agent},
+ });
+
+ test('the tile the command was typed in becomes the remote terminal, in place, and the old shell is stopped', () async {
+ final app = notifier();
+ _machine(app, 'mac', [
+ _agent('claude-1', engine: 'claude'),
+ _agent('shell-local'),
+ ]);
+ _machine(app, 'box', [_agent('shell-remote')]);
+ await app.assignAgentToPane(null, 'mac', 'claude-1');
+ await app.assignAgentToPane(null, 'mac', 'shell-local');
+ expect(_desk(app), [('mac', 'claude-1'), ('mac', 'shell-local')]);
+ final tile = app.panes[1];
+ tile.pinnedSlot = 1;
+
+ await handoff(app);
+ await Future<void>.delayed(Duration.zero);
+
+ expect(_desk(app), [('mac', 'claude-1'), ('box', 'shell-remote')]);
+ // The same tile, re-pointed: no new pane, no remount, its pin kept.
+ expect(identical(app.panes[1], tile), isTrue);
+ expect(tile.pinnedSlot, 1);
+ expect(app.focusedPane?.agentId, 'shell-remote');
+ expect(
+ connections['mac']!.calls
+ .where((call) => call.$1 == 'agent_delete')
+ .map((call) => call.$2['agentId']),
+ ['shell-local'],
+ reason: 'the shell harness remote ran in is ended, not left behind',
+ );
+ expect(app.machineStates['mac']!.agents.map((a) => a.id), ['claude-1']);
+ app.dispose();
+ });
+
+ test('a window with no tile for that shell does nothing', () async {
+ final app = notifier();
+ _machine(app, 'mac', [_agent('shell-local')]);
+ _machine(app, 'box', [_agent('shell-remote')]);
+ await handoff(app);
+ await Future<void>.delayed(Duration.zero);
+ expect(_desk(app), isEmpty);
+ expect(connections['mac']?.calls ?? [], isEmpty);
+ app.dispose();
+ });
+
+ test('an agent whose agent_created arrives after the hand-over is waited for, then placed', () async {
+ final app = notifier();
+ _machine(app, 'mac', [_agent('shell-local')]);
+ _machine(app, 'box', []);
+ await app.assignAgentToPane(null, 'mac', 'shell-local');
+
+ await handoff(app);
+ await Future<void>.delayed(const Duration(milliseconds: 20));
+ expect(_desk(app), [
+ ('mac', 'shell-local'),
+ ], reason: 'not yet: the agent is unknown');
+ // The other machine's own push lands on its own connection, a moment later.
+ await app.handleEventForTest('box', {
+ 'type': 'agent_created',
+ 'payload': {'agent': _agentJson('shell-remote')},
+ });
+ await Future<void>.delayed(const Duration(milliseconds: 700));
+
+ expect(_desk(app), [('box', 'shell-remote')]);
+ app.dispose();
+ });
+
+ test('a malformed push is ignored', () async {
+ final app = notifier();
+ _machine(app, 'mac', [_agent('shell-local')]);
+ await app.assignAgentToPane(null, 'mac', 'shell-local');
+ await app.handleEventForTest('mac', {
+ 'type': 'remote_terminal_handoff',
+ 'payload': {'fromAgentId': 'shell-local', 'machineId': 'box'},
+ });
+ await Future<void>.delayed(Duration.zero);
+ expect(_desk(app), [('mac', 'shell-local')]);
+ expect(connections['mac']?.calls ?? [], isEmpty);
+ app.dispose();
+ });
+}
diff --git a/docs/cli.md b/docs/cli.md
index 9201dbe94..3ecf4098d 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -22,6 +22,7 @@ works the same on a headless Linux server; the app is not required on a machine,
| `harness browser-link` | Print a reusable seven-day setup link for browsers. |
| `harness remote-password set\|status\|clear` | This machine's persistent password for machine-to-machine links. |
| `harness link connect <id> [--name=<label>]` · `harness link list` · `harness link unlink <id>` | Let this machine reach another of yours, terminating E2EE here; list; unlink. |
+| `harness remote` | From a terminal tile in the app: pick another of your machines (↑/↓, Enter; Online/Offline shown, offline not takeable), link it on the spot if it is not yet, open a terminal there and switch the tile to it — the shell it was typed in is ended. Only inside a Harness tile. |
| `harness grid login [--force] [--json]` · `harness grid logout` | Sign the `grid` CLI in with this computer's account, no second browser. |
| `harness flash [flags]` | Re-flash a plugged-in Harness device over USB. Flags pass straight to the flasher. |
| `harness autonomous-device discover\|status\|list\|pair\|revoke` | Pair Autonomous OS devices found on the LAN, directly, with no relay. |