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
The viewer follows the terminal into every tab; a header control shows or hides it
dee690cb5b183dc
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex c10a2aeb0..c5b9bb0a2 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -3877,47 +3877,50 @@ class AppNotifier extends ChangeNotifier {////// The daemon says where the harness's viewer is (`viewerUrl`); this puts a/// web tile immediately to the RIGHT of the agent's terminal in whichever- /// swarm shows that terminal (the active one first), navigates an open tile- /// when the URL changes, and takes the tile down when the viewer goes away.+ /// tab that shows that terminal, navigates an open tile when the URL+ /// changes, and takes the tile down when the viewer or the terminal goes./// It never steals focus: the person is typing in the terminal the viewer/// belongs to. Nothing is persisted — see [PaneKind.web].void _syncViewerPane(MachineState machine, Agent agent) {final machineId = machine.machine.machineId;final url = agent.viewerUrl;- final open = <(Swarm, TerminalPane)>[- for (final swarm in swarms)- for (final pane in swarm.panes)- if (pane.isWeb &&- pane.machineId == machineId &&- pane.ownerAgentId == agent.id)- (swarm, pane),- ];- if (url == null) {- for (final (swarm, pane) in open) {- swarm.remove(pane);- }- if (open.isNotEmpty) _persistLayout();- return;- }- if (open.isNotEmpty) {- for (final (_, pane) in open) {- pane.url = url;- }- return;- }- if (_dismissedViewers[_viewerKey(machineId, agent.id)] == url) return;- // The swarm holding the agent's terminal — the active one when it does,- // else the first that does. No terminal on any desk, no viewer.- final ordered = [activeSwarm, ...swarms.where((s) => s != activeSwarm)];- for (final swarm in ordered) {+ final dismissed =+ url != null &&+ _dismissedViewers[_viewerKey(machineId, agent.id)] == url;+ var changed = false;+ // Tab by tab: wherever this agent's terminal is, its viewer is beside it,+ // and nowhere else. A terminal opened in a second tab gets a second+ // viewer; a tab whose terminal went loses its viewer.+ for (final swarm in swarms) {final at = swarm.panes.indexWhere((pane) =>!pane.isWeb &&pane.machineId == machineId &&pane.agentId == agent.id,);- if (at < 0) continue;- if (swarm.panes.length >= maxPanes) return;+ final viewers = [+ for (final pane in swarm.panes)+ if (pane.isWeb &&+ pane.machineId == machineId &&+ pane.ownerAgentId == agent.id)+ pane,+ ];+ if (url == null || at < 0) {+ for (final pane in viewers) {+ swarm.remove(pane);+ changed = true;+ }+ continue;+ }+ if (viewers.isNotEmpty) {+ // The same page again is nothing new; a different one navigates in+ // place rather than reopening a tile.+ for (final pane in viewers) {+ pane.url = url;+ }+ continue;+ }+ if (dismissed || swarm.panes.length >= maxPanes) continue;// The viewer goes LEFT of the terminal: it is what the user watches, the// terminal is where they type, and reading order puts the product first.final insertion = at;@@ -3936,15 +3939,49 @@ class AppNotifier extends ChangeNotifier {);swarm.arranged = null;swarm.arrangedKey = null;- // Alone with its terminal, the viewer takes three quarters of the tab —- // a board or a part wants the width, a chat column does not. Only when- // nobody has sized this pair by hand: a manual layout is the user's.+ // Alone with its terminal, the viewer takes two thirds of the tab — a+ // board or a part wants the width, and a third is the least a coding+ // agent's interface reads well at. Only when nobody has sized this pair+ // by hand: a manual layout is the user's.if (swarm.panes.length == 2 && swarm.paneSizes['2:manual'] == null) {swarm.savePaneSizes('2:manual', PaneArrangement.viewerBesideTerminal);}- _persistLayout();+ changed = true;+ }+ if (changed) _persistLayout();+ }++ /// Whether the active tab shows this agent's viewer beside its terminal.+ bool viewerPaneShown(String machineId, String agentId) =>+ activeSwarm.panes.any(+ (pane) =>+ pane.isWeb &&+ pane.machineId == machineId &&+ pane.ownerAgentId == agentId,+ );++ /// The header's viewer control: hide the viewer in this tab, or bring it+ /// back beside the terminal. Bringing it back also lifts a dismissal, so a+ /// page closed by hand earlier opens again on request.+ Future<void> toggleViewerPane(String machineId, String agentId) async {+ final viewer = activeSwarm.panes+ .where(+ (pane) =>+ pane.isWeb &&+ pane.machineId == machineId &&+ pane.ownerAgentId == agentId,+ )+ .firstOrNull;+ if (viewer != null) {+ await closePane(viewer.id);return;}+ final machine = machineStates[machineId];+ final agent = machine?.agents.where((a) => a.id == agentId).firstOrNull;+ if (machine == null || agent == null || agent.viewerUrl == null) return;+ _dismissedViewers.remove(_viewerKey(machineId, agentId));+ _syncViewerPane(machine, agent);+ notifyListeners();}String? _eventAgentId(@@ -5531,6 +5568,18 @@ class AppNotifier extends ChangeNotifier {// background tile going away changes nothing the dial can see.final wasFocused = focusedPaneId == paneId;activeSwarm.remove(pane);+ // A harness's viewer lives beside its terminal and nowhere else: closing+ // the terminal in this tab takes the viewer in this tab with it. The+ // viewer's own close above is different — it is a choice about the page.+ if (!pane.isWeb && pane.agentId != null) {+ for (final viewer in activeSwarm.panes.toList()) {+ if (viewer.isWeb &&+ viewer.machineId == pane.machineId &&+ viewer.ownerAgentId == pane.agentId) {+ activeSwarm.remove(viewer);+ }+ }+ }_settlePins();if (persist) _persistLayout();selectedMachineId = focusedPane?.machineId;diff --git a/desktop/lib/state/pane_arrangement.dart b/desktop/lib/state/pane_arrangement.dartindex 7a397cc88..84513d730 100644--- a/desktop/lib/state/pane_arrangement.dart+++ b/desktop/lib/state/pane_arrangement.dart@@ -9,12 +9,15 @@ class PaneArrangement {PaneArrangement(Iterable<Rect> tiles) : tiles = List.unmodifiable(tiles);final List<Rect> tiles;- /// The split a harness tab opens with: the viewer on the left at three- /// quarters, its terminal on the right. One shared instance, so the code- /// that opened the pair can tell its own split from one the user dragged.+ /// The split a harness tab opens with: the viewer on the left at two+ /// thirds, its terminal on the right. A third of a laptop window is the+ /// narrowest a coding agent's interface reads well at (they are laid out+ /// for 80 columns); a board, a part or a slide has enough at two thirds.+ /// One shared instance, so the code that opened the pair can tell its own+ /// split from one the user dragged.static final viewerBesideTerminal = PaneArrangement(const [- Rect.fromLTRB(0, 0, 0.75, 1),- Rect.fromLTRB(0.75, 0, 1, 1),+ Rect.fromLTRB(0, 0, 2 / 3, 1),+ Rect.fromLTRB(2 / 3, 0, 1, 1),]);static const _epsilon = 0.000001;diff --git a/desktop/lib/widgets/pane_header_actions.dart b/desktop/lib/widgets/pane_header_actions.dartindex 5edd3033e..2ee61d0fc 100644--- a/desktop/lib/widgets/pane_header_actions.dart+++ b/desktop/lib/widgets/pane_header_actions.dart@@ -15,12 +15,19 @@ class PaneHeaderActions extends StatelessWidget {this.onClose,this.onToggleComposer,this.composerVisible = false,+ this.onToggleViewer,+ this.viewerVisible = false,this.details,});final bool zoomed, composerVisible;final VoidCallback? onZoom, onRestart, onDelete, onClose, onToggleComposer;+ /// A harness agent's viewer: show it beside this terminal, or hide it.+ /// Absent for an agent that has no viewer.+ final VoidCallback? onToggleViewer;+ final bool viewerVisible;+/// Folder, branch and machine share the controls' space while idle. Both/// layers keep their size so hovering never changes the title's width.final Widget? details;@@ -69,6 +76,19 @@ class PaneHeaderActions extends StatelessWidget {child: Row(mainAxisSize: MainAxisSize.min,children: [+ if (onToggleViewer != null) ...[+ KeyedSubtree(+ key: const ValueKey('pane-viewer-toggle'),+ child: action(+ viewerVisible ? 'Hide viewer' : 'Show viewer',+ viewerVisible+ ? LucideIcons.panelLeftClose+ : LucideIcons.panelLeftOpen,+ onToggleViewer,+ ),+ ),+ const SizedBox(width: 2),+ ],if (onToggleComposer != null) ...[action(composerVisiblediff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dartindex 51bcba160..a4713d5da 100644--- a/desktop/lib/widgets/terminal_panel.dart+++ b/desktop/lib/widgets/terminal_panel.dart@@ -1670,6 +1670,17 @@ class _TerminalHeader extends StatelessWidget {onClose: onClose,onToggleComposer: remoteComposer,composerVisible: composerVisible,+ // A harness agent's viewer, shown or hidden from the+ // pane it belongs to.+ onToggleViewer: agent?.viewerUrl == null+ ? null+ : () => notifier.toggleViewerPane(+ session.machineId,+ agent!.id,+ ),+ viewerVisible:+ agent != null &&+ notifier.viewerPaneShown(session.machineId, agent.id),details: Tooltip(message: [if (project != null) project.cwd,diff --git a/desktop/test/web_pane_test.dart b/desktop/test/web_pane_test.dartindex 545f05142..45d5c66f6 100644--- a/desktop/test/web_pane_test.dart+++ b/desktop/test/web_pane_test.dart@@ -78,7 +78,7 @@ void main() {expect(app.panes.map((p) => p.id), [first.id, second.id]);});- test('alone with its terminal, the viewer takes three quarters', () async {+ test('alone with its terminal, the viewer takes two thirds', () async {final app = createApp();addTearDown(app.dispose);final input = <TerminalBinaryFrame>[];@@ -88,8 +88,8 @@ void main() {expect(app.panes.map((p) => p.id), [viewer.id, terminalPane.id]);final split = app.activeSwarm.paneSizes['2:manual'];expect(split, isNotNull);- expect(split!.tiles.map((t) => t.left), [0, 0.75]);- expect(split.tiles.map((t) => t.right), [0.75, 1]);+ expect(split!.tiles.map((t) => t.left), [0, 2 / 3]);+ expect(split.tiles.map((t) => t.right), [2 / 3, 1]);expect(split.tiles.map((t) => t.height), [1, 1]);// The viewer going away takes the pair's layout with it, the way any// removal does; a new viewer starts the split afresh.@@ -113,6 +113,64 @@ void main() {expect(app.activeSwarm.paneSizes['2:manual'], same(theirs));});+ test(+ 'the viewer is beside the terminal in every tab that shows it',+ () async {+ final app = createApp();+ addTearDown(app.dispose);+ final input = <TerminalBinaryFrame>[];+ final first = app.adoptSessionForTest(terminal('a0', input));+ final one = app.activeSwarm;+ app.newSwarm(name: 'Second');+ final second = app.adoptSessionForTest(terminal('a0', input));+ final two = app.activeSwarm;+ await _synced(app, 'a0', viewerUrl: 'http://127.0.0.1:4179/');+ expect(app.allPanes.where((p) => p.isWeb), hasLength(2));+ expect(one.panes.map((p) => p.isWeb), [true, false]);+ expect(two.panes.map((p) => p.isWeb), [true, false]);+ expect(one.panes.last, same(first));+ expect(two.panes.last, same(second));+ // A tab that loses the terminal loses the viewer on the next frame; the+ // other tab keeps its pair.+ two.remove(second);+ await _synced(app, 'a0', viewerUrl: 'http://127.0.0.1:4179/');+ expect(two.panes, isEmpty);+ expect(one.panes.map((p) => p.isWeb), [true, false]);+ },+ );++ test('closing the terminal by hand takes its viewer with it', () async {+ final app = createApp();+ addTearDown(app.dispose);+ final input = <TerminalBinaryFrame>[];+ final terminalPane = app.adoptSessionForTest(terminal('a0', input));+ await _synced(app, 'a0', viewerUrl: 'http://127.0.0.1:4179/');+ expect(_viewers(app), hasLength(1));+ await app.closePane(terminalPane.id);+ expect(app.panes, isEmpty);+ // Not a dismissal: the next open of the agent brings the viewer back.+ app.adoptSessionForTest(terminal('a0', input));+ await _synced(app, 'a0', viewerUrl: 'http://127.0.0.1:4179/');+ expect(_viewers(app), hasLength(1));+ });++ test('the header control hides the viewer and brings it back', () async {+ final app = createApp();+ addTearDown(app.dispose);+ final input = <TerminalBinaryFrame>[];+ app.adoptSessionForTest(terminal('a0', input));+ await _synced(app, 'a0', viewerUrl: 'http://127.0.0.1:4179/');+ expect(app.viewerPaneShown('m', 'a0'), isTrue);+ await app.toggleViewerPane('m', 'a0');+ expect(app.viewerPaneShown('m', 'a0'), isFalse);+ // Hidden is a dismissal: the same page does not creep back on a frame.+ await _synced(app, 'a0', viewerUrl: 'http://127.0.0.1:4179/');+ expect(app.viewerPaneShown('m', 'a0'), isFalse);+ await app.toggleViewerPane('m', 'a0');+ expect(app.viewerPaneShown('m', 'a0'), isTrue);+ expect(app.panes.map((p) => p.isWeb), [true, false]);+ });+test('a viewer closed by hand stays closed until the URL changes', () async {final app = createApp();addTearDown(app.dispose);