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
Avoid formatting unopened agents on History focus updates
deee8ddd36d7cb3
diff --git a/desktop/lib/state/swarm_navigation.dart b/desktop/lib/state/swarm_navigation.dartindex 098d1fa17..3ced46257 100644--- a/desktop/lib/state/swarm_navigation.dart+++ b/desktop/lib/state/swarm_navigation.dart@@ -125,7 +125,11 @@ class SwarmNavigationHistory {if (listEquals(_menuPresentation, presentation)) return _menuDestinations;_menuPresentation = presentation;final catalog = {- for (final entry in swarmDestinations(app, recent: _recent))+ for (final entry in swarmDestinations(+ app,+ recent: _recent,+ openOnly: true,+ ))if (entry.hasView) entry.id: entry,};return _menuDestinations = List.unmodifiable([@@ -633,6 +637,7 @@ List<SwarmDestination> closedWorkDestinations(AppNotifier app) => [List<SwarmDestination> swarmDestinations(AppNotifier app, {List<String> recent = const [],+ bool openOnly = false,}) {final owners = <String, List<Swarm>>{};final agents = <String, (MachineState, Agent)>{};@@ -682,7 +687,10 @@ List<SwarmDestination> swarmDestinations(),);}- for (final id in {...owners.keys, ...agents.keys}) {+ // History refreshes on focus changes, but only offers existing views. Keep+ // their normal owner/metadata resolution without formatting every unopened+ // runtime in discovery. Add agent continues to include those runtimes.+ for (final id in {...owners.keys, if (!openOnly) ...agents.keys}) {final memberships = owners[id] ?? const <Swarm>[];final row = agents[id];if (memberships.isEmpty && row?.$2.terminalAvailable != true) continue;diff --git a/desktop/test/benchmarks/swarm_benchmark.dart b/desktop/test/benchmarks/swarm_benchmark.dartindex 725525322..82724d8d4 100644--- a/desktop/test/benchmarks/swarm_benchmark.dart+++ b/desktop/test/benchmarks/swarm_benchmark.dart@@ -3,6 +3,7 @@import 'dart:convert';import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness/auth/auth_session.dart';import 'package:harness/core/config.dart';@@ -213,91 +214,145 @@ void main() {navigator.setQuery('agent 0 machine 0');}, setup: () => navigator.setQuery(''))})}',);+ final history = SwarmNavigationHistory();+ for (final swarm in app.swarms) {+ app.selectSwarm(swarm.id);+ for (final pane in swarm.panes) {+ app.focusPane(pane.id);+ history.record(app);+ }+ }+ expect(history.menuDestinations(app), hasLength(60));+ debugPrint(+ 'SWARM_BENCH ${jsonEncode({'kind': 'headless_debug_cpu', 'operation': 'native_history_snapshot', 'discoveredAgents': 2000, 'swarms': 12, 'entries': 60, 'changedFocus': measure(() {+ history.menuDestinations(app);+ }, setup: () {+ app.focusPaneBy(1);+ history.record(app);+ }), 'unchanged': measure(() {+ history.menuDestinations(app);+ })})}',+ );});- for (final swarmCount in [4, 12]) {- testWidgets('tab-switch CPU benchmark with $swarmCount retained swarms', (- tester,- ) async {- final app = createApp();- app.machineStates['m']!.nodeOnline = true;- final first = app.activeSwarmId;- for (var swarm = 0; swarm < swarmCount; swarm++) {- if (swarm != 0) app.newSwarm();- for (var pane = 0; pane < 4; pane++) {- final id = 'a${swarm * 4 + pane}';- final session =- TerminalSession(- machineId: 'm',- agentId: id,- agentName: 'Agent $id',- engineId: 'codex',- send: (_, _) async => true,- sendBinary: (_) async => true,- )- ..status = TerminalSessionStatus.controlling- ..streamId = 'stream-$id';- session.terminal.write(- List.generate(- 1000,- (line) =>- '\x1b[32m$line\x1b[0m terminal output with project context\r\n',- ).join(),- );- app.adoptSessionForTest(session);+ for (final scenario in [+ (swarms: 4, native: false),+ (swarms: 12, native: false),+ (swarms: 4, native: true),+ (swarms: 12, native: true),+ ]) {+ final swarmCount = scenario.swarms;+ final chrome = scenario.native ? 'native bridge' : 'Flutter tabs';+ testWidgets(+ 'tab-switch CPU benchmark with $swarmCount retained swarms ($chrome)',+ (tester) async {+ final app = createApp();+ app.machineStates['m']!.nodeOnline = true;+ var nativeUpdates = 0;+ if (scenario.native) {+ // Exercise production History and bridge serialization without AppKit.+ // This is still a headless CPU test, not native input/display timing.+ const channel = MethodChannel('harness/swarm_tabs');+ final messenger = tester.binding.defaultBinaryMessenger;+ messenger.setMockMethodCallHandler(channel, (call) async {+ if (call.method == 'update') nativeUpdates++;+ return null;+ });+ addTearDown(() => messenger.setMockMethodCallHandler(channel, null));+ app.machineStates['m']!.agents = [+ for (var i = 0; i < 2000; i++)+ Agent(+ id: 'a$i',+ name: 'Agent a$i',+ engine: 'codex',+ terminalAvailable: true,+ project: AgentProject(+ name: 'Project ${i % 50}',+ cwd: '/work/project-${i % 50}',+ branch: 'main',+ ),+ ),+ ];}- }- app.selectSwarm(first);- await mount(tester, app);- for (var warmup = 0; warmup < swarmCount * 3; warmup++) {- app.stepSwarm(1);- await tester.pump();- }- final times = <int>[];- for (var sample = 0; sample < 60; sample++) {- final watch = Stopwatch()..start();- app.stepSwarm(1);- await tester.pump();- times.add(watch.elapsedMicroseconds);- }- expect(find.byType(TerminalPanel), findsNWidgets(4));- expect(- find.byType(TerminalPanel, skipOffstage: false),- findsNWidgets(swarmCount * 4),- );- final rebuilds = <String, int>{};- debugOnRebuildDirtyWidget = (element, _) {- final type = element.widget.runtimeType.toString();- rebuilds.update(type, (count) => count + 1, ifAbsent: () => 1);- };- try {- app.stepSwarm(1);- await tester.pump();- } finally {- debugOnRebuildDirtyWidget = null;- }- final largest = rebuilds.entries.toList()- ..sort((a, b) => b.value.compareTo(a.value));- final focusTimes = <int>[];- for (var sample = 0; sample < 60; sample++) {- final watch = Stopwatch()..start();- app.focusPaneBy(1);- await tester.pump();- focusTimes.add(watch.elapsedMicroseconds);- }- var focusRebuilds = 0;- debugOnRebuildDirtyWidget = (_, _) => focusRebuilds++;- try {- app.focusPaneBy(1);- await tester.pump();- } finally {- debugOnRebuildDirtyWidget = null;- }- debugPrint(- 'SWARM_BENCH ${jsonEncode({'kind': 'headless_debug_cpu', 'swarms': swarmCount, 'terminals': swarmCount * 4, 'scrollbackLinesPerTerminal': 1000, 'viewport': '1280x800', 'tabSwitchAndFrame': distribution(times), 'rebuildsPerSwitch': rebuilds.values.fold(0, (total, count) => total + count), 'focusAndFrame': distribution(focusTimes), 'rebuildsPerFocus': focusRebuilds, 'mostRebuiltWidgets': Map.fromEntries(largest.take(12))})}',- );- await tester.pumpWidget(const SizedBox());- app.dispose();- });+ final first = app.activeSwarmId;+ for (var swarm = 0; swarm < swarmCount; swarm++) {+ if (swarm != 0) app.newSwarm();+ for (var pane = 0; pane < 4; pane++) {+ final id = 'a${swarm * 4 + pane}';+ final session =+ TerminalSession(+ machineId: 'm',+ agentId: id,+ agentName: 'Agent $id',+ engineId: 'codex',+ send: (_, _) async => true,+ sendBinary: (_) async => true,+ )+ ..status = TerminalSessionStatus.controlling+ ..streamId = 'stream-$id';+ session.terminal.write(+ List.generate(+ 1000,+ (line) =>+ '\x1b[32m$line\x1b[0m terminal output with project context\r\n',+ ).join(),+ );+ app.adoptSessionForTest(session);+ }+ }+ app.selectSwarm(first);+ await mount(tester, app, nativeTabs: scenario.native);+ for (var warmup = 0; warmup < swarmCount * 3; warmup++) {+ app.stepSwarm(1);+ await tester.pump();+ }+ final times = <int>[];+ for (var sample = 0; sample < 60; sample++) {+ final watch = Stopwatch()..start();+ app.stepSwarm(1);+ await tester.pump();+ times.add(watch.elapsedMicroseconds);+ }+ expect(find.byType(TerminalPanel), findsNWidgets(4));+ expect(+ find.byType(TerminalPanel, skipOffstage: false),+ findsNWidgets(swarmCount * 4),+ );+ final rebuilds = <String, int>{};+ debugOnRebuildDirtyWidget = (element, _) {+ final type = element.widget.runtimeType.toString();+ rebuilds.update(type, (count) => count + 1, ifAbsent: () => 1);+ };+ try {+ app.stepSwarm(1);+ await tester.pump();+ } finally {+ debugOnRebuildDirtyWidget = null;+ }+ final largest = rebuilds.entries.toList()+ ..sort((a, b) => b.value.compareTo(a.value));+ final focusTimes = <int>[];+ for (var sample = 0; sample < 60; sample++) {+ final watch = Stopwatch()..start();+ app.focusPaneBy(1);+ await tester.pump();+ focusTimes.add(watch.elapsedMicroseconds);+ }+ var focusRebuilds = 0;+ debugOnRebuildDirtyWidget = (_, _) => focusRebuilds++;+ try {+ app.focusPaneBy(1);+ await tester.pump();+ } finally {+ debugOnRebuildDirtyWidget = null;+ }+ if (scenario.native) expect(nativeUpdates, greaterThan(120));+ debugPrint(+ 'SWARM_BENCH ${jsonEncode({'kind': 'headless_debug_cpu', 'chrome': scenario.native ? 'native_bridge_stubbed' : 'flutter_tabs', 'discoveredAgents': app.machineStates['m']!.agents.length, 'swarms': swarmCount, 'terminals': swarmCount * 4, 'scrollbackLinesPerTerminal': 1000, 'viewport': '1280x800', 'tabSwitchAndFrame': distribution(times), 'rebuildsPerSwitch': rebuilds.values.fold(0, (total, count) => total + count), 'focusAndFrame': distribution(focusTimes), 'rebuildsPerFocus': focusRebuilds, 'mostRebuiltWidgets': Map.fromEntries(largest.take(12))})}',+ );+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ );}}diff --git a/desktop/test/swarm_history_test.dart b/desktop/test/swarm_history_test.dartindex 0adfae255..80f8924b3 100644--- a/desktop/test/swarm_history_test.dart+++ b/desktop/test/swarm_history_test.dart@@ -17,7 +17,46 @@ import 'swarm_screen_test.dart' show terminal;import 'swarm_state_test.dart' show createApp;import 'swarm_switcher_test.dart' show jumpField;+class _UnopenedAgent extends Agent {+ _UnopenedAgent()+ : super(id: 'unopened', name: 'Unopened', terminalAvailable: true);++ int projectReads = 0;++ @override+ AgentProject? get project {+ projectReads++;+ return const AgentProject(name: 'Unopened project', cwd: '/work/unopened');+ }+}+void main() {+ test('History does not format unopened agents during focus changes', () {+ final app = createApp();+ addTearDown(app.dispose);+ final unopened = _UnopenedAgent();+ app.machineStates['m']!.agents = [+ ...app.machineStates['m']!.agents,+ unopened,+ ];+ final history = SwarmNavigationHistory();+ app.addListener(() => history.record(app));+ final first = app.adoptSessionForTest(terminal('a0', []));+ final second = app.adoptSessionForTest(terminal('a1', []));+ history.record(app);+ history.menuDestinations(app);+ unopened.projectReads = 0;+ for (var i = 0; i < 12; i++) {+ final pane = i.isEven ? first : second;+ app.focusPane(pane.id);+ final rows = history.menuDestinations(app);+ expect(rows.first.agentId, pane.agentId);+ expect(rows.first.current, isTrue);+ expect(rows.any((row) => row.agentId == unopened.id), isFalse);+ }+ expect(unopened.projectReads, 0);+ });+test('swarm History counts distinct machines, including offline and closed work',() async {diff --git a/desktop/test/swarm_screen_test.dart b/desktop/test/swarm_screen_test.dartindex a1738fa24..128635d38 100644--- a/desktop/test/swarm_screen_test.dart+++ b/desktop/test/swarm_screen_test.dart@@ -23,6 +23,7 @@ Future<void> mount(WidgetTester tester,AppNotifier app, {SwarmProjectStore? projects,+ bool nativeTabs = false,}) async {tester.view.devicePixelRatio = 1;tester.view.physicalSize = const Size(1280, 800);@@ -33,7 +34,7 @@ Future<void> mount(theme: grid.buildAppTheme(brightness: Brightness.dark),home: SwarmScreen(notifier: app,- nativeTabs: false,+ nativeTabs: nativeTabs,projectStore: projects ?? SwarmProjectStore(),),),diff --git a/docs/harness-v2-handoff.md b/docs/harness-v2-handoff.mdindex 1f0c5a87c..1f064d711 100644--- a/docs/harness-v2-handoff.md+++ b/docs/harness-v2-handoff.md@@ -135,6 +135,13 @@ flows** for these two jobs.### Add agent+- Latest user approval: search and select one or several existing agents,+ preserve that selection across queries, show a count with easy removal, then+ add the selection to the target swarm. Keep machines and projects visible+ as swarm starters instead of hiding them behind Browse. New agent remains+ the distinct action for a fresh runtime. This continuation is in progress.+- The bottom-right + floats over the terminal canvas. Do not reserve a footer+ or shorten every pane to make room for it.- Build one shared Add interface for **New swarm, the floating +, and bothsplit directions**. It must support existing agents and a clearly visible**New agent** action. A split must not immediately force the creation form.diff --git a/docs/harness-v2-performance.md b/docs/harness-v2-performance.mdindex b82301eaf..7e6a1e9e3 100644--- a/docs/harness-v2-performance.md+++ b/docs/harness-v2-performance.md@@ -12,6 +12,50 @@ It prints `SWARM_BENCH` JSON records. Its filename deliberately does not end in## Current continuation benchmark (2026-09-14)+### History focus hot path++History now formats only agents with open views. Previously each focus change+formatted all discovered agents before discarding unopened ones. Add still+includes the full discovery inventory. A regression failed with 12 unnecessary+project reads before the fix and now observes zero, while preserving History's+current destination and ordering.++The expanded seven-case benchmark ran sequentially before and after this change+on the same shared M2 Max, in the headless debug runner. History has 2,000+discovered agents, 50 open locations in 12 swarms and 60 menu entries. The new+frame cases run production native-tab serialization with the AppKit method+channel receiver mocked; they do not measure AppKit or physical display latency.++| Operation | Before median / p95 / p99 | After median / p95 / p99 |+| --- | ---: | ---: |+| History snapshot after focus | 1.863 / 2.344 / 2.737 ms | 0.334 / 0.358 / 0.388 ms |+| Native bridge stub: switch/pump, 16 retained terminals | 8.262 / 9.341 / 11.797 ms | 6.113 / 6.977 / 8.298 ms |+| Native bridge stub: focus/pump, 16 retained terminals | 4.217 / 4.815 / 6.131 ms | 2.498 / 3.337 / 3.523 ms |+| Native bridge stub: switch/pump, 48 retained terminals | 8.214 / 8.940 / 9.038 ms | 6.467 / 7.482 / 7.629 ms |+| Native bridge stub: focus/pump, 48 retained terminals | 4.329 / 4.849 / 5.513 ms | 2.783 / 3.512 / 4.403 ms |+| Flutter tabs: switch/pump, 16 retained terminals | 13.698 / 20.591 / 24.499 ms | 13.151 / 22.382 / 24.439 ms |+| Flutter tabs: focus/pump, 16 retained terminals | 5.632 / 6.629 / 6.901 ms | 6.153 / 7.202 / 7.618 ms |+| Flutter tabs: switch/pump, 48 retained terminals | 10.913 / 12.465 / 13.061 ms | 10.596 / 12.296 / 18.970 ms |+| Flutter tabs: focus/pump, 48 retained terminals | 5.599 / 7.345 / 8.597 ms | 6.080 / 7.705 / 8.308 ms |++History's median CPU cost fell about 82%; unchanged snapshots stayed at 0.002 ms.+Rebuild counts did not change. The native-bridge fixtures discover 2,000 agents;+the older Flutter-tab fixtures discover 70, so do not compare these modes as+equivalent workloads. Flutter-tab tails remain variable and some worsened.+There are 100 History samples and 60 frame samples, with 1,000 retained lines per+terminal at 1280×800. JIT and shared-host load limit tail conclusions. Native+input-to-display and remote round-trip latency remain unmeasured.++Both seven-case benchmark runs passed, as did 39 affected behavior tests.+Analyzer: zero errors/warnings, 14 existing informational diagnostics. The+normal macOS arm64 Release target built successfully. Logs:+`/private/tmp/harness-history-benchmark-{before,after}.log`,+`/private/tmp/harness-history-focused-tests.log`,+`/private/tmp/harness-history-analyze.log`, and+`/private/tmp/harness-history-release-build.log`.++### Earlier integrated-main observation+After integrating updated main, the five explicit benchmark cases passed onproduction source at `0b3b343`. They ran sequentially (`--concurrency=1`) afterthe builds and correctness checks finished, on the same shared M2 Max workstation.diff --git a/docs/harness-v2-progress.md b/docs/harness-v2-progress.mdindex f620cad7b..71d8f8518 100644--- a/docs/harness-v2-progress.md+++ b/docs/harness-v2-progress.md@@ -6,6 +6,19 @@ Updated 2026-09-14 after integrating the continuation into main. This is a worki## Continue directly on main+- The user confirms the current menu and Navigate changes are visible. No+ further app restart or inspection is needed for that confirmation.+- History focus updates now skip formatting unopened agents. A failing-before+ regression passes; 39 affected tests, all seven expanded benchmark cases,+ analysis (zero errors/warnings) and the arm64 Release build pass. History+ snapshot CPU median fell 1.863 to 0.334 ms in the 2,000-agent fixture.+ Full paired timings, including variable/worse fallback-tab tails, are in+ [the performance record](harness-v2-performance.md). Native latency is still+ unmeasured.+- Latest approved work: restore visible machine/project swarm starters; let+ shared Add select multiple existing agents across searches with an explicit+ count/removal and Add N action; keep New agent visible and Navigate separate.+ The bottom-right + must overlay the panes without reserving a footer.- The user now wants all subsequent work, commits and pushes on **main**.This supersedes the earlier fresh-feature-branch workflow. Only consolidatethis user's own branches; other contributors' branches and PRs are excluded.