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.

Restore Restart Harness in pane controls

dee918fd6a71104
diff --git a/desktop/lib/widgets/machine_rail.dart b/desktop/lib/widgets/machine_rail.dart
index 068f58dcd..bd202b85f 100644
--- a/desktop/lib/widgets/machine_rail.dart
+++ b/desktop/lib/widgets/machine_rail.dart
@@ -18,6 +18,7 @@ import '../shortcuts/app_shortcuts.dart';
import '../state/app_state.dart';
import 'agent_drag.dart';
import 'delete_agent_dialog.dart';
+import 'restart_agent_action.dart';
import 'rename_agent_dialog.dart';
import 'account_footer.dart';
import 'device_row.dart';
@@ -1020,31 +1021,8 @@ class _AgentRowState extends State<_AgentRow> {
agent.name,
);
- // Restart is disruptive (it briefly kills the current process) but NOT destructive — the same
- // agent survives, resumed where possible — so unlike delete it fires straight away, no
- // confirmation dialog, and just surfaces a failure the same lightweight way.
- Future<void> _restartAgent() async {
- final result = await notifier.restartAgent(
- state.machine.machineId,
- agent.id,
- );
- if (!mounted) return;
- final error = result.error;
- if (error != null) {
- ScaffoldMessenger.of(context)
- .showSnackBar(SnackBar(content: Text(error)));
- return;
- }
- if (!result.resumed) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(
- content: Text(
- 'Restarted with a new session — the previous one could not be resumed.',
- ),
- ),
- );
- }
- }
+ Future<void> _restartAgent() =>
+ restartHarness(context, notifier, state.machine.machineId, agent.id);
@override
Widget build(BuildContext context) {
@@ -1225,7 +1203,7 @@ class _AgentRowState extends State<_AgentRow> {
const AppMenuDivider(),
AppMenuItem(
icon: LucideIcons.refreshCw300,
- label: 'Restart',
+ label: 'Restart Harness',
onPressed: () {
_agentMenu.close();
_restartAgent();
diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dart
index 9af38c0a7..2cfaa92a3 100644
--- a/desktop/lib/widgets/pane_grid.dart
+++ b/desktop/lib/widgets/pane_grid.dart
@@ -24,6 +24,7 @@ import 'agent_drag.dart';
import 'harness_join_guide_screen.dart';
import 'new_agent_dialog.dart';
import 'delete_agent_dialog.dart';
+import 'restart_agent_action.dart';
import 'terminal_panel.dart';
import 'pane_resize_handle.dart';
import 'pane_split_edges.dart';
@@ -1332,6 +1333,10 @@ class _PaneContent extends StatelessWidget {
notice: notice,
onToggleComposer: () => notifier.toggleComposer(pane.id),
onClose: single && !swarmMode ? null : close,
+ onRestart: agent == null || offline || needsLink
+ ? null
+ : () =>
+ restartHarness(context, notifier, pane.machineId, agent.id),
// The same confirmation the rail's row menu opens. Only for an
// agent the machine still lists — a pane whose agent is already
// gone has nothing to end.
diff --git a/desktop/lib/widgets/pane_header_actions.dart b/desktop/lib/widgets/pane_header_actions.dart
index 53e384a71..69c673c7e 100644
--- a/desktop/lib/widgets/pane_header_actions.dart
+++ b/desktop/lib/widgets/pane_header_actions.dart
@@ -10,6 +10,7 @@ class PaneHeaderActions extends StatelessWidget {
super.key,
required this.zoomed,
this.onZoom,
+ this.onRestart,
this.onDelete,
this.onClose,
this.onToggleComposer,
@@ -18,7 +19,7 @@ class PaneHeaderActions extends StatelessWidget {
});
final bool zoomed, composerVisible;
- final VoidCallback? onZoom, onDelete, onClose, onToggleComposer;
+ final VoidCallback? onZoom, onRestart, onDelete, onClose, onToggleComposer;
/// Folder, branch and machine share the controls' space while idle. Both
/// layers keep their size so hovering never changes the title's width.
@@ -84,6 +85,8 @@ class PaneHeaderActions extends StatelessWidget {
onZoom,
),
const SizedBox(width: 2),
+ action('Restart Harness', LucideIcons.refreshCw, onRestart),
+ const SizedBox(width: 2),
action('Stop Harness', LucideIcons.circleStop, onDelete),
const SizedBox(width: 2),
action('Close Pane', LucideIcons.x, onClose),
diff --git a/desktop/lib/widgets/restart_agent_action.dart b/desktop/lib/widgets/restart_agent_action.dart
new file mode 100644
index 000000000..336d59f68
--- /dev/null
+++ b/desktop/lib/widgets/restart_agent_action.dart
@@ -0,0 +1,23 @@
+import 'package:flutter/material.dart';
+
+import '../state/app_state.dart';
+
+/// Relaunches the same harness through the existing CLI restart action.
+Future<void> restartHarness(
+ BuildContext context,
+ AppNotifier notifier,
+ String machineId,
+ String agentId,
+) async {
+ final result = await notifier.restartAgent(machineId, agentId);
+ if (!context.mounted) return;
+ final message =
+ result.error ??
+ (result.resumed
+ ? null
+ : 'Restarted with a new session — the previous one could not be resumed.');
+ if (message != null) {
+ ScaffoldMessenger.of(context)
+ .showSnackBar(SnackBar(content: Text(message)));
+ }
+}
diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dart
index a950c3e1d..839298cd9 100644
--- a/desktop/lib/widgets/terminal_panel.dart
+++ b/desktop/lib/widgets/terminal_panel.dart
@@ -45,6 +45,7 @@ class TerminalPanel extends StatefulWidget {
/// Takes this tile off the grid. Null when the terminal is the whole window,
/// where there is nothing to close it back to.
final VoidCallback? onClose;
+ final VoidCallback? onRestart;
final VoidCallback? onDelete;
final VoidCallback? onToggleZoom;
@@ -96,6 +97,7 @@ class TerminalPanel extends StatefulWidget {
this.notice,
this.onToggleComposer,
this.onClose,
+ this.onRestart,
this.onDelete,
this.onToggleZoom,
this.zoomed = false,
@@ -1338,6 +1340,7 @@ class _TerminalPanelState extends State<TerminalPanel>
project: agent == null ? null : machine?.projectOf(agent),
compact: widget.compactHeader,
close: widget.onClose != null,
+ restart: widget.onRestart != null,
delete: widget.onDelete != null,
composer: widget.composerVisible,
toggleComposer: widget.onToggleComposer != null,
@@ -1359,6 +1362,9 @@ class _TerminalPanelState extends State<TerminalPanel>
? null
: () => widget.onToggleZoom?.call(),
onClose: widget.onClose == null ? null : () => widget.onClose?.call(),
+ onRestart: widget.onRestart == null
+ ? null
+ : () => widget.onRestart?.call(),
onDelete: widget.onDelete == null
? null
: () => widget.onDelete?.call(),
@@ -1379,6 +1385,7 @@ class _TerminalHeader extends StatelessWidget {
final TerminalNotice? notice;
final bool readOnly;
final VoidCallback? onClose;
+ final VoidCallback? onRestart;
/// Ends the agent (with a confirmation), as the rail's row menu does. Null
/// where the pane cannot name a live agent to end.
@@ -1405,6 +1412,7 @@ class _TerminalHeader extends StatelessWidget {
this.notice,
this.readOnly = false,
this.onClose,
+ this.onRestart,
this.onDelete,
this.compact = false,
this.onToggleZoom,
@@ -1482,7 +1490,7 @@ class _TerminalHeader extends StatelessWidget {
final remoteComposer = machine != null && !machine.isLocalMachine
? onToggleComposer
: null;
- final actionsWidth = remoteComposer == null ? 88.0 : 118.0;
+ final actionsWidth = remoteComposer == null ? 118.0 : 148.0;
final folder =
project?.cwd
.split(RegExp(r'[/\\]'))
@@ -1615,6 +1623,7 @@ class _TerminalHeader extends StatelessWidget {
child: PaneHeaderActions(
zoomed: zoomed,
onZoom: onToggleZoom,
+ onRestart: onRestart,
onDelete: onDelete,
onClose: onClose,
onToggleComposer: remoteComposer,
diff --git a/desktop/test/pane_restart_test.dart b/desktop/test/pane_restart_test.dart
new file mode 100644
index 000000000..913232d19
--- /dev/null
+++ b/desktop/test/pane_restart_test.dart
@@ -0,0 +1,98 @@
+import 'package:flutter/gestures.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/widgets/pane_header_actions.dart';
+import 'package:harness/ws/ws_conn.dart';
+
+import 'swarm_screen_test.dart' show mount, terminal;
+import 'swarm_state_test.dart' show createApp;
+
+class _RestartConnection extends WsConn {
+ _RestartConnection(this.reply)
+ : super(
+ wsBaseUrl: 'ws://fixture.invalid',
+ autonomousEnv: 'test',
+ machineId: 'm',
+ accessTokenProvider: (_, _) async => '',
+ onAuthFailure: (_) {},
+ onEvent: (_) {},
+ onStatus: (_) {},
+ );
+ final Map<String, dynamic> reply;
+ final calls = <(String, Map<String, dynamic>)>[];
+
+ @override
+ Future<Map<String, dynamic>> request(
+ String type, {
+ Map<String, dynamic> payload = const {},
+ Duration timeout = const Duration(seconds: 20),
+ }) async {
+ calls.add((type, payload));
+ return reply;
+ }
+}
+
+void main() {
+ for (final (reply, message) in <(Map<String, dynamic>, String?)>[
+ ({'resumed': true}, null),
+ (
+ {'resumed': false},
+ 'Restarted with a new session — the previous one could not be resumed.',
+ ),
+ (
+ {'error': 'RESTART_FAILED', 'detail': 'The engine could not restart.'},
+ 'The engine could not restart.',
+ ),
+ ]) {
+ testWidgets('pane restarts its own harness and reports $reply', (
+ tester,
+ ) async {
+ final connection = _RestartConnection(reply);
+ final app = createApp(connectionForTest: (_) => connection);
+ app.machineStates['m']!.nodeOnline = true;
+ final first = app.adoptSessionForTest(terminal('a0', []));
+ final session = first.session;
+ final second = app.adoptSessionForTest(terminal('a1', []));
+ await mount(tester, app);
+ expect(app.focusedPane, same(second));
+ final controls = find.byType(PaneHeaderActions).first;
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: tester.getCenter(controls));
+ await tester.pump(const Duration(milliseconds: 120));
+ await tester.tap(
+ find.descendant(
+ of: controls,
+ matching: find.byTooltip('Restart Harness'),
+ ),
+ );
+ await tester.pump();
+ expect(connection.calls, hasLength(1));
+ expect(connection.calls.single.$1, 'agent_restart');
+ expect(connection.calls.single.$2, {'agentId': 'a0'});
+ expect(app.panes, [first, second]);
+ expect(first.session, same(session));
+ expect(find.byType(AlertDialog), findsNothing);
+ if (message == null) {
+ expect(find.byType(SnackBar), findsNothing);
+ } else {
+ expect(find.text(message), findsOneWidget);
+ }
+ app.machineStates['m']!.nodeOnline = false;
+ app.notifyListeners();
+ await tester.pump();
+ final restart = tester.widget<IconButton>(
+ find.descendant(
+ of: controls,
+ matching: find.byWidgetPredicate(
+ (widget) =>
+ widget is IconButton && widget.tooltip == 'Restart Harness',
+ ),
+ ),
+ );
+ expect(restart.onPressed, isNull);
+ await mouse.removePointer();
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ });
+ }
+}
diff --git a/desktop/test/swarm_interactions_test.dart b/desktop/test/swarm_interactions_test.dart
index e9cf4fbf2..e98f665fb 100644
--- a/desktop/test/swarm_interactions_test.dart
+++ b/desktop/test/swarm_interactions_test.dart
@@ -237,7 +237,7 @@ void main() {
final controls = find.byType(PaneHeaderActions).first;
expect(
find.descendant(of: controls, matching: find.byType(IconButton)),
- findsNWidgets(4),
+ findsNWidgets(5),
);
expect(find.byTooltip('Stop Harness').first.hitTestable(), findsNothing);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
diff --git a/desktop/test/terminal_panel_presentation_test.dart b/desktop/test/terminal_panel_presentation_test.dart
index d4534ae18..59aaf4f9c 100644
--- a/desktop/test/terminal_panel_presentation_test.dart
+++ b/desktop/test/terminal_panel_presentation_test.dart
@@ -19,6 +19,7 @@ void main() {
final revision = ValueNotifier(0);
final closed = <int>[];
final deleted = <int>[];
+ final restarted = <int>[];
final zoomed = <int>[];
final composed = <int>[];
tester.view.devicePixelRatio = 1;
@@ -35,6 +36,7 @@ void main() {
compactHeader: true,
onClose: () => closed.add(version),
onDelete: () => deleted.add(version),
+ onRestart: () => restarted.add(version),
onToggleZoom: () => zoomed.add(version),
zoomed: version >= 2,
onToggleComposer: () => composed.add(version),
@@ -52,11 +54,13 @@ void main() {
await tester.pump(const Duration(milliseconds: 120));
await tester.tap(find.byTooltip('Show message composer'));
await tester.tap(find.byTooltip('Zoom Pane'));
+ await tester.tap(find.byTooltip('Restart Harness'));
await tester.tap(find.byTooltip('Stop Harness'));
await tester.tap(find.byTooltip('Close Pane'));
await tester.pump();
expect(closed, [1]);
expect(deleted, [1]);
+ expect(restarted, [1]);
expect(zoomed, [1]);
expect(composed, [1]);
session.agentName = 'Renamed terminal';
@@ -160,7 +164,7 @@ void main() {
expect(find.byTooltip('Stop Harness').hitTestable(), findsNothing);
expect(
find.descendant(of: controls, matching: find.byType(IconButton)),
- findsNWidgets(local ? 3 : 4),
+ findsNWidgets(local ? 4 : 5),
);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: tester.getCenter(title));
diff --git a/docs/harness-agent-first-tabs.md b/docs/harness-agent-first-tabs.md
index 1c0fb2ebe..81990b318 100644
--- a/docs/harness-agent-first-tabs.md
+++ b/docs/harness-agent-first-tabs.md
@@ -152,14 +152,17 @@ shows **folder • branch • machine**, omitting unavailable folder/branch data
Long details truncate, with full context in the session-name tooltip.
Hovering anywhere on the header replaces the details with small, muted controls:
-**Zoom Pane, Stop Harness, Close Pane**, with **Keyboard** first for remote sessions. Keyboard
+**Zoom Pane, Restart Harness, Stop Harness, Close Pane**, with **Keyboard** first for remote sessions. Keyboard
focus also reveals the controls. The title keeps the same space during the swap,
and hovering retains the terminal renderer. Stop uses a Lucide circle-stop icon
and an explicit confirmation: it ends the engine process and removes the active
harness, preserving project files and saved conversation history. The existing
`agent_delete` protocol remains unchanged. It is not Pause and promises no live
process suspension/resume. Close Pane removes only this view and leaves the agent
-running. Keyboard toggles the remote message composer.
+running. Restart uses the same circular-arrow icon and existing restart action as
+the agent menu. It relaunches the same harness, resuming the conversation where
+supported; failures and a fresh-session fallback are shown in a snackbar. It is
+disabled for unavailable or unlinked machines. Keyboard toggles the remote message composer.
Resize grips are invisible while idle and appear on divider hover, keyboard
focus or active drag. Their hit targets and resize behavior stay the same. The
diff --git a/docs/harness-v2-handoff.md b/docs/harness-v2-handoff.md
index 112e5d3b4..29d93ee4c 100644
--- a/docs/harness-v2-handoff.md
+++ b/docs/harness-v2-handoff.md
@@ -74,7 +74,7 @@ are:
**Open Machines Manager**, with visible Rename actions.
- Pane headers show agent icon/session on the left and folder/branch/machine
on the right, with a small muted branch glyph before the branch. Header hover
- or keyboard focus reveals **Zoom Pane, Stop Harness, Close Pane**, with
+ or keyboard focus reveals **Zoom Pane, Restart Harness, Stop Harness, Close Pane**, with
Keyboard first for remote sessions. Stop uses a circle-stop icon and a clear
confirmation; the existing action ends the process and removes its active
entry, preserving project files and saved conversation history. Divider grips appear on
@@ -142,7 +142,7 @@ restart/upgrade the user's CLI daemon or type test commands into working agents.
Temporary logs, SDKs, builds, account state and preview processes do not transfer
with Git.
-## Discussion still pending implementation
+## Creation discussion and approved preview work
The **larger New Harness creation form is not implemented**. The discussed
shape is New Project / Existing Folder / Clone Repository, remembered agent,
@@ -151,7 +151,11 @@ project would create its own folder, requiring no picker or typing. Do not infer
the project from the current pane in a multiproject workspace. The user has been
told candidly that entry/chrome polish is separate from this form redesign.
-The **search preview remains discussion-only**, explicitly by user request.
+The user has now explicitly approved **building a useful, beautiful, fast search
+preview** in Cmd-O and New Tab. Validate real excerpt content first, then build
+the shared UI and cache. The [preview proposal](harness-search-preview.md) records
+the acceptance criteria. The [Rex study](mitchellh-rex-study.md) is saved, pushed,
+and open for the user in Chrome. The following audit remains relevant:
The old implementation at f04f6d3 read only already-attached terminal buffers,
showed at most twelve nonblank tail lines, provided no group preview, and froze
the snapshot while the selection stayed put. Terminal prompts/tool noise rarely