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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat: add remote password linking action to unlinked machine panes
0xken15c93c55872663
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 94256e99a..d5416e96b 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -8707,11 +8707,12 @@ class AppNotifier extends ChangeNotifier {/// It has to be a tile like any other — the alternative of letting a machine/// take over the whole content area would blank three working terminals/// belonging to two other machines. The one exception is a machine that- /// already needs linking: that state now surfaces as a blocking popup- /// (showLinkMachineScreenDialog, from SwarmScreen) rather- /// than a tile, so opening one here too would just be a redundant "not- /// linked" pane sitting behind it. Selecting is still worth doing — it's- /// what makes the popup's gate notice this machine — the tile is not.+ /// already needs linking: selecting it brings up the Machines panel+ /// (`SwarmScreen._maybeLink`), so opening a tile here too would just be a+ /// redundant "not linked" pane sitting behind it. Selecting is still worth+ /// doing — it's what makes that gate notice this machine — the tile is not.+ /// A tile that ALREADY shows such a machine is a different case and keeps+ /// its own way out: its "Link…" button (`pane_grid.dart`).void showMachinePane(String machineId) {final machine = machineStates[machineId];if (machine == null) return;diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dartindex 78ef34852..a6af1500e 100644--- a/desktop/lib/widgets/pane_grid.dart+++ b/desktop/lib/widgets/pane_grid.dart@@ -26,6 +26,7 @@ import '../terminal/terminal_session.dart';import '../theme/app_theme.dart';import 'agent_drag.dart';import 'harness_join_guide_screen.dart';+import 'link_machine_screen.dart';import 'new_agent_dialog.dart';import 'delete_agent_dialog.dart';import 'fork_agent_dialog.dart';@@ -1430,7 +1431,7 @@ class _PaneContent extends StatelessWidget {terminalPaneCount >= 3;final TerminalNotice? notice;if (machine == null) {- notice = (+ notice = terminalNotice(label: 'Unavailable',icon: Icons.cloud_off,detail: notifier.machineInventoryLoaded@@ -1438,21 +1439,29 @@ class _PaneContent extends StatelessWidget {: 'Waiting for this machine. Retained output is read only.',);} else if (needsLink) {- notice = (+ notice = terminalNotice(label: 'Link required',icon: Icons.link_off,detail:'${machine.machine.displayName} needs linking. Retained output is read only.',+ // A tile still showing its last screen gets the same way out as an+ // empty one — the band's button asks for the remote password.+ actionLabel: 'Link…',+ onAction: () => showLinkMachineScreenDialog(+ context,+ notifier,+ pane.machineId,+ ).ignore(),);} else if (offline) {- notice = (+ notice = terminalNotice(label: 'Offline',icon: Icons.cloud_off,detail:'${machine.machine.displayName} is offline. Retained output is read only.',);} else if (agent == null || !agent.terminalAvailable) {- notice = (+ notice = terminalNotice(label: 'Unavailable',icon: Icons.terminal,detail:@@ -1460,7 +1469,7 @@ class _PaneContent extends StatelessWidget {'This agent is unavailable on ${machine.machine.displayName}. Retained output is read only.',);} else if (agent.launchState == 'failed') {- notice = (+ notice = terminalNotice(label: 'Start failed',icon: Icons.error_outline,detail:@@ -1572,8 +1581,19 @@ class _PaneContent extends StatelessWidget {title: agentName ?? machine.machine.displayName,icon: Icons.link_off,message:- '${machine.machine.displayName} is not linked to this computer yet.',+ '${machine.machine.displayName} is not linked to this computer yet. '+ 'Link it with the remote password set on that machine.',onClose: single && !swarmMode ? null : close,+ // The way out, where the dead end was: the same card the Machines+ // panel's Connect row opens, asking for that machine's remote+ // password. It closes itself the moment the link lands, and this tile+ // goes back to attaching.+ actionLabel: 'Link…',+ onAction: () => showLinkMachineScreenDialog(+ context,+ notifier,+ pane.machineId,+ ).ignore(),);}if (offline) {diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dartindex 2ff98dc0d..44030e930 100644--- a/desktop/lib/widgets/terminal_panel.dart+++ b/desktop/lib/widgets/terminal_panel.dart@@ -42,7 +42,36 @@ import 'pane_header_actions.dart';/// The pane header's own horizontal inset.const double _stripPadding = 14;-typedef TerminalNotice = ({String label, String detail, IconData icon});+typedef TerminalNotice = ({+ String label,+ String detail,+ IconData icon,++ /// A way out of what the notice describes, shown as the header's button —+ /// a machine that needs linking offers to ask for its password. Null where+ /// the state is merely reported and nothing here would fix it.+ String? actionLabel,+ VoidCallback? onAction,+});++/// A [TerminalNotice] without spelling out the fields it does not have.+///+/// A record has no default values, so every caller of a five-field one has to+/// name all five — which is how widening this typedef broke eight untouched+/// call sites at once. This is the one place that knows the full shape.+TerminalNotice terminalNotice({+ required String label,+ required String detail,+ required IconData icon,+ String? actionLabel,+ VoidCallback? onAction,+}) => (+ label: label,+ detail: detail,+ icon: icon,+ actionLabel: actionLabel,+ onAction: onAction,+);class TerminalPanel extends StatefulWidget {final AppNotifier notifier;@@ -1853,24 +1882,25 @@ class _TerminalHeader extends StatelessWidget {notice ??switch (session.status) {TerminalSessionStatus.controlling => null,- TerminalSessionStatus.opening => (+ TerminalSessionStatus.opening => terminalNotice(label: 'Connecting',icon: Icons.sync,detail:'Connecting to this terminal. Retained output is read only.',),- TerminalSessionStatus.resyncing => (+ TerminalSessionStatus.resyncing => terminalNotice(label: 'Restoring',icon: Icons.sync,detail: 'Restoring this terminal. Retained output is read only.',),- TerminalSessionStatus.takenOver => (+ TerminalSessionStatus.takenOver => terminalNotice(label: 'Take control',icon: Icons.lock_outline,detail:'Read only: ${taker ?? 'another app'} controls this terminal. Take control moves input ownership to this app.',),- TerminalSessionStatus.error || TerminalSessionStatus.closed => (+ TerminalSessionStatus.error ||+ TerminalSessionStatus.closed => terminalNotice(label: 'Reconnect',icon: Icons.refresh,detail:@@ -1879,12 +1909,17 @@ class _TerminalHeader extends StatelessWidget {'This stream is closed. Retained output is read only.',),};+ // A notice that carries its own way out owns the button — a machine that+ // needs linking asks for its password there. Otherwise the button is the+ // session's own reconnect, which a notice has always suppressed.+ final noticeAction = notice?.onAction;final canReconnect =notice == null &&!readOnly &&(session.status == TerminalSessionStatus.error ||session.status == TerminalSessionStatus.closed ||session.status == TerminalSessionStatus.takenOver);+ final statusAction = noticeAction ?? (canReconnect ? onReconnect : null);final machine = notifier.stateOf(session.machineId);final agent = machine?.agents.where((a) => a.id == session.agentId)@@ -1990,8 +2025,8 @@ class _TerminalHeader extends StatelessWidget {Tooltip(message: '${status.label}: ${status.detail}',child: IconButton(- tooltip: status.label,- onPressed: canReconnect ? onReconnect : null,+ tooltip: status.actionLabel ?? status.label,+ onPressed: statusAction,icon: Icon(status.icon, size: 14),style: IconButton.styleFrom(foregroundColor: color,@@ -2019,7 +2054,7 @@ class _TerminalHeader extends StatelessWidget {child: Tooltip(message: status.detail,child: TextButton(- onPressed: canReconnect ? onReconnect : null,+ onPressed: statusAction,style: TextButton.styleFrom(foregroundColor: color,disabledForegroundColor: AppColors.textSoft,@@ -2038,6 +2073,12 @@ class _TerminalHeader extends StatelessWidget {const SizedBox(width: 6),Flexible(child: Text(+ // The chip names the STATE; what+ // pressing it does is in the tooltip+ // and in `actionLabel`. "Link+ // required" that can be pressed reads+ // better than a bare verb where every+ // neighbour is a status.status.label,maxLines: 1,overflow: TextOverflow.ellipsis,diff --git a/desktop/test/pane_needs_link_test.dart b/desktop/test/pane_needs_link_test.dartnew file mode 100644index 000000000..d032ab830--- /dev/null+++ b/desktop/test/pane_needs_link_test.dart@@ -0,0 +1,206 @@+// A tile whose machine is not linked is not a dead end.+//+// It used to say "<machine> is not linked to this computer yet." and stop+// there: the only way on was to know that ⌘M opens the Machines panel, find+// the row and press Connect. The way in belongs where the person is looking,+// so the tile asks for the machine's remote password itself — the same card+// the panel opens, which closes on its own the moment the link lands.+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/auth/auth_session.dart';+import 'package:harness/auth/cli_link.dart';+import 'package:harness/core/config.dart';+import 'package:harness/core/models.dart';+import 'package:harness/state/app_state.dart';+import 'package:harness/state/terminal_pane.dart';+import 'package:harness/terminal/terminal_binary.dart';+import 'package:harness/widgets/pane_grid.dart';++import 'swarm_screen_test.dart' show terminal;++class _Link implements CliLink {+ _Link(this.onConnect);+ final Future<CliLinkConnectResult> Function(String machineId, String password)+ onConnect;+ final asked = <String>[];++ @override+ Future<CliLinkConnectResult> connect(+ String machineId,+ String password, {+ void Function(String stage)? onProgress,+ String? displayName,+ }) {+ asked.add(password);+ return onConnect(machineId, password);+ }++ @override+ Future<RemotePasswordSetResult> setRemotePassword(String password) async =>+ const RemotePasswordSetResult();++ @override+ Future<RemotePasswordStatus> remotePasswordStatus() async =>+ const RemotePasswordStatus(hasPassword: false);++ @override+ Future<String?> clearRemotePassword() async => null;++ @override+ Future<CliLinkListResult> list() async => const CliLinkListResult();++ @override+ Future<String?> unlink(String machineId) async => null;+}++void main() {+ late _Link link;+ late AppNotifier app;++ AppNotifier appWith({bool local = false}) {+ final built = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ cliLink: link,+ )..hasNavigationRail = false;+ const machine = Machine(+ machineId: 'remote-1',+ authMode: MachineAuthMode.remote,+ name: 'build-box',+ );+ built.machines = [machine];+ built.machineStates['remote-1'] = MachineState(machine)+ ..localOnly = local+ ..nodeOnline = true+ ..needsLink = true+ ..agentLoadStatus = AgentLoadStatus.needsLink+ ..agents = [const Agent(id: 'a0', name: 'A0', terminalAvailable: true)];+ return built;+ }++ setUp(() {+ link = _Link(+ (machineId, _) async => CliLinkConnectResult(linkedMachineId: machineId),+ );+ });++ Future<void> pump(WidgetTester tester) async {+ tester.view.devicePixelRatio = 1;+ tester.view.physicalSize = const Size(1100, 760);+ addTearDown(tester.view.reset);+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: ListenableBuilder(+ listenable: app,+ builder: (_, _) => PaneGrid(notifier: app, swarmMode: false),+ ),+ ),+ ),+ );+ await tester.pump();+ }++ Future<void> finish(WidgetTester tester) async {+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ }++ /// A tile on the unlinked machine, with nothing attached to it.+ void placeEmptyPane() {+ app.activeSwarm.panes.add(+ TerminalPane(id: 1, machineId: 'remote-1', agentId: 'a0'),+ );+ }++ testWidgets('the tile says how, and its button asks for the password', (+ tester,+ ) async {+ app = appWith();+ placeEmptyPane();+ await pump(tester);++ expect(+ find.textContaining('is not linked to this computer yet'),+ findsOneWidget,+ );+ expect(+ find.textContaining('remote password'),+ findsWidgets,+ reason: 'the sentence says what the button will ask for',+ );++ await tester.tap(find.text('Link…'));+ await tester.pumpAndSettle();+ expect(+ find.byKey(const Key('remote-password-connect-field')),+ findsOneWidget,+ );+ await finish(tester);+ });++ testWidgets('the password links the machine and the card closes itself', (+ tester,+ ) async {+ app = appWith();+ placeEmptyPane();+ await pump(tester);+ await tester.tap(find.text('Link…'));+ await tester.pumpAndSettle();++ await tester.enterText(+ find.byKey(const Key('remote-password-connect-field')),+ 'correct horse battery staple',+ );+ await tester.tap(find.text('enter link machine'));+ await tester.pumpAndSettle();++ expect(link.asked, ['correct horse battery staple']);+ expect(app.stateOf('remote-1')!.needsLink, isFalse);+ expect(+ find.byKey(const Key('remote-password-connect-field')),+ findsNothing,+ reason: 'the card is done the moment the link lands',+ );+ await finish(tester);+ });++ testWidgets('a tile still showing its last screen gets the same way out', (+ tester,+ ) async {+ app = appWith();+ final session = terminal('a0', <TerminalBinaryFrame>[]);+ app.adoptSessionForTest(session);+ app.panes.single.machineId = 'remote-1';+ await pump(tester);++ // The header's own button, over the retained output — the detail sits in+ // its tooltip, so the label is what is on screen.+ expect(+ find.byKey(const Key('remote-password-connect-field')),+ findsNothing,+ reason: 'nothing asked yet',+ );+ await tester.tap(find.text('Link required'));+ await tester.pumpAndSettle();+ expect(+ find.byKey(const Key('remote-password-connect-field')),+ findsOneWidget,+ );+ await finish(tester);+ });++ testWidgets('a linked machine says nothing about linking', (tester) async {+ app = appWith();+ app.stateOf('remote-1')!+ ..needsLink = false+ ..agentLoadStatus = AgentLoadStatus.loaded+ ..terminalCapabilityAvailable = true;+ placeEmptyPane();+ await pump(tester);++ expect(find.text('Link…'), findsNothing);+ await finish(tester);+ });+}diff --git a/desktop/test/terminal_control_banner_test.dart b/desktop/test/terminal_control_banner_test.dartindex 6c24b30df..c52080b9b 100644--- a/desktop/test/terminal_control_banner_test.dart+++ b/desktop/test/terminal_control_banner_test.dart@@ -240,7 +240,7 @@ void main() {// A pane-level notice (offline, unlinked) already explains itself.await pump(tester,- notice: (+ notice: terminalNotice(label: 'Offline',icon: Icons.cloud_off,detail: 'Test host is offline.',@@ -631,7 +631,7 @@ void main() {app.stateOf('m')!.nodeOnline = false;await pump(tester,- notice: (+ notice: terminalNotice(label: 'Offline',icon: Icons.cloud_off,detail: 'Test host is offline.',