Multiplayer agent harness for work.
Sidebar: always show Sessions, collapse (#498)
Regan Belle96352619252
diff --git a/plugins/web-ui/src/contexts.ts b/plugins/web-ui/src/contexts.tsindex bc504bcdb..3f1169f0c 100644--- a/plugins/web-ui/src/contexts.ts+++ b/plugins/web-ui/src/contexts.ts@@ -30,7 +30,7 @@ import {import { UI_BASE } from "./deep-link";import { errMessage } from "../../chassis/src/errors";import { actionSnippet, closeFormMenus, fieldSelect, formatBytes, icon, initials, relTime, toggleFormMenu } from "./ui";-import { appState, renderSidebarTop, replacePanePreservingFocus, switchView, syncUrlFromState } from "./shell";+import { appState, replacePanePreservingFocus, switchView, syncUrlFromState } from "./shell";import { mainConversation } from "./conversations";import { groupDmTitle, openSession, refreshSessions, sessionsState, slackLogo, surfaceOf } from "./sessions";import { activityOf } from "./session-list";@@ -1443,7 +1443,5 @@ function startChatIn(c: CoreContext): void {}async function openFromContext(s: CoreSession): Promise<void> {- appState.currentView = "chats";- renderSidebarTop();await openSession(s);}diff --git a/plugins/web-ui/src/sessions.ts b/plugins/web-ui/src/sessions.tsindex 775c79c59..c6b44aac6 100644--- a/plugins/web-ui/src/sessions.ts+++ b/plugins/web-ui/src/sessions.ts@@ -73,7 +73,7 @@ import {} from "./contexts";import { groupDmLabel, groupDmText } from "./group-dm-label";import { transcriptModel } from "./model-options";-import { appState, closeSidebarOnNarrowView, renderSidebarTop, showMainEmpty } from "./shell";+import { appState, closeSidebarOnNarrowView, renderSidebarTop, showMainEmpty, syncUrlFromState } from "./shell";import { allConversations, mainConversation } from "./conversations";import type { Conversation } from "./conv-types";import {@@ -82,6 +82,7 @@ import {endSessionDrag,notifySessionsChanged,closeSessionSurfaces,+ drawCanvas,sessionInCanvas,splitInterceptsOpen,splitState,@@ -257,7 +258,7 @@ function visibleSessions(): CoreSession[] {}export function renderList(): void {- if (!appState.listEl || appState.currentView !== "chats") return;+ if (!appState.listEl) return;const visible = visibleSessions();const active = visible.filter((s) => !s.archived);const archived = visible.filter((s) => s.archived);@@ -1182,6 +1183,14 @@ export async function refreshSessions(}export async function openSession(s: CoreSession, entriesPrefetch?: Promise<TranscriptPage | null>): Promise<void> {+ if (appState.currentView !== "chats") {+ appState.currentView = "chats";+ appState.viewRenderSeq++;+ renderSidebarTop();+ renderList();+ if (splitState.active) drawCanvas();+ syncUrlFromState(s.id || null);+ }if (splitInterceptsOpen(s)) return;closeSidebarOnNarrowView();if (projectName(s.scopeId) && sessionsState.collapsedProjectScopes.delete(s.scopeId)) renderList();diff --git a/plugins/web-ui/src/shell.ts b/plugins/web-ui/src/shell.tsindex 480b69f97..4fa01dc1f 100644--- a/plugins/web-ui/src/shell.ts+++ b/plugins/web-ui/src/shell.ts@@ -14,6 +14,7 @@ import {Plus,RefreshCw,Rocket,+ ShieldCheck,type IconNode,} from "lucide";import "@mariozechner/mini-lit/dist/ThemeToggle.js";@@ -65,7 +66,7 @@ import { renderDeploys } from "./deploys";import { renderMemory, resetMemoryState } from "./memory";import { renderSkills } from "./skills";import { contextsState, ensureContexts, renderContexts, resetContextsState, resolveProjectScope } from "./contexts";-import { appState, isView, type AuthMode, type Me, type View } from "./shell-state";+import { appState, can, isView, type AuthMode, type Me, type View } from "./shell-state";import { trapDialogFocus } from "./dialog-focus";export { appState, can, type Me, type View } from "./shell-state";@@ -85,9 +86,11 @@ export const ADMIN_BASE = (() => {})();export const ADMIN_HOME_URL = `${ADMIN_BASE}/`;-export function syncUrlFromState(): void {+export function syncUrlFromState(sessionOverride?: string | null): void {const chatState = mainConversation().state;- const sessionId = splitState.active ? null : (chatState.sessionId ?? chatState.rememberedSessionId);+ const fromState =+ sessionOverride !== undefined ? sessionOverride : (chatState.sessionId ?? chatState.rememberedSessionId);+ const sessionId = splitState.active ? null : fromState;const next = deepLinkPath(UI_BASE, appState.currentView, sessionId, contextsState.selected);if (`${location.pathname}${location.search}` !== next) history.replaceState(null, "", next);}@@ -144,9 +147,9 @@ const NAV_WORKSPACE_KEY = "web-ui:nav-workspace";function loadNavOpen(key: string): boolean {try {- return localStorage.getItem(key) !== "0";+ return localStorage.getItem(key) === "1";} catch {- return true;+ return false;}}@@ -527,28 +530,31 @@ export function renderSidebarTop(): void {${navRow("files", ICON.files, "Files")} ${navRow("crons", ICON.crons, "Crons")}${navRow("keychain", ICON.keychain, "Keychain")} ${navRow("deploys", ICON.deploys, "Apps")}${navRow("memory", ICON.memory, "Memory")} ${navRow("skills", ICON.skills, "Skills")}+ ${+ can("admin")+ ? html`<a class="navrow" href=${ADMIN_HOME_URL} title="Admin">+ ${icon(ShieldCheck, 17)}<span>Admin</span>+ </a>`+ : nothing+ }`,)}</nav>- ${- appState.currentView === "chats"- ? html`- <div class="section-label recents-label">- <span>Sessions</span>- <button- class="web-only-toggle ${sessionsState.webOnly ? "on" : ""}"- type="button"- role="switch"- aria-checked=${sessionsState.webOnly ? "true" : "false"}- title=${sessionsState.webOnly ? "Showing web chats only" : "Hide non-web conversations"}- @click=${toggleWebOnly}- >- <span>Web only</span><span class="mini-switch"><span class="mini-knob"></span></span>- </button>- </div>- `- : ""- }+ ${html`+ <div class="section-label recents-label">+ <span>Sessions</span>+ <button+ class="web-only-toggle ${sessionsState.webOnly ? "on" : ""}"+ type="button"+ role="switch"+ aria-checked=${sessionsState.webOnly ? "true" : "false"}+ title=${sessionsState.webOnly ? "Showing web chats only" : "Hide non-web conversations"}+ @click=${toggleWebOnly}+ >+ <span>Web only</span><span class="mini-switch"><span class="mini-knob"></span></span>+ </button>+ </div>+ `}`,appState.topEl,);@@ -582,7 +588,6 @@ export function switchView(v: View): void {}renderSidebarTop();syncUrlFromState();- if (v !== "chats" && appState.listEl) render(nothing, appState.listEl);switch (v) {case "chats":if (splitState.active) drawCanvas();diff --git a/plugins/web-ui/test/open-session-view-switch.test.ts b/plugins/web-ui/test/open-session-view-switch.test.tsnew file mode 100644index 000000000..f60270689--- /dev/null+++ b/plugins/web-ui/test/open-session-view-switch.test.ts@@ -0,0 +1,33 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++const sessions = readFileSync(new URL("../src/sessions.ts", import.meta.url), "utf8");+const contexts = readFileSync(new URL("../src/contexts.ts", import.meta.url), "utf8");++const openSessionBody = sessions.match(/export async function openSession\([^]*?\n\}/)?.[0] ?? "";++test("openSession returns to the chats view before mounting (sidebar sessions are visible on every view)", () => {+ const guard = openSessionBody.match(/if \(appState\.currentView !== "chats"\) \{[^]*?\n {2}\}/)?.[0] ?? "";+ assert.ok(guard, "openSession must switch back to the chats view when invoked from another view");+ assert.match(guard, /appState\.currentView = "chats"/);+ assert.match(guard, /appState\.viewRenderSeq\+\+/, "must invalidate pending renders of the previous view");+ assert.match(guard, /renderSidebarTop\(\)/);+ assert.match(guard, /if \(splitState\.active\) drawCanvas\(\)/, "split canvas must be redrawn on return to chats");+ assert.match(+ guard,+ /syncUrlFromState\(s\.id \|\| null\)/,+ "URL must leave the old view — with the target session, not a stale remembered one — even when the split intercept returns early",+ );+ assert.ok(+ openSessionBody.indexOf(guard) < openSessionBody.indexOf("splitInterceptsOpen"),+ "view switch must happen before the split intercept so canvas opens intercept correctly",+ );+});++test("openFromContext delegates the view switch to openSession", () => {+ const body = contexts.match(/async function openFromContext\([^]*?\n\}/)?.[0] ?? "";+ assert.ok(body, "openFromContext exists");+ assert.match(body, /await openSession\(s\)/);+ assert.doesNotMatch(body, /appState\.currentView = "chats"/);+});