Multiplayer agent harness for work.
web-ui: close a session's open panes when it is archived (#406)
Regan Bellad733c4330ca
diff --git a/plugins/web-ui/src/sessions.ts b/plugins/web-ui/src/sessions.tsindex 738e164f0..f601f4ac4 100644--- a/plugins/web-ui/src/sessions.ts+++ b/plugins/web-ui/src/sessions.ts@@ -80,6 +80,7 @@ import {beginSessionDrag,endSessionDrag,notifySessionsChanged,+ closeSessionSurfaces,sessionInCanvas,splitInterceptsOpen,splitState,@@ -1068,6 +1069,7 @@ async function commitRename(s: CoreSession): Promise<void> {function setArchived(s: CoreSession, archived: boolean): void {sessionsState.openMenuId = null;+ if (archived && s.id) closeSessionSurfaces(s.id);void persistSessionPatch(s.id, { archived });}diff --git a/plugins/web-ui/src/split.ts b/plugins/web-ui/src/split.tsindex c791b88fa..5c31b4cbc 100644--- a/plugins/web-ui/src/split.ts+++ b/plugins/web-ui/src/split.ts@@ -362,6 +362,23 @@ export function sessionInCanvas(sessionId: string): boolean {return splitState.active && paneShowing(sessionId) !== null;}+/** Close any pane (and, outside the canvas, the main view) showing this session. */+export function closeSessionSurfaces(sessionId: string): boolean {+ if (!sessionId) return false;+ if (splitState.active && dockApi) {+ const showing = dockApi.panels.filter((p) => panelParams(p).sessionId === sessionId);+ if (showing.length) {+ closePanels(showing);+ return true;+ }+ return false;+ }+ const conv = mainConversation();+ if (conv.state.sessionId !== sessionId) return false;+ conv.newChat();+ return true;+}+export function splitInterceptsOpen(s: CoreSession): boolean {if (!splitState.active || appState.currentView !== "chats" || !s.id) return false;const target = splitState.focusedId ?? dockApi?.panels[0]?.id ?? "";diff --git a/plugins/web-ui/test/archive-closes-pane.test.ts b/plugins/web-ui/test/archive-closes-pane.test.tsnew file mode 100644index 000000000..0d30f8478--- /dev/null+++ b/plugins/web-ui/test/archive-closes-pane.test.ts@@ -0,0 +1,29 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++const read = (f: string): string => readFileSync(new URL(`../src/${f}`, import.meta.url), "utf8");+const split = read("split.ts");+const sessions = read("sessions.ts");++const fn = (src: string, name: string): string => {+ const body = src.match(new RegExp(`^(?:export )?(?:async )?function ${name}\\([\\s\\S]*?\\n\\}`, "m"))?.[0] ?? "";+ assert.ok(body, `${name} not found`);+ return body;+};++test("archiving a session closes any surface still showing it", () => {+ const close = fn(split, "closeSessionSurfaces");+ assert.match(close, /dockApi\.panels\.filter\(\(p\) => panelParams\(p\)\.sessionId === sessionId\)/);+ assert.match(close, /closePanels\(showing\)/, "open panes must be removed, and reconciled by closePanels");+ assert.match(close, /conv\.state\.sessionId !== sessionId\) return false;/, "leave other conversations alone");+ assert.match(close, /conv\.newChat\(\);/, "outside the canvas the main view drops the archived session");++ const archived = fn(sessions, "setArchived");+ assert.match(archived, /if \(archived && s\.id\) closeSessionSurfaces\(s\.id\);/);+ assert.ok(+ archived.indexOf("closeSessionSurfaces") < archived.indexOf("persistSessionPatch"),+ "close the surface before the patch round-trip so the UI reacts immediately",+ );+ assert.doesNotMatch(archived, /!archived.*closeSessionSurfaces/s, "unarchiving must not close anything");+});