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.

Merge batch 11-03 bx: #2741 (#2751)

0xken1527fe8ea009a7
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index cea87d45f..ed33d43d7 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -211,6 +211,7 @@ class SuperTabController extends ChangeNotifier {
buddiesGroupOpen = initial['buddiesGroupOpen'] as bool? ?? true;
modelsGroupOpen = initial['modelsGroupOpen'] as bool? ?? true;
offlineMachinesOpen = initial['offlineMachinesOpen'] as bool? ?? false;
+ sessionProjectId = initial['sessionProjectId'] as String? ?? '';
selectedId = initial['selectedId'] as String? ?? 'lead';
final drafts = initial['drafts'];
if (drafts is Map) {
@@ -1008,6 +1009,18 @@ class SuperTabController extends ChangeNotifier {
/// Whether the Machines group's "Offline · N" disclosure is open; it starts closed.
bool offlineMachinesOpen = false;
+ /// The project last chosen for a New session in the reader's Buddy chat on
+ /// this device, `''` for All projects (task #2347). The next New session
+ /// starts on it, while the reader can still read it.
+ String sessionProjectId = '';
+
+ void chooseSessionProject(String projectId) {
+ if (sessionProjectId == projectId) return;
+ sessionProjectId = projectId;
+ _saveSoon();
+ _changed();
+ }
+
void toggleProject(String id) {
if (!expandedProjects.remove(id)) {
expandedProjects.add(id);
@@ -2642,6 +2655,7 @@ class SuperTabController extends ChangeNotifier {
'buddiesGroupOpen': buddiesGroupOpen,
'modelsGroupOpen': modelsGroupOpen,
'offlineMachinesOpen': offlineMachinesOpen,
+ 'sessionProjectId': sessionProjectId,
'drafts': Map<String, String>.of(_drafts),
'terminals': Map<String, String>.of(_terminals),
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index 33a8f7b55..a3d99ed6c 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -141,10 +141,6 @@ class _SuperTabViewState extends State<SuperTabView>
/// The Buddy chats whose next message starts its own thread's session.
final _chatSessions = <String>{};
- /// The project a New session in the reader's one Buddy chat works in, by
- /// chat; none is a session that reads every project and sends to no PM
- /// (spec 2026-10-31-one-buddy-per-swarm).
- final _chatSessionProjects = <String, String>{};
String? _selected;
int _scrollRequest = 0;
bool _jumpingToEnd = false;
@@ -851,7 +847,7 @@ class _SuperTabViewState extends State<SuperTabView>
final result = await c.send(
replyTo: _replies[id]?.id,
newSession: newSession,
- sessionProjectId: newSession ? _chosenSessionProject(id) : null,
+ sessionProjectId: newSession ? _chosenSessionProject() : null,
// The reply goes with the message, which shows at the end at once.
onSending: () {
if (!mounted) return;
@@ -860,10 +856,7 @@ class _SuperTabViewState extends State<SuperTabView>
},
);
if (!mounted) return;
- if (newSession && result != null) {
- _chatSessions.remove(id);
- _chatSessionProjects.remove(id);
- }
+ if (newSession && result != null) _chatSessions.remove(id);
// Refused for New session, its text is back as the chat's draft: it shows
// in the box, ready to send without it, unless another chat is shown or
// something was typed meanwhile.
@@ -910,10 +903,13 @@ class _SuperTabViewState extends State<SuperTabView>
);
}
- /// The project chosen for chat [id]'s New session while the reader still
- /// reads it: one they lost is no longer chosen (security review 1 of #2437).
- String? _chosenSessionProject(String? id) {
- final chosen = _chatSessionProjects[id];
+ /// The project chosen for a New session, the last one on this device (task
+ /// #2347), while the reader still reads it: one they lost is no longer
+ /// chosen, and the session reads every project (security review 1 of #2437).
+ /// None is a session that reads every project and sends to no PM (spec
+ /// 2026-10-31-one-buddy-per-swarm).
+ String? _chosenSessionProject() {
+ final chosen = c.sessionProjectId;
return c.snapshot?.projects.any((p) => p.id == chosen) == true
? chosen
: null;
@@ -923,21 +919,16 @@ class _SuperTabViewState extends State<SuperTabView>
/// they read, sending to no PM, or one project, whose PM it alone sends to.
/// A quiet menu beside New session, shown while it is on.
Widget _chatSessionProject(bool writable) {
- final id = c.selectedId;
final projects = c.snapshot?.projects ?? const <SuperTabProject>[];
final chosen = projects
- .where((p) => p.id == _chatSessionProjects[id])
+ .where((p) => p.id == _chosenSessionProject())
.firstOrNull;
return PopupMenuButton<String>(
key: const ValueKey('super-chat-session-project'),
enabled: writable,
tooltip: 'Where this session works',
initialValue: chosen?.id ?? '',
- onSelected: (projectId) => setState(
- () => projectId.isEmpty
- ? _chatSessionProjects.remove(id)
- : _chatSessionProjects[id] = projectId,
- ),
+ onSelected: c.chooseSessionProject,
itemBuilder: (_) => [
PopupMenuItem(
key: const ValueKey('super-chat-session-any'),
diff --git a/desktop/test/super_tab_session_project_memory_test.dart b/desktop/test/super_tab_session_project_memory_test.dart
new file mode 100644
index 000000000..1d0d3f190
--- /dev/null
+++ b/desktop/test/super_tab_session_project_memory_test.dart
@@ -0,0 +1,174 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/super_tabs/controller.dart';
+import 'package:harness/super_tabs/view.dart';
+
+import 'support/buddy_fixture.dart';
+import 'support/super_tab_fixture.dart';
+
+/// Task #2347 (Scholes, 2026-11-03): the "Where this session works" menu beside
+/// New session starts on the project chosen there last time on this device,
+/// also after a restart; All projects is remembered too; a project the reader
+/// can no longer read is never used (security review 1 of #2437).
+void main() {
+ List<Map<String, dynamic>> sends(ConversationServer server) => [
+ for (final post in server.posts)
+ if ((post['command'] as Map)['type'] == 'message.send')
+ Map<String, dynamic>.from(post['command'] as Map),
+ ];
+
+ final menu = find.byKey(const ValueKey('super-chat-session-project'));
+ final buddyRow = find.byKey(const ValueKey('super-swarm-buddy'));
+
+ /// Shows the Swarm as `peer`, from [initial] (a saved view: a restart).
+ Future<SuperTabController> show(
+ WidgetTester tester,
+ ConversationServer server, {
+ Map<String, dynamic>? initial,
+ }) async {
+ await tester.binding.setSurfaceSize(const Size(1280, 800));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ final c = server.controller(account: 'peer', initial: initial);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.light),
+ home: Scaffold(
+ body: SuperTabView(
+ controller: c,
+ onInvite: () {},
+ onAddAgent: (_) {},
+ onOpenTerminal: (_) {},
+ machineName: (_) => 'Kens-MacBook',
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(buddyRow);
+ await tester.pumpAndSettle();
+ return c;
+ }
+
+ Future<void> close(WidgetTester tester, SuperTabController c) async {
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ }
+
+ Future<void> newSessionOn(WidgetTester tester) async {
+ await tester.tap(find.byKey(const ValueKey('super-chat-new-session')));
+ await tester.pumpAndSettle();
+ }
+
+ Future<void> choose(WidgetTester tester, String key) async {
+ await tester.tap(menu);
+ await tester.pumpAndSettle();
+ await tester.tap(find.byKey(ValueKey(key)).last);
+ await tester.pumpAndSettle();
+ }
+
+ Future<void> send(WidgetTester tester, String text) async {
+ await tester.enterText(
+ find.byKey(const ValueKey('super-message-composer')),
+ text,
+ );
+ await tester.pump();
+ await tester.tap(find.byTooltip('Send message'));
+ await tester.pumpAndSettle();
+ }
+
+ bool shows(String label) => find
+ .descendant(of: menu, matching: find.text(label))
+ .evaluate()
+ .isNotEmpty;
+
+ testWidgets('starts on the project chosen last time, for the next session', (
+ tester,
+ ) async {
+ final server = oneBuddySwarm();
+ giveSwarmBuddy(server);
+ final c = await show(tester, server);
+ await newSessionOn(tester);
+ expect(shows('All projects'), isTrue);
+ await choose(tester, 'super-chat-session-in-lead');
+ await send(tester, 'First session');
+ expect(sends(server).last['sessionProjectId'], 'lead');
+ // New session goes off with the send; turned on again, Pilot is chosen.
+ await newSessionOn(tester);
+ expect(shows('Pilot'), isTrue);
+ await send(tester, 'Second session');
+ expect(sends(server).last['newSession'], isTrue);
+ expect(sends(server).last['sessionProjectId'], 'lead');
+ await close(tester, c);
+ });
+
+ testWidgets('starts on the remembered project after a restart', (
+ tester,
+ ) async {
+ final server = oneBuddySwarm();
+ giveSwarmBuddy(server);
+ final first = await show(tester, server);
+ await newSessionOn(tester);
+ await choose(tester, 'super-chat-session-in-lead');
+ await close(tester, first);
+ final again = await show(tester, server, initial: server.saved);
+ await newSessionOn(tester);
+ expect(shows('Pilot'), isTrue);
+ await send(tester, 'After the restart');
+ expect(sends(server).last['sessionProjectId'], 'lead');
+ await close(tester, again);
+ });
+
+ testWidgets('remembers All projects over an earlier project', (tester) async {
+ final server = oneBuddySwarm();
+ giveSwarmBuddy(server);
+ final first = await show(tester, server);
+ await newSessionOn(tester);
+ await choose(tester, 'super-chat-session-in-lead');
+ await choose(tester, 'super-chat-session-any');
+ await close(tester, first);
+ final again = await show(tester, server, initial: server.saved);
+ await newSessionOn(tester);
+ expect(shows('All projects'), isTrue);
+ await send(tester, 'Anywhere');
+ expect(sends(server).last.containsKey('sessionProjectId'), isFalse);
+ await close(tester, again);
+ });
+
+ testWidgets('falls back to All projects for a project the reader lost', (
+ tester,
+ ) async {
+ final server = oneBuddySwarm();
+ giveSwarmBuddy(server);
+ final first = await show(tester, server);
+ await newSessionOn(tester);
+ await choose(tester, 'super-chat-session-in-lead');
+ await close(tester, first);
+ // The project is gone from what the reader sees: deleted, or access lost.
+ server.state['projects'] = [projectFixture('other', 'Other', 'lead')];
+ final again = await show(tester, server, initial: server.saved);
+ await newSessionOn(tester);
+ expect(shows('All projects'), isTrue);
+ expect(shows('Pilot'), isFalse);
+ await send(tester, 'Not into a lost project');
+ expect(sends(server).last['newSession'], isTrue);
+ expect(sends(server).last.containsKey('sessionProjectId'), isFalse);
+ await close(tester, again);
+ });
+
+ testWidgets('never applies a choice saved for another Swarm', (tester) async {
+ final server = oneBuddySwarm();
+ giveSwarmBuddy(server);
+ final first = await show(tester, server);
+ await newSessionOn(tester);
+ await choose(tester, 'super-chat-session-in-lead');
+ await close(tester, first);
+ final other = {...server.saved!, 'tabId': 'another-swarm'};
+ final again = await show(tester, server, initial: other);
+ await newSessionOn(tester);
+ expect(shows('All projects'), isTrue);
+ await close(tester, again);
+ });
+}
diff --git a/docs/plans/2026-11-03-session-project-memory-plan.md b/docs/plans/2026-11-03-session-project-memory-plan.md
new file mode 100644
index 000000000..afb1b739f
--- /dev/null
+++ b/docs/plans/2026-11-03-session-project-memory-plan.md
@@ -0,0 +1,58 @@
+# New session remembers its project Implementation Plan
+
+> **How this plan runs:** by this project's instructions (Engineer role): implemented task by task, test first (the
+> failing test committed and watched failing, then the code); the pull request's Review step is the one independent
+> review. Steps use checkbox (`- [ ]`) syntax.
+
+**Goal:** The "Where this session works" menu beside New session starts on the project the reader chose there last
+time on this device, also after a restart; All projects is remembered too; a project the reader can no longer read is
+never used.
+
+**Architecture:** The choice joins the controller's saved view (`SuperTabController._localState` and its `initial`
+restore), which is already per device, per account and per Swarm and survives a restart. The view reads it instead of
+its per-chat map, and the existing readable-project check (`_chosenSessionProject`, security review 1 of #2437) stays
+the only way it reaches a send.
+
+**Tech Stack:** Flutter (Desktop and web share `desktop/lib/super_tabs`), widget tests with the conversation fixture.
+
+**Spec:** task #2347's brief (Scholes, 2026-11-03).
+
+## Global Constraints
+
+- No visible change besides the menu's starting value. Harness design language.
+- Out: syncing across devices or accounts, the phone app.
+- PR body first line: "Requested by [email protected] through Harness."
+- Desktop tests use a memory store and a fake sign-in; never the real CLI sign-out.
+
+## Review Focus
+
+1. A remembered project the reader lost (deleted or access gone) is shown as All projects and never sent. Test in Task 1.
+2. A remembered project from another Swarm or account never applies: the saved view is per account and Swarm already
+ (`initial['tabId']`, `initial['accountId']`). Test in Task 1.
+3. Choosing All projects after a project replaces the remembered project. Test in Task 1.
+4. Sending a New session keeps the choice (it no longer resets to All projects after a send). Test in Task 1.
+
+---
+
+### Task 1: Remember the session project in the controller's saved view
+
+**Files:**
+- Modify: `desktop/lib/super_tabs/controller.dart` (field, restore, `_localState`, `chooseSessionProject`)
+- Modify: `desktop/lib/super_tabs/view.dart` (`_chatSessionProject`, `_chosenSessionProject`, send)
+- Test: `desktop/test/super_tab_session_project_memory_test.dart`
+
+**Interfaces:**
+- Produces: `String SuperTabController.sessionProjectId` (`''` = All projects, the default);
+ `void SuperTabController.chooseSessionProject(String projectId)` (saves soon, notifies); saved as
+ `'sessionProjectId'`.
+
+- [ ] **Step 1: Failing widget tests:** choose Pilot, send a New session, turn New session on again → the menu's
+ value is Pilot and the send carries `sessionProjectId: 'pilot'`; a new controller built from the first one's saved
+ view (restart) → Pilot preselected; choose All projects, restart → All projects; the remembered project removed
+ from the reader's projects → All projects shown and no `sessionProjectId` sent; a saved view of another Swarm → All
+ projects.
+- [ ] **Step 2:** `flutter test test/super_tab_session_project_memory_test.dart` → FAIL.
+- [ ] **Step 3:** Implement as the Interfaces say; drop `_chatSessionProjects`.
+- [ ] **Step 4:** PASS; run `super_tab_one_buddy_test.dart`, `super_tab_one_buddy_shots_test.dart`, `flutter analyze`
+ on the changed files, `python3 scripts/check-ui-style.py --only desktop/lib/super_tabs`.
+- [ ] **Step 5:** Commit test, then code; screenshot of the menu preselected after a restart for the PR.