Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(web): animate the sidebar collapse, label the rail's icons, open the account menu on it (#684)

Yaowei Zheng3a29e09eeb48
diff --git a/changelog/unreleased/2026-09-11-sidebar-rail-behaviour.md b/changelog/unreleased/2026-09-11-sidebar-rail-behaviour.md
new file mode 100644
index 00000000..3c6479f1
--- /dev/null
+++ b/changelog/unreleased/2026-09-11-sidebar-rail-behaviour.md
@@ -0,0 +1,32 @@
+# The collapsed sidebar animates, labels its icons, and opens the account menu in place
+
+- **Date:** 2026-09-11
+- **Type:** feature
+- **Scope:** `web`
+- **PR:** [#684](https://github.com/Prism-Shadow/penguin-harness/pull/684)
+
+[中文版](2026-09-11-sidebar-rail-behaviour.zh.md)
+
+Four changes to the desktop sidebar and the narrow rail it collapses into.
+
+## Details
+
+- Collapsing and expanding animate the sidebar's width over 200ms instead of snapping. Each
+ pane is laid out at its own final width inside the box and clipped by it, so the rail is at
+ its resting 48px from the first frame and the pinned sidebar is uncovered left to right.
+ Width is the only property the animation touches: a transform or a partial opacity on this
+ box would make it a stacking context and trap the menus the sidebar opens. Under
+ `prefers-reduced-motion` the width still snaps, as every other animation here does.
+- The rail's "last conversation" entry, and the Session the chat page auto-selects when
+ `/chat` is opened with none, now pick the conversation with the most recent activity rather
+ than the most recent creation time — the conversation the user was last in. The filter is
+ unchanged: archived rows and subagent Sessions are still never auto-opened.
+- The rail's icons carry a styled tooltip that opens on hover and on keyboard focus, after a
+ 400ms delay, and closes on blur, Escape, scroll or resize. It replaces the native `title`
+ on those entries, which appeared only after about a second, could not be styled, and never
+ appeared for a keyboard user. Entries on an update trail keep showing what is waiting.
+- The rail's avatar opens the account menu — System settings, the update row, sign out —
+ anchored on the rail, instead of expanding the sidebar first. Both avatars now render the
+ same menu component and the same-sized tile, so collapsing no longer makes the avatar jump
+ in size. Its tooltip reads "User settings"; the signed-in id stays in its accessible name,
+ which on a collapsed rail is the only place the id appears.
diff --git a/changelog/unreleased/2026-09-11-sidebar-rail-behaviour.zh.md b/changelog/unreleased/2026-09-11-sidebar-rail-behaviour.zh.md
new file mode 100644
index 00000000..0a2fc025
--- /dev/null
+++ b/changelog/unreleased/2026-09-11-sidebar-rail-behaviour.zh.md
@@ -0,0 +1,26 @@
+# 侧栏收起有了动画,图标有了提示,头像就地打开账户菜单
+
+- **Date:** 2026-09-11
+- **Type:** feature
+- **Scope:** `web`
+- **PR:** [#684](https://github.com/Prism-Shadow/penguin-harness/pull/684)
+
+[English](2026-09-11-sidebar-rail-behaviour.md)
+
+桌面侧栏及其收起后的窄栏共四项改动。
+
+## 细节
+
+- 收起与展开改为 200ms 的宽度动画,不再瞬间跳变。两种形态各自以自己的最终宽度布局、由外层裁剪,因此
+ 窄栏从第一帧起就停在 48px 的位置,固定侧栏则自左向右被揭开。动画只涉及宽度:在这个盒子上用 transform
+ 或小于 1 的不透明度都会生成层叠上下文,把侧栏弹出的菜单困在里面。开启 `prefers-reduced-motion` 时宽度
+ 照旧瞬间到位,与这里其他动画一致。
+- 窄栏的「最近一次对话」入口,以及打开 `/chat` 而未指定 Session 时聊天页自动选中的 Session,改为按
+ **最近活动时间**而不是创建时间选取——即用户上一次待在其中的那段对话。筛选规则不变:已归档与子智能体
+ Session 依然不会被自动打开。
+- 窄栏图标改用带样式的提示条:悬停或键盘聚焦后延时 400ms 出现,失焦、Escape、滚动或窗口尺寸变化时消失。
+ 它取代了这些入口上的原生 `title`——后者要等约一秒才出现、无法定制样式,键盘用户也永远看不到。位于更新
+ 提醒线索上的入口仍会带出在等什么。
+- 窄栏底部的头像改为就地打开账户菜单(系统设置、更新入口、登出),锚定在窄栏一侧,不再先展开侧栏。两处
+ 头像自此渲染同一个菜单组件,头像本身也统一为同一尺寸,收起侧栏时不再突然变大。它的提示条写「用户设置」;
+ 登录账号仍留在无障碍名称里——侧栏收起后,那是账号唯一出现的地方。
diff --git a/packages/web/e2e/layout.spec.mjs b/packages/web/e2e/layout.spec.mjs
index 50e14f75..9af3d179 100644
--- a/packages/web/e2e/layout.spec.mjs
+++ b/packages/web/e2e/layout.spec.mjs
@@ -27,10 +27,10 @@
* chrome used to stop fitting below ~412px;
* - the sidebar's "New chat" button has no background fill (same gray-scale style as nav items);
* - the collapsed rail shows, in product-specified order, last conversation / new chat /
- * Agents / Plugin library / Models / Cost Center / Evaluation Center with localized
- * (en + zh) hover
- * tooltips; "last conversation" targets the newest non-archived session and is disabled
- * while none exists; expanding from the rail restores the pinned sidebar;
+ * Agents / Plugin library / Models / Cost Center / Evaluation Center, each labeled by a
+ * localized (en + zh) styled tooltip on hover and by no native `title` (two tooltips would
+ * stack); "last conversation" targets the most recently active non-archived session and is
+ * disabled while none exists; expanding from the rail restores the pinned sidebar;
* - login page: a single brand penguin logo above the form (part of the form area; the
* background still only has the trace animation), the trace animation grows in after a
* delayed blank first paint, no two trace segments cross or touch (except where a fork shares
@@ -412,8 +412,9 @@ test("layout: collapsed rail — order, bilingual tooltips, last conversation",
await expect(entries).toHaveCount(7);
await expect(rail.getByRole("button", { name: "Last conversation" })).toBeDisabled();
- // --- Order and tooltips (en): aria-label defines the order, title carries the same copy.
- // Traces has no rail entry — the Trace panel lives in the chat toolbar's panel switcher. ---
+ // --- Order and tooltips (en): aria-label defines the order, and the styled tooltip shows the
+ // same copy on hover. Traces has no rail entry — the Trace panel lives in the chat toolbar's
+ // panel switcher. ---
const EN = [
"Last conversation",
"New chat",
@@ -426,9 +427,18 @@ test("layout: collapsed rail — order, bilingual tooltips, last conversation",
const attrs = (name) =>
entries.evaluateAll((els, n) => els.map((el) => el.getAttribute(n)), name);
expect(await attrs("aria-label"), "rail order (en)").toEqual(EN);
- expect(await attrs("title"), "rail tooltips (en)").toEqual(EN);
-
- // --- Three sessions via the API (distinct createdAt), newest archived: the rail must target the newest *non-archived* one ---
+ // No native title anywhere on the rail: it would open a second, slower tooltip under the
+ // styled one, which is the whole reason the styled one exists.
+ expect(await attrs("title"), "rail carries no native tooltips (en)").toEqual(EN.map(() => null));
+ const tooltip = page.getByTestId("tooltip");
+ await rail.getByRole("link", { name: "Models" }).hover();
+ await expect(tooltip, "rail tooltip (en)").toHaveText("Models");
+ await rail.getByRole("button", { name: "Last conversation" }).hover();
+ await expect(tooltip, "rail tooltip follows the pointer (en)").toHaveText("Last conversation");
+
+ // --- Three sessions via the API (distinct createdAt, so distinct lastActiveAt — a row starts
+ // out last-active at its creation), newest archived: the rail must target the most recently
+ // active *non-archived* one ---
const mkSession = async () => {
const res = await page.request.post(
`${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,
@@ -482,7 +492,9 @@ test("layout: collapsed rail — order, bilingual tooltips, last conversation",
await expect(entries).toHaveCount(7);
const ZH = ["最近一次对话", "新建对话", "智能体", "插件库", "模型库", "成本中心", "评估中心"];
expect(await attrs("aria-label"), "rail order (zh)").toEqual(ZH);
- expect(await attrs("title"), "rail tooltips (zh)").toEqual(ZH);
+ expect(await attrs("title"), "rail carries no native tooltips (zh)").toEqual(ZH.map(() => null));
+ await rail.getByRole("link", { name: "模型库" }).hover();
+ await expect(page.getByTestId("tooltip"), "rail tooltip (zh)").toHaveText("模型库");
// --- Expand: the rail's top button (localized) restores the pinned sidebar ---
await page.getByRole("button", { name: "展开侧栏" }).click();
diff --git a/packages/web/src/components/account/update-row.tsx b/packages/web/src/components/account/update-row.tsx
index 2de878d8..fd3fef75 100644
--- a/packages/web/src/components/account/update-row.tsx
+++ b/packages/web/src/components/account/update-row.tsx
@@ -14,9 +14,9 @@ export function UpdateRow({
menuItemClass,
onOpen,
}: {
- /** The menu's shared row class (owned by sidebar.tsx). */
+ /** The menu's shared row class (dropdown.tsx's `menuItemClass`). */
menuItemClass: string;
- /** Click: the Sidebar closes the menu and opens the update modal. */
+ /** Click: the account menu closes and the update modal opens. */
onOpen: () => void;
}) {
const { mode, flow, currentVersion } = useUpdateFlow();
diff --git a/packages/web/src/components/layout/app-layout.tsx b/packages/web/src/components/layout/app-layout.tsx
index 1ef6a623..6696aa39 100644
--- a/packages/web/src/components/layout/app-layout.tsx
+++ b/packages/web/src/components/layout/app-layout.tsx
@@ -4,7 +4,7 @@
* - <md: top thin bar (hamburger -> sidebar drawer + brand name) + main content.
* All chrome uses solid backgrounds and avoids stacking contexts (frosted-glass/transform would trap overlay z-index).
*/
-import { useEffect, useLayoutEffect, useMemo, useState } from "react";
+import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { NavLink, Outlet, useMatch, useNavigate } from "react-router";
import * as api from "../../api/endpoints";
import { S } from "../../lib/strings";
@@ -16,9 +16,11 @@ import { useSessions } from "../../state/sessions";
import { useCompletionNotifications } from "../../state/use-completion-notifications";
import { Drawer } from "../ui/drawer";
import { GlyphIcon } from "../ui/glyph-icon";
+import { Tooltip } from "../ui/tooltip";
import { UpdateDot } from "../ui/update-dot";
import { CloseIcon, NAV_ICONS } from "../ui/icons";
import { NEW_CHAT_ICON, Sidebar } from "./sidebar";
+import { UserMenu } from "./user-menu";
import { DRAFT_SESSION_ID } from "../../features/chat/chat-page";
import { parkActiveDraft } from "../../features/chat/draft-sessions";
import { ChangePasswordDialog } from "../account/change-password-dialog";
@@ -45,9 +47,13 @@ const railItemClass = (active: boolean) =>
/**
* Collapsed narrow rail: expand button on top; below it, in product-specified order, last
- * conversation / new chat / Agents / Skills / Models / Costs / Benchmark (every entry
- * carries a localized title + aria-label, so hover tooltips follow the UI language); user
- * avatar at the bottom. No Logo shown.
+ * conversation / new chat / Agents / Skills / Models / Costs / Benchmark; user avatar at the
+ * bottom, opening the same account menu the pinned sidebar's avatar does. No Logo shown.
+ *
+ * Every entry is an icon with no visible label, so each carries a localized aria-label and
+ * the same words in a styled Tooltip — never also a native `title`, which would put a second
+ * tooltip under the first. The entries' own names come from the same strings as the pinned
+ * nav's, so the rail follows the UI language with it.
*/
function CollapsedRail({ onExpand }: { onExpand: () => void }) {
const { user } = useAuth();
@@ -65,7 +71,7 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {
/** On some conversation (any non-draft /chat/:id): the "you are here" state of the last-conversation entry. */
const onConversation = activeSessionId !== null && activeSessionId !== DRAFT_SESSION_ID;
- /** Newest loaded conversation across the current Project (active/schedule only — archived and subagent rows are never auto-opened; the flat list is only ordered per Agent). */
+ /** The most recently active loaded conversation across the current Project (active/schedule only — archived and subagent rows are never auto-opened; the flat list is only ordered per Agent). */
const lastSession = useMemo(() => latestConversation(sessions), [sessions]);
/** Mirrors Sidebar.openSession: the current Agent follows the opened Session's Agent. */
@@ -94,17 +100,55 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {
{ to: "/benchmark", label: S.nav.benchmark, icon: NAV_ICONS.benchmark },
];
+ /**
+ * The rail's avatar hangs its menu off the rail's OUTER edge rather than over the rail:
+ * measured at click time as a zero-size point at the avatar's bottom and the aside's right,
+ * so a 48px column cannot hold (or clip) a 224px panel. A virtual anchor is a position, not
+ * an element, so `anchorOwner` is what tells the panel which scrolls moved it.
+ */
+ const avatarRef = useRef<HTMLButtonElement>(null);
+ const [menuAnchor, setMenuAnchor] = useState<{
+ top: number;
+ bottom: number;
+ left: number;
+ right: number;
+ } | null>(null);
+ const measureMenuAnchor = () => {
+ const button = avatarRef.current;
+ if (!button) return null;
+ const rect = button.getBoundingClientRect();
+ const left = (button.closest("aside")?.getBoundingClientRect().right ?? rect.right) + 4;
+ return { top: rect.bottom, bottom: rect.bottom, left, right: left };
+ };
+
+ /**
+ * The avatar's accessible name keeps the signed-in id: the menu behind it shows no id of its
+ * own, so while the sidebar is collapsed this is the only place one appears. The visible
+ * tooltip names what the control does instead — an initial in a circle is not a name a reader
+ * needs read back. Both carry what the update trail is waiting on, which from this rail is the
+ * only route left to the update row.
+ */
+ const avatarName =
+ badges.softwareNote !== null
+ ? `${user?.userId ?? ""} · ${badges.softwareNote}`
+ : (user?.userId ?? S.auth.admin);
+ const avatarTooltip =
+ badges.softwareNote !== null
+ ? `${S.nav.userSettings} · ${badges.softwareNote}`
+ : S.nav.userSettings;
+
return (
<div className="flex h-full flex-col items-center gap-1 py-2.5">
- <button
- type="button"
- title={S.nav.expandSidebar}
- aria-label={S.nav.expandSidebar}
- onClick={onExpand}
- className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-gray-500 transition-colors duration-150 hover:bg-gray-200/70 hover:text-gray-800 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200"
- >
- <GlyphIcon d="M9 6l6 6-6 6M20 4v16" size={18} />
- </button>
+ <Tooltip label={S.nav.expandSidebar} className="shrink-0">
+ <button
+ type="button"
+ aria-label={S.nav.expandSidebar}
+ onClick={onExpand}
+ className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-gray-500 transition-colors duration-150 hover:bg-gray-200/70 hover:text-gray-800 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200"
+ >
+ <GlyphIcon d="M9 6l6 6-6 6M20 4v16" size={18} />
+ </button>
+ </Tooltip>
{/* The entries scroll as one block, like the pinned sidebar's nav + session list: the rail
keeps only the expand control and the account avatar at fixed height, so a window too
short for the icons scrolls them here instead of pushing them out of the rail and
@@ -116,30 +160,32 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {
Lit on any non-draft conversation. Dimmed/disabled (tooltip kept) only once the list
has settled with no non-archived Session — while it is still loading the entry keeps
its normal look (no flash) and a click is a graceful no-op. */}
- <button
- type="button"
- title={S.nav.lastConversation}
- aria-label={S.nav.lastConversation}
- disabled={!lastSession && !loading}
- onClick={openLastSession}
- className={
- lastSession || loading
- ? railItemClass(onConversation)
- : "flex h-8 w-8 cursor-not-allowed items-center justify-center rounded-md text-gray-300 dark:text-gray-700"
- }
- >
- <GlyphIcon d={HISTORY_ICON} size={18} />
- </button>
+ <Tooltip label={S.nav.lastConversation}>
+ <button
+ type="button"
+ aria-label={S.nav.lastConversation}
+ disabled={!lastSession && !loading}
+ onClick={openLastSession}
+ className={
+ lastSession || loading
+ ? railItemClass(onConversation)
+ : "flex h-8 w-8 cursor-not-allowed items-center justify-center rounded-md text-gray-300 dark:text-gray-700"
+ }
+ >
+ <GlyphIcon d={HISTORY_ICON} size={18} />
+ </button>
+ </Tooltip>
{/* 2. New chat: shows the same gray active fill while on the draft page (pinned-sidebar convention). */}
- <button
- type="button"
- title={S.chat.newSessionMenu}
- aria-label={S.chat.newSessionMenu}
- onClick={newChat}
- className={railItemClass(activeSessionId === DRAFT_SESSION_ID)}
- >
- <GlyphIcon d={NEW_CHAT_ICON} size={18} />
- </button>
+ <Tooltip label={S.chat.newSessionMenu}>
+ <button
+ type="button"
+ aria-label={S.chat.newSessionMenu}
+ onClick={newChat}
+ className={railItemClass(activeSessionId === DRAFT_SESSION_ID)}
+ >
+ <GlyphIcon d={NEW_CHAT_ICON} size={18} />
+ </button>
+ </Tooltip>
{/* 3-8. Page entries */}
{pages.map((item) => {
/* Four entries sit on a badge trail — Agents (an outdated kernel), Skills, Models and
@@ -147,38 +193,61 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {
say what is waiting, and this rail's icons have no visible label, so they carry
both the entry's name and that sentence. */
const note = navNoteFor(badges, item.to);
+ const label = note !== null ? `${item.label} · ${note}` : item.label;
return (
- <NavLink
- key={item.to}
- to={item.to}
- title={note !== null ? `${item.label} · ${note}` : item.label}
- aria-label={note !== null ? `${item.label} · ${note}` : item.label}
- className={({ isActive }) => railItemClass(isActive)}
- >
- <GlyphIcon d={item.icon} size={18} />
- {note !== null && <UpdateDot />}
- </NavLink>
+ <Tooltip key={item.to} label={label}>
+ <NavLink
+ to={item.to}
+ aria-label={label}
+ className={({ isActive }) => railItemClass(isActive)}
+ >
+ <GlyphIcon d={item.icon} size={18} />
+ {note !== null && <UpdateDot />}
+ </NavLink>
+ </Tooltip>
);
})}
</nav>
- <button
- type="button"
- title={[user?.userId ?? "", S.nav.expandSidebar]
- .concat(badges.softwareNote !== null ? [badges.softwareNote] : [])
- .join(" · ")}
- aria-label={
- badges.softwareNote !== null
- ? `${user?.userId ?? ""} · ${badges.softwareNote}`
- : (user?.userId ?? S.auth.admin)
- }
- onClick={onExpand}
- className="relative mt-auto flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-gray-900 text-xs font-bold text-white dark:bg-gray-200 dark:text-gray-900"
- >
- {(user?.userId ?? "?").slice(0, 1).toUpperCase()}
- {/* Update reminder, mirroring the pinned sidebar's avatar: expanding the rail is the
- only way to the update row, so the title/aria-label above name what is waiting. */}
- {badges.software !== null && <UpdateDot />}
- </button>
+ {/* The account menu opens here, on the rail, instead of the avatar expanding the sidebar
+ first: appearance and System settings, the update row and signing out all stay one
+ click away while collapsed. Same component as the pinned sidebar's (user-menu.tsx). */}
+ <UserMenu
+ className="mt-auto shrink-0"
+ menuClass="w-56 origin-bottom-left"
+ portal={{ direction: "up", align: "left" }}
+ anchorRect={menuAnchor}
+ anchorOwner={() => avatarRef.current}
+ trigger={({ open, toggle }) => (
+ /* The tooltip names the same avatar the open menu hangs off, so it stands down while
+ the menu is up rather than covering it. */
+ <Tooltip label={avatarTooltip} suppressed={open}>
+ <button
+ ref={avatarRef}
+ type="button"
+ aria-label={avatarName}
+ aria-haspopup="menu"
+ aria-expanded={open}
+ onClick={() => {
+ setMenuAnchor(measureMenuAnchor());
+ toggle();
+ }}
+ className="flex h-8 w-8 shrink-0 items-center justify-center"
+ >
+ {/* The tile is the pinned sidebar's avatar, at its size, inside a rail-sized hit
+ box: the two states swap this element outright, so a tile that changed size
+ between them would pop on every collapse while the box beside it animates
+ smoothly. The button keeps the rail's 32px square, which is every other
+ entry's target. */}
+ <span className="relative flex h-7 w-7 items-center justify-center rounded-full bg-gray-900 text-xs font-bold text-white dark:bg-gray-200 dark:text-gray-900">
+ {(user?.userId ?? "?").slice(0, 1).toUpperCase()}
+ {/* Update reminder, mirroring the pinned sidebar's avatar: the update row sits in
+ the menu this opens, and the label above names what is waiting. */}
+ {badges.software !== null && <UpdateDot />}
+ </span>
+ </button>
+ </Tooltip>
+ )}
+ />
</div>
);
}
@@ -245,17 +314,30 @@ export function AppLayout() {
return (
<div className="flex h-full">
- {/* Desktop: single-column sidebar (collapsible to a narrow rail) */}
+ {/* Desktop: single-column sidebar (collapsible to a narrow rail).
+ Collapsing animates the WIDTH, which is the one animation here that transform cannot
+ carry: the sidebar is in flow, so the main content reflows beside it rather than
+ being slid over. Width is also the only property this box may animate at all —
+ transform, will-change and any opacity below 1 each make it a stacking context and
+ would trap the z-40 menus the sidebar opens inside it (see the file header).
+ `prefers-reduced-motion` is answered globally in styles.css, which drops the
+ transition and leaves the resting width correct.
+ The panes do NOT cross-fade. Each is rendered at its own final width inside the box
+ and clipped by it, so neither is ever laid out against a width it will not keep: the
+ rail sits at its final 48px from the first frame while the box closes around it, and
+ the pinned sidebar is uncovered left to right instead of reflowing on every frame. */}
<aside
- className={`hidden shrink-0 border-r border-gray-200 bg-gray-50 md:block dark:border-gray-800 dark:bg-gray-900 ${
+ className={`hidden shrink-0 overflow-hidden border-r border-gray-200 bg-gray-50 transition-[width] duration-200 ease-out md:block dark:border-gray-800 dark:bg-gray-900 ${
collapsed ? "w-12" : "w-64 lg:w-72"
}`}
>
- {collapsed ? (
- <CollapsedRail onExpand={toggleCollapsed} />
- ) : (
- <Sidebar onCollapse={toggleCollapsed} />
- )}
+ <div className={`h-full ${collapsed ? "w-12" : "w-64 lg:w-72"}`}>
+ {collapsed ? (
+ <CollapsedRail onExpand={toggleCollapsed} />
+ ) : (
+ <Sidebar onCollapse={toggleCollapsed} />
+ )}
+ </div>
</aside>
<div className="flex min-w-0 flex-1 flex-col">
diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsx
index 15d2db1b..857709d4 100644
--- a/packages/web/src/components/layout/sidebar.tsx
+++ b/packages/web/src/components/layout/sidebar.tsx
@@ -20,7 +20,7 @@
* trailing slot shows the compact last-active time at rest and swaps to archive + delete
* icon buttons on hover/focus; the full set (pin, rename, archive, delete) opens as a
* context menu on right-click, Shift+F10, or a press-and-hold on touch
- * -> bottom user config (theme / language / System settings / logout).
+ * -> bottom user row, which opens the shared account menu (user-menu.tsx).
* Desktop keeps it pinned as the left column; mobile puts the whole thing in a drawer.
* New chats always enter draft state (/chat/new, route state specifies the Agent and optionally
* the Workspace): Model / Workspace / approval mode are all chosen on the draft input card, so
@@ -106,7 +106,7 @@ import {
orderGroups,
saveGroupOrder,
} from "../../lib/group-order";
-import { Dropdown } from "../ui/dropdown";
+import { Dropdown, menuItemClass } from "../ui/dropdown";
import { useRowContextMenu } from "../ui/context-menu";
import {
HOVER_ROW_ACTIONS,
@@ -165,10 +165,8 @@ import {
} from "../../features/chat/draft-sessions";
import type { DraftSessionEntry } from "../../features/chat/draft-sessions";
import { CreateProjectDialog, ProjectSettingsDialog } from "./project-dialogs";
-import { UpdateRow } from "../account/update-row";
-import { openUpdateModal } from "../../lib/use-update-flow";
+import { UserMenu } from "./user-menu";
import { navNoteFor, useUpdateBadges } from "../../lib/use-update-badges";
-import { SettingsDialog } from "../../features/settings/settings-dialog";
import { pendingScheduleSessions } from "../../features/schedules/schedule-panel-state";
import { useAgentSchedules } from "../../features/schedules/schedule-store";
import { ICON_SIZE } from "../../lib/icon-scale";
@@ -246,9 +244,6 @@ function AddBadgeIcon({ base, size = 15 }: { base: string; size?: number }) {
);
}
-const menuItemClass =
- "block w-full px-3.5 py-2 text-left text-sm transition-colors duration-150 hover:bg-gray-100 dark:hover:bg-gray-800";
-
/** Section-header icon control (search / list settings / create): the grouping-toggle button look — active renders as a pressed fill. */
const headerControlClass = (active: boolean) =>
`flex h-6 w-6 shrink-0 items-center justify-center rounded-md transition-colors duration-150 ${
@@ -322,7 +317,7 @@ export function Sidebar({
onCollapse?: () => void;
}) {
const navigate = useNavigate();
- const { user, logout, desktopMode, sessionVia } = useAuth();
+ const { user, sessionVia } = useAuth();
const { locale } = useLocale();
const {
projects,
@@ -350,10 +345,8 @@ export function Sidebar({
const activeSessionId = chatMatch?.params.sessionId ?? null;
const [projectOpen, setProjectOpen] = useState(false);
- const [userOpen, setUserOpen] = useState(false);
const [createProjectOpen, setCreateProjectOpen] = useState(false);
const [projectSettingsOpen, setProjectSettingsOpen] = useState(false);
- const [settingsOpen, setSettingsOpen] = useState(false);
/** The badges over the update and to-do trails (use-update-badges.ts); the avatar's dot follows the update flow's offer / restart states. */
const badges = useUpdateBadges();
const currentProjectId = currentProject?.projectId ?? null;
@@ -2172,16 +2165,17 @@ export function Sidebar({
)}
</div>
- {/* Bottom user config */}
+ {/* Bottom user row: the trigger for the account menu both this sidebar and the
+ collapsed rail open (user-menu.tsx). */}
<div className="shrink-0 border-t border-gray-200 p-2 dark:border-gray-800">
- <Dropdown
- open={userOpen}
- setOpen={setUserOpen}
+ <UserMenu
menuClass="bottom-full left-0 right-0 mb-1 origin-bottom"
- button={
+ trigger={({ open, toggle }) => (
<button
type="button"
- onClick={() => setUserOpen(!userOpen)}
+ onClick={toggle}
+ aria-haspopup="menu"
+ aria-expanded={open}
{...(badges.softwareNote !== null
? {
// The dot alone is mysterious: name what is waiting on the trigger (hover
@@ -2203,57 +2197,10 @@ export function Sidebar({
<span className="text-xs text-gray-400 dark:text-gray-500">{S.auth.admin}</span>
)}
</button>
- }
- >
- <div className="py-1">
- {/* System settings dialog: everyone gets the row — the dialog always has the
- personal pages, and the server-global ones inside it stay gated by the
- section registry rather than by this row. The preference rows that used to
- stack here live on its pages now. */}
- <button
- type="button"
- className={menuItemClass}
- onClick={() => {
- setUserOpen(false);
- setSettingsOpen(true);
- }}
- >
- {S.settings.systemSettings}
- </button>
- {/* Update entry, directly under the settings entry rather than on a page inside
- it: one row for both backends (the server release here, the shell's own
- updater in the desktop window), naming where the update flow stands and
- opening the update modal — where the flow is explained and acted on. The
- modal is mounted by the app layout, so it outlives this menu. Hidden where
- this session can update nothing (a browser signed into a desktop-mode
- server, see updateModeFor). */}
- <UpdateRow
- menuItemClass={menuItemClass}
- onOpen={() => {
- setUserOpen(false);
- openUpdateModal();
- }}
- />
- {/* Hidden in desktop mode: the window IS the session — logging out would
- strand the user on a login page whose password was never shown. */}
- {!desktopMode && (
- <button
- type="button"
- className="block w-full px-3.5 py-2 text-left text-sm text-red-600 transition-colors duration-150 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40"
- onClick={() => {
- setUserOpen(false);
- void logout().then(() => navigate("/login"));
- }}
- >
- {S.auth.logout}
- </button>
- )}
- </div>
- </Dropdown>
+ )}
+ />
</div>
- <SettingsDialog open={settingsOpen} onClose={() => setSettingsOpen(false)} />
-
<CreateProjectDialog
open={createProjectOpen}
onClose={() => setCreateProjectOpen(false)}
diff --git a/packages/web/src/components/layout/user-menu.tsx b/packages/web/src/components/layout/user-menu.tsx
new file mode 100644
index 00000000..ae1745a3
--- /dev/null
+++ b/packages/web/src/components/layout/user-menu.tsx
@@ -0,0 +1,110 @@
+/**
+ * The account menu, shared by both avatars that open one: the pinned sidebar's user row and
+ * the collapsed rail's avatar. One component rather than a copy per anchor — the rows
+ * (System settings, the update entry, sign out) and the dialog behind the first of them must
+ * stay the same menu from either side, and a second copy is how two menus drift apart.
+ *
+ * Only the trigger differs, so the trigger is the caller's: it is handed the menu's own open
+ * state, which is what keeps "what opening means" here rather than in two places.
+ *
+ * The settings dialog is mounted OUTSIDE the panel: the panel's children unmount the moment
+ * the menu closes, and the settings row closes the menu as it opens the dialog.
+ */
+import { useState } from "react";
+import type { ReactNode } from "react";
+import { useNavigate } from "react-router";
+import { S } from "../../lib/strings";
+import { useAuth } from "../../state/auth";
+import { Dropdown, menuItemClass } from "../ui/dropdown";
+import type { DropdownPortal } from "../ui/dropdown";
+import { UpdateRow } from "../account/update-row";
+import { openUpdateModal } from "../../lib/use-update-flow";
+import { SettingsDialog } from "../../features/settings/settings-dialog";
+
+export function UserMenu({
+ trigger,
+ menuClass,
+ portal,
+ anchorRect,
+ anchorOwner,
+ className,
+}: {
+ /** The anchor's own look, wired to this menu's state: the sidebar's full-width row, the rail's avatar. */
+ trigger: (state: { open: boolean; toggle: () => void }) => ReactNode;
+ /** Panel size and, for an in-flow panel, its docking direction (see Dropdown). */
+ menuClass?: string;
+ /** Escape the anchor's clipping box by rendering the panel through a body portal. */
+ portal?: DropdownPortal;
+ /** Place the panel against this viewport box instead of the anchor's own — the rail hangs its menu off the rail's outer edge rather than over the rail. */
+ anchorRect?: { top: number; bottom: number; left: number; right: number } | null;
+ /** The element `anchorRect` was measured from, so only a scroll that moved it dismisses the panel. */
+ anchorOwner?: () => HTMLElement | null;
+ /** Extra classes for the anchor container (e.g. `mt-auto` in a flex column). */
+ className?: string;
+}) {
+ const navigate = useNavigate();
+ const { logout, desktopMode } = useAuth();
+ const [open, setOpen] = useState(false);
+ const [settingsOpen, setSettingsOpen] = useState(false);
+
+ return (
+ <>
+ <Dropdown
+ open={open}
+ setOpen={setOpen}
+ button={trigger({ open, toggle: () => setOpen(!open) })}
+ {...(className !== undefined ? { className } : {})}
+ {...(menuClass !== undefined ? { menuClass } : {})}
+ {...(portal !== undefined ? { portal } : {})}
+ {...(anchorRect !== undefined ? { anchorRect } : {})}
+ {...(anchorOwner !== undefined ? { anchorOwner } : {})}
+ >
+ <div className="py-1">
+ {/* System settings dialog: everyone gets the row — the dialog always has the
+ personal pages, and the server-global ones inside it stay gated by the
+ section registry rather than by this row. The preference rows that used to
+ stack here live on its pages now. */}
+ <button
+ type="button"
+ className={menuItemClass}
+ onClick={() => {
+ setOpen(false);
+ setSettingsOpen(true);
+ }}
+ >
+ {S.settings.systemSettings}
+ </button>
+ {/* Update entry, directly under the settings entry rather than on a page inside
+ it: one row for both backends (the server release here, the shell's own
+ updater in the desktop window), naming where the update flow stands and
+ opening the update modal — where the flow is explained and acted on. The
+ modal is mounted by the app layout, so it outlives this menu. Hidden where
+ this session can update nothing (a browser signed into a desktop-mode
+ server, see updateModeFor). */}
+ <UpdateRow
+ menuItemClass={menuItemClass}
+ onOpen={() => {
+ setOpen(false);
+ openUpdateModal();
+ }}
+ />
+ {/* Hidden in desktop mode: the window IS the session — logging out would
+ strand the user on a login page whose password was never shown. */}
+ {!desktopMode && (
+ <button
+ type="button"
+ className="block w-full px-3.5 py-2 text-left text-sm text-red-600 transition-colors duration-150 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40"
+ onClick={() => {
+ setOpen(false);
+ void logout().then(() => navigate("/login"));
+ }}
+ >
+ {S.auth.logout}
+ </button>
+ )}
+ </div>
+ </Dropdown>
+ <SettingsDialog open={settingsOpen} onClose={() => setSettingsOpen(false)} />
+ </>
+ );
+}
diff --git a/packages/web/src/components/ui/dropdown.tsx b/packages/web/src/components/ui/dropdown.tsx
index 327a5003..5aea5930 100644
--- a/packages/web/src/components/ui/dropdown.tsx
+++ b/packages/web/src/components/ui/dropdown.tsx
@@ -43,6 +43,10 @@ import { scrollMovesAnchor } from "../../lib/context-menu";
const PANEL_GAP = 4;
const VIEWPORT_MARGIN = 8;
+/** The panel's plain row: full-width, left-aligned, hover-filled. Shared so menus opened from different anchors cannot drift apart on density. */
+export const menuItemClass =
+ "block w-full px-3.5 py-2 text-left text-sm transition-colors duration-150 hover:bg-gray-100 dark:hover:bg-gray-800";
+
/** Portal docking: which way the panel opens and which of its edges lines up with the trigger. */
export interface DropdownPortal {
direction: "up" | "down";
diff --git a/packages/web/src/components/ui/tooltip.tsx b/packages/web/src/components/ui/tooltip.tsx
new file mode 100644
index 00000000..b5809ce7
--- /dev/null
+++ b/packages/web/src/components/ui/tooltip.tsx
@@ -0,0 +1,141 @@
+/**
+ * Hover/focus tooltip for a control whose visible form is an icon alone.
+ *
+ * What it replaces is the native `title` attribute: that one waits about a second before it
+ * appears, cannot be styled, and never shows on keyboard focus — so an icon rail labeled
+ * only by `title` reads as unlabeled. A trigger must carry one or the other, never both, or
+ * two tooltips appear over each other.
+ *
+ * Portaled to document.body at fixed viewport coordinates, like every other overlay here
+ * (see use-portal-panel.ts): an in-place absolute panel is a descendant of its trigger, so a
+ * scrolling or clipping ancestor — the collapsed rail is both — cuts it off. It sits on the
+ * portaled-panel layer (z-[60]) and takes no pointer events, so it can never swallow a click
+ * meant for what it covers.
+ *
+ * Deliberately NOT `role="tooltip"` + `aria-describedby`: its callers label their triggers
+ * with the same words it shows, and a description repeating the accessible name makes a
+ * screen reader say the entry twice. The panel is decorative here and hidden from the
+ * accessibility tree; the trigger's own `aria-label` stays the one name.
+ *
+ * Dismissal mirrors the portal panel's, minus the parts a hover-driven panel has no use for
+ * (no outside click, no Esc layer): it closes on pointer leave, on blur, on Escape, on any
+ * scroll and on a resize — the last three because the position is measured once and is stale
+ * the moment the trigger moves.
+ */
+import { useCallback, useEffect, useRef, useState } from "react";
+import { createPortal } from "react-dom";
+import type { ReactNode } from "react";
+
+/**
+ * Open delay. Long enough that a pointer crossing a column of icons on its way elsewhere
+ * leaves no trail of popping panels, short enough to answer a pointer that stopped to ask.
+ */
+const OPEN_DELAY_MS = 400;
+
+/** Gap between the trigger's edge and the panel, and the panel's minimum distance from the viewport edge (px). */
+const PANEL_GAP = 8;
+const VIEWPORT_MARGIN = 8;
+
+export function Tooltip({
+ label,
+ suppressed,
+ className,
+ children,
+}: {
+ /** The words the panel shows — the trigger's own name, so the two cannot disagree. */
+ label: string;
+ /**
+ * Hold the panel closed and refuse to open it. For a trigger that owns something else on
+ * screen while it is active: the rail avatar's open user menu hangs off the same corner,
+ * and a tooltip naming that avatar would sit on top of the menu it just opened.
+ */
+ suppressed?: boolean;
+ /** Extra classes for the wrapper that measures the trigger (e.g. `mt-auto` in a flex column). */
+ className?: string;
+ children: ReactNode;
+}) {
+ const anchorRef = useRef<HTMLSpanElement>(null);
+ const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ /** Non-null only while the panel is up; the measured viewport point its left edge and vertical centre sit at. */
+ const [position, setPosition] = useState<{ top: number; left: number } | null>(null);
+
+ const hide = useCallback(() => {
+ if (timerRef.current !== null) {
+ clearTimeout(timerRef.current);
+ timerRef.current = null;
+ }
+ setPosition(null);
+ }, []);
+
+ const show = () => {
+ if (suppressed === true || timerRef.current !== null) return;
+ timerRef.current = setTimeout(() => {
+ timerRef.current = null;
+ const rect = anchorRef.current?.getBoundingClientRect();
+ if (!rect) return;
+ // Placed to the right of the trigger — the one geometry the callers need, an icon rail
+ // against the left edge of the window. Vertically centred on the trigger and clamped so
+ // a rail entry scrolled to the very top or bottom still gets a panel on screen.
+ setPosition({
+ top: Math.min(
+ Math.max(rect.top + rect.height / 2, VIEWPORT_MARGIN),
+ window.innerHeight - VIEWPORT_MARGIN,
+ ),
+ left: rect.right + PANEL_GAP,
+ });
+ }, OPEN_DELAY_MS);
+ };
+
+ useEffect(() => {
+ if (suppressed === true) hide();
+ }, [suppressed, hide]);
+
+ // Unmounting with a pending timer would fire a state update on a dead component.
+ useEffect(() => hide, [hide]);
+
+ useEffect(() => {
+ if (position === null) return;
+ // Escape is heard in capture so a focused trigger inside a dialog still dismisses its
+ // tooltip, and is deliberately NOT stopped: this panel is not a dismissible layer, and
+ // swallowing the key would keep the dialog behind it open on the same press.
+ const onKey = (e: KeyboardEvent) => {
+ if (e.key === "Escape") hide();
+ };
+ // Capture, because scroll does not bubble. Any scroll dismisses, with none of the
+ // portal panel's "did it move the trigger" refinement: this panel is already gone the
+ // moment the pointer leaves, so the cost of closing one too eagerly is nothing.
+ window.addEventListener("keydown", onKey, true);
+ window.addEventListener("scroll", hide, true);
+ window.addEventListener("resize", hide);
+ return () => {
+ window.removeEventListener("keydown", onKey, true);
+ window.removeEventListener("scroll", hide, true);
+ window.removeEventListener("resize", hide);
+ };
+ }, [position, hide]);
+
+ return (
+ <span
+ ref={anchorRef}
+ className={`flex ${className ?? ""}`}
+ onPointerEnter={show}
+ onPointerLeave={hide}
+ onFocus={show}
+ onBlur={hide}
+ >
+ {children}
+ {position !== null &&
+ createPortal(
+ <div
+ data-testid="tooltip"
+ aria-hidden
+ style={{ position: "fixed", top: position.top, left: position.left }}
+ className="anim-fade pointer-events-none z-[60] w-max max-w-64 -translate-y-1/2 rounded-md border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700 shadow-lg dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200"
+ >
+ {label}
+ </div>,
+ document.body,
+ )}
+ </span>
+ );
+}
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index dcfefdfd..0ee037e6 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -721,10 +721,11 @@ export function ChatPage() {
isSessionDeleted,
]);
- // Auto-select the most recent conversation when the route doesn't select one (newest loaded
- // active/schedule Session — archived rows are hidden by choice and subagent Sessions belong
- // to their parent, so neither is auto-opened); if there is none, fall back to draft state
- // (instead of auto-creating one).
+ // Auto-select the last conversation when the route doesn't select one: the most recently
+ // ACTIVE loaded active/schedule Session, the same rule the collapsed rail's entry follows —
+ // archived rows are hidden by choice and subagent Sessions belong to their parent, so
+ // neither is auto-opened. If there is none, fall back to draft state (instead of
+ // auto-creating one).
useEffect(() => {
if (sessionsLoading || draft) return;
if (selected !== null) return;
diff --git a/packages/web/src/lib/session-grouping.ts b/packages/web/src/lib/session-grouping.ts
index 20f1b15d..901d5cc3 100644
--- a/packages/web/src/lib/session-grouping.ts
+++ b/packages/web/src/lib/session-grouping.ts
@@ -229,12 +229,13 @@ export function aggregateWorkspaceCounts(
/**
* The Session the UI opens as "the last conversation" (the chat home's auto-select and
- * the collapsed rail's entry): the newest loaded row that is a conversation of the
- * user's own. Archived rows are hidden by choice and a subagent Session is a child of
- * some other conversation, so neither is ever auto-opened; schedule-created runs are
- * the user's conversations and qualify. Newest by createdAt (uniform ISO-8601 UTC, so
- * string comparison is chronological), ties broken by sessionId — the list's ordering
- * convention. Input order doesn't matter.
+ * the collapsed rail's entry): the loaded row the user was last IN — not the one created
+ * last, which on a revisited conversation is a different row. Archived rows are hidden by
+ * choice and a subagent Session is a child of some other conversation, so neither is ever
+ * auto-opened; schedule-created runs are the user's conversations and qualify. Newest by
+ * lastActiveAt (stamped from `Date#toISOString`, so uniform ISO-8601 UTC like createdAt and
+ * comparable as a string), ties broken by sessionId — the list's ordering convention. Input
+ * order doesn't matter.
*/
export function latestConversation(sessions: readonly SessionInfo[]): SessionInfo | null {
let best: SessionInfo | null = null;
@@ -243,8 +244,8 @@ export function latestConversation(sessions: readonly SessionInfo[]): SessionInf
if (category !== "active" && category !== "schedule") continue;
if (
!best ||
- s.createdAt > best.createdAt ||
- (s.createdAt === best.createdAt && s.sessionId > best.sessionId)
+ s.lastActiveAt > best.lastActiveAt ||
+ (s.lastActiveAt === best.lastActiveAt && s.sessionId > best.sessionId)
) {
best = s;
}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index be237ca9..0821b370 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -20,8 +20,10 @@ export const en: Strings = {
usage: "Cost Center",
traces: "Trajectories",
benchmark: "Evaluation Center",
- // Collapsed-rail tooltip (product-specified wording; new chat reuses chat.newSessionMenu, the other pages reuse the page names above).
+ // Collapsed-rail tooltips (product-specified wording; new chat reuses chat.newSessionMenu, the other pages reuse the page names above).
lastConversation: "Last conversation",
+ // The rail avatar's tooltip says what the control does; who is signed in stays in its accessible name.
+ userSettings: "User settings",
collapseSidebar: "Collapse sidebar",
expandSidebar: "Expand sidebar",
collapseGroup: "Collapse",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index a3446aae..1be3f195 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -24,8 +24,10 @@ export const zh = {
usage: "成本中心",
traces: "轨迹观测",
benchmark: "评估中心",
- // Collapsed-rail tooltip (product-specified wording; new chat reuses chat.newSessionMenu, the other pages reuse the page names above).
+ // Collapsed-rail tooltips (product-specified wording; new chat reuses chat.newSessionMenu, the other pages reuse the page names above).
lastConversation: "最近一次对话",
+ // The rail avatar's tooltip says what the control does; who is signed in stays in its accessible name.
+ userSettings: "用户设置",
collapseSidebar: "收起侧栏",
expandSidebar: "展开侧栏",
collapseGroup: "折叠",
diff --git a/packages/web/test/account-menu.test.ts b/packages/web/test/account-menu.test.ts
index 7d006a0d..5b1c2e5c 100644
--- a/packages/web/test/account-menu.test.ts
+++ b/packages/web/test/account-menu.test.ts
@@ -1,5 +1,5 @@
/**
- * account-menu.ts unit tests: which sessions the sidebar user menu offers a
+ * account-menu.ts unit tests: which sessions the account menu offers a
* change-password entry to.
*
* The rule is pinned by value in all four combinations rather than by shape, because the
@@ -75,9 +75,11 @@ describe("the settings section registry", () => {
});
});
-describe("the sidebar user menu", () => {
+describe("the account menu", () => {
+ // One menu, two anchors: the pinned sidebar's user row and the collapsed rail's avatar
+ // both render this component, so the rows below are asserted once, where they live.
const source = readFileSync(
- resolve(dirname(fileURLToPath(import.meta.url)), "../src/components/layout/sidebar.tsx"),
+ resolve(dirname(fileURLToPath(import.meta.url)), "../src/components/layout/user-menu.tsx"),
"utf8",
);
diff --git a/packages/web/test/session-grouping.test.ts b/packages/web/test/session-grouping.test.ts
index bfedfff0..89e068f1 100644
--- a/packages/web/test/session-grouping.test.ts
+++ b/packages/web/test/session-grouping.test.ts
@@ -219,20 +219,27 @@ describe("partitionSessions (per-group user / subagent / scheduled / archived sp
});
describe("latestConversation (the auto-opened 'last conversation')", () => {
- it("picks the newest active/schedule row regardless of input order; archived and subagent rows never win", () => {
- const oldActive = session("/srv/a", "2026-07-01T10:00:00.000Z");
- const newActive = session("/srv/a", "2026-07-03T10:00:00.000Z");
- // Newer than every conversation, but never auto-opened:
- const newerSub = session("/srv/a", "2026-07-08T10:00:00.000Z", { source: "subagent" });
- const newerGone = session("/srv/a", "2026-07-09T10:00:00.000Z", { archived: true });
- expect(latestConversation([newerSub, oldActive, newerGone, newActive])).toBe(newActive);
-
- // A schedule-created run is the user's conversation: the newest one qualifies.
- const newerSched = session("/srv/a", "2026-07-05T10:00:00.000Z", { source: "schedule" });
- expect(latestConversation([newActive, newerSched, newerSub])).toBe(newerSched);
+ it("picks the most recently active active/schedule row regardless of input order; archived and subagent rows never win", () => {
+ // Created first but returned to since: this is the conversation the user was last in,
+ // and the one created last is not.
+ const revisited = session("/srv/a", "2026-07-01T10:00:00.000Z", {
+ lastActiveAt: "2026-07-06T10:00:00.000Z",
+ });
+ const newerUntouched = session("/srv/a", "2026-07-03T10:00:00.000Z");
+ // Active more recently than every conversation, but never auto-opened:
+ const subAfter = session("/srv/a", "2026-07-08T10:00:00.000Z", { source: "subagent" });
+ const goneAfter = session("/srv/a", "2026-07-09T10:00:00.000Z", { archived: true });
+ expect(latestConversation([subAfter, newerUntouched, goneAfter, revisited])).toBe(revisited);
+
+ // A schedule-created run is the user's conversation: the most recently active one qualifies.
+ const schedAfter = session("/srv/a", "2026-07-05T10:00:00.000Z", {
+ lastActiveAt: "2026-07-07T10:00:00.000Z",
+ source: "schedule",
+ });
+ expect(latestConversation([revisited, schedAfter, subAfter])).toBe(schedAfter);
});
- it("ties on createdAt break by sessionId, and no qualifying row yields null", () => {
+ it("ties on lastActiveAt break by sessionId, and no qualifying row yields null", () => {
const at = "2026-07-02T10:00:00.000Z";
const a = session("/srv/a", at, { sessionId: "session-a" });
const b = session("/srv/a", at, { sessionId: "session-b" });