A local-first multi-agent app development platform, built on PenguinHarness
fix(web): a sidebar folder reveals ten rows at a time and folds back (#712)
Yaowei Zhengaccd47d8a6aa
diff --git a/changelog/unreleased/2026-09-12-sidebar-folder-reveal.md b/changelog/unreleased/2026-09-12-sidebar-folder-reveal.mdnew file mode 100644index 00000000..c6ed0b43--- /dev/null+++ b/changelog/unreleased/2026-09-12-sidebar-folder-reveal.md@@ -0,0 +1,26 @@+# A sidebar folder reveals ten conversations at a time and folds back++- **Date:** 2026-09-12+- **Type:** fix+- **Scope:** `web`, `docs`+- **PR:** [#712](https://github.com/Prism-Shadow/penguin-harness/pull/712)++[中文版](2026-09-12-sidebar-folder-reveal.zh.md)++The conversation list's folders — Subagents, Scheduled, Archived — showed every row a fetch+returned and had no way back: expanding Archived with 28 conversations left revealed 13 of them in+one click, and once its share was loaded nothing folded it up again. A folder now follows the same+display rule the active list above it already did: ten rows at a time, "Show N more chats" for the+next ten, and a "Show less" row beside it that folds back to those first ten.++## Details++- Each folder carries its own display cap, stepped a page at a time by its reveal row, and reset —+ like the active list's — on a grouping-mode switch and on a Project change.+- The reveal row reveals rows already in memory first and asks the server for another page only+ when they run short. Under time grouping the folders are one Project-wide set whose fetch fans out+ to every contributing Agent, so a single request can return several pages; the extra rows stay in+ memory under the cap instead of landing on screen at once.+- The row names what it still hides — the rows past the cap plus the folder's unfetched remainder —+ and disappears once nothing is left, with a "Show less" row folding the folder back to its first+ ten. A search still forces every folder open with its matches and offers neither row.diff --git a/changelog/unreleased/2026-09-12-sidebar-folder-reveal.zh.md b/changelog/unreleased/2026-09-12-sidebar-folder-reveal.zh.mdnew file mode 100644index 00000000..37ef0cf3--- /dev/null+++ b/changelog/unreleased/2026-09-12-sidebar-folder-reveal.zh.md@@ -0,0 +1,16 @@+# 侧边栏折叠夹一次显示十个对话,并可折回++- **Date:** 2026-09-12+- **Type:** fix+- **Scope:** `web`, `docs`+- **PR:** [#712](https://github.com/Prism-Shadow/penguin-harness/pull/712)++[English](2026-09-12-sidebar-folder-reveal.md)++会话列表的折叠夹——子智能体、定时任务、已归档——把取回的行全部显示出来,且无法回退:在还剩 28 个对话的「已归档」上点一次「更多」,一次露出 13 条;份额加载齐后又没有任何入口把它们收回去。现在折叠夹遵守与上方活跃列表相同的显示规则:一次显示十行,「展开其余 N 个对话」再显示十行,并有与之并列的「收起」把它折回最前十行。++## 细节++- 每个折叠夹各有自己的显示上限,由它自己的展开行按页抬升,并与活跃列表同口径地在切换分组方式与切换 Project 时复位。+- 展开行先显示内存里已加载的行,不够时才向服务端再取一页。按时间分组时折叠夹是 Project 范围内共享的一组,取数会扇出到每个有份额的 Agent,因此一次请求可能取回好几页;多出来的行留在内存里、不越过显示上限,不会一次全部落到屏幕上。+- 该行报出它仍然藏着的数量——上限之外的已加载行加上本夹未取回的余量——藏无可藏时消失,另由「收起」一行把折叠夹折回最前十条。搜索时折叠夹仍强制展开显示命中结果,两行都不出现。diff --git a/packages/docs/content/web-app.en.md b/packages/docs/content/web-app.en.mdindex c02d4f26..9855f26b 100644--- a/packages/docs/content/web-app.en.md+++ b/packages/docs/content/web-app.en.md@@ -52,6 +52,8 @@ Beside a row's title sit its status marks: a turning hourglass while the SessionPinning is offered only in the active list — the archived, subagent and scheduled folders leave it out — and a pinned conversation sorts to the top of its group. The choice is remembered per Project in the browser.+An expanded folder reveals ten conversations at a time, the window the active list above it already uses: **Show N more chats** reveals ten more per click — rows already in memory first, and a page is fetched from the server only when they run short, so a fetch that returns more than a page leaves the extra rows in memory rather than on screen. As soon as the folder shows more than those first ten a **Show less** row stands beside the reveal row and folds it back to them; the reveal row itself disappears once the folder's whole share is on screen.+### Streaming Rendering- Model text renders token by token; thinking blocks are collapsible;diff --git a/packages/docs/content/web-app.zh.md b/packages/docs/content/web-app.zh.mdindex 19a70217..c2980561 100644--- a/packages/docs/content/web-app.zh.md+++ b/packages/docs/content/web-app.zh.md@@ -52,6 +52,8 @@ penguin web置顶只在活跃列表里出现(已归档、子智能体与定时任务的折叠夹中没有这一项),置顶的会话排在所属分组的最前面,该状态按 Project 记在浏览器本地。+展开的折叠夹一次只显示十个对话,与上方活跃列表同一口径:**展开其余 N 个对话**每次再显示十个——先显示内存里已加载的行,不够时才向服务端再取一页,因此一次取回多于一页时,多出来的行留在内存里而不落到屏幕上。折叠夹显示的行数一超过最前十条,**收起**一行便与展开行并列出现,把它折回这十条;展开行本身则在本夹份额全部显示后消失。+### 流式渲染- 模型文本逐 Token 渲染,思考块可折叠;diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsxindex 6fd758b2..f9df9f67 100644--- a/packages/web/src/components/layout/sidebar.tsx+++ b/packages/web/src/components/layout/sidebar.tsx@@ -59,9 +59,9 @@ import {groupPageSlice,groupSessionsByTime,groupSessionsByWorkspace,- hiddenRowCount,matchesSessionQuery,partitionSessions,+ revealPlan,sessionCategory,totalCategoryCounts,workspaceGroupKey,@@ -468,6 +468,7 @@ export function Sidebar({setGroupPage(0);// The other Project's groups are gone, and so is any meaning their reveal state had.setGroupCaps(new Map());+ setFolderCaps(new Map());// eslint-disable-next-line react-hooks/exhaustive-deps}, [collapseStoreKey, pinStoreKey, currentProjectId]);/** Expanded folders (subagent / scheduled / archived; collapsed by default), keyed by folderKey — each folder has its own open state. */@@ -476,6 +477,8 @@ export function Sidebar({const [pendingLoads, setPendingLoads] = useState<ReadonlySet<string>>(new Set());/** Per-group display cap for active rows (keyed by group key; absent = SIDEBAR_PAGE_SIZE). "More" raises it a page at a time. */const [groupCaps, setGroupCaps] = useState<ReadonlyMap<string, number>>(new Map());+ /** The same display cap per folder (keyed by folderKey; absent = SIDEBAR_PAGE_SIZE), so an expanded folder reveals a page at a time instead of everything a fetch returned. */+ const [folderCaps, setFolderCaps] = useState<ReadonlyMap<string, number>>(new Map());/** Which PAGE of groups renders (#139: dozens of Agents/Workspaces made the list too tall to scan), 0-based; reset per Project and on a mode switch, and clamped at render to the pages that still exist. */const [groupPage, setGroupPage] = useState(0);/** Session pending delete confirmation (null = none). */@@ -504,6 +507,7 @@ export function Sidebar({setGroupOrder(loadGroupOrder(currentProjectId, mode));setGroupPage(0);setGroupCaps(new Map());+ setFolderCaps(new Map());};/** Collapse/expand the page-nav group (same store-then-set convention as setGroupMode). */@@ -1289,18 +1293,58 @@ export function Sidebar({</ul>);+ /**+ * A folder's "Show N more chats": reveal one more page of the rows it already holds,+ * and fetch its next server page only when the reveal actually runs past them and+ * somewhere is left to fetch from. Mirrors the active list's showMore — a page already+ * in memory spends no request, which in time mode is a fan-out across every+ * contributing Agent.+ */+ const revealFolderMore = (+ groupKey: string,+ category: FolderCategory,+ agentIds: string[],+ loaded: number,+ ) => {+ const key = folderKey(groupKey, category);+ const nextCap = (folderCaps.get(key) ?? SIDEBAR_PAGE_SIZE) + SIDEBAR_PAGE_SIZE;+ setFolderCaps((prev) => {+ const next = new Map(prev);+ next.set(key, nextCap);+ return next;+ });+ if (loaded < nextCap && agentIds.some((id) => hasMoreFor(id, category, fetchScope(groupKey)))) {+ trackedLoadMore(groupKey, category, agentIds);+ }+ };++ /** A folder's "show less": back to the first page (rows already fetched stay in memory). */+ const collapseFolder = (key: string) => {+ setFolderCaps((prev) => {+ if (!prev.has(key)) return prev;+ const next = new Map(prev);+ next.delete(key);+ return next;+ });+ };+/*** Collapsed-by-default lazy folder (subagent / scheduled / archived): nothing is- * fetched until the first expand, and once open the folder pages independently with- * its own "More" row. Everything is driven by the group's **own** exact server share- * (`totals` — the Agent's counts in agent mode, the per-Workspace fold in workspace- * mode): the folder exists only while its share is non-zero, the label shows that- * share, and "More" shows only while loaded rows fall short of it — an Agent's- * content in *other* Workspaces can never surface a folder here. The folder's "More"- * pages independently of the active list's; in workspace mode a fetched page can land- * rows in other groups' folders too, so one click may grow this folder by fewer than- * a full page — the row shows a loading state while the fetch runs and stays until- * this group's share is fully loaded.+ * fetched until the first expand, and once open the folder reveals and pages+ * independently with its own "More" and "show less" rows. Everything is driven by the+ * group's **own** exact server share (`totals` — the Agent's counts in agent mode, the+ * per-Workspace fold in workspace mode): the folder exists only while its share is+ * non-zero, the label shows that share, and "More" shows only while something of that+ * share is still hidden — an Agent's content in *other* Workspaces can never surface a+ * folder here.+ *+ * The folder obeys the same display rule the active list does (revealPlan): one page+ * of rows shows at a time and "More" reveals one page more, spending a fetch only when+ * the reveal runs past what is in memory. In time mode the folders span every contributing+ * Agent, so one fetch can return several pages at once; they stay in memory under the+ * cap rather than all landing on screen. In workspace mode a fetched page can land rows+ * in other groups' folders too, so one click may grow this folder by fewer than a full+ * page — the row shows a loading state while the fetch runs.*/const renderFolder = (groupKey: string,@@ -1315,32 +1359,40 @@ export function Sidebar({// While searching the folder speaks for its loaded MATCHES only: a match hidden// behind a collapsed folder would look like a missing result (the models page's// search-forces-open rationale), so the folder is forced open, labelled by the- // match count, hidden when nothing matches, and never offers "More" (the server- // cannot search unloaded rows).+ // match count, hidden when nothing matches, and never offers "More" or "show less"+ // (the server cannot search unloaded rows, and every match is already on screen).if (searching && rows.length === 0) return null;// Loaded rows win a disagreement with the totals (counts refresh only on reload).const total = searching ? rows.length : Math.max(totals?.[category] ?? 0, rows.length);if (total === 0) return null;- // More while the group's share isn't fully loaded AND somewhere is left to fetch from- // (counts drifting above reality would otherwise leave a dead button until reload).- const more =- !searching &&- rows.length < total &&- agentIds.some((id) => hasMoreFor(id, category, fetchScope(groupKey)));+ const key = folderKey(groupKey, category);+ const cap = folderCaps.get(key) ?? SIDEBAR_PAGE_SIZE;+ // The folder's whole share is in memory (every Agent that could hold a row of it is+ // fetched out), which is when the loaded rows become the truth — the same clause the+ // active list applies, and what keeps a count drifting above reality from leaving a+ // reveal row with nothing behind it.+ const fullyLoaded =+ agentIds.length > 0 && !agentIds.some((id) => hasMoreFor(id, category, fetchScope(groupKey)));+ const plan = revealPlan({ cap, loaded: rows.length, total, fullyLoaded });+ const shown = searching ? rows : rows.slice(0, plan.shown);+ const hidden = searching ? 0 : plan.hidden;return (<FolderSectionkey={category}label={S.chat.folderGroups[category](total)}- open={searching || openFolders.has(folderKey(groupKey, category))}+ open={searching || openFolders.has(key)}onToggle={() => toggleFolder(groupKey, category, agentIds)}- more={more}- // The folder shows every row it has loaded, so its remainder is its own share- // minus those — the same count the active list's reveal row names one level up.- moreLabel={S.chat.expandRestSessions(Math.max(total - rows.length, 0))}+ more={hidden > 0}+ // The rows past the cap plus the unfetched remainder of this folder's own share —+ // the same count, and the same wording, the active list's reveal row names one+ // level up.+ moreLabel={S.chat.expandRestSessions(hidden)}pending={pendingLoads.has(loadKey(groupKey, category))}- onMore={() => trackedLoadMore(groupKey, category, agentIds)}+ onMore={() => revealFolderMore(groupKey, category, agentIds, rows.length)}+ less={!searching && plan.canCollapse}+ onLess={() => collapseFolder(key)}>- {renderRows(rows, withAgentHint)}+ {renderRows(shown, withAgentHint)}</FolderSection>);};@@ -1386,7 +1438,6 @@ export function Sidebar({totals: SessionCategoryCounts | undefined,agentsFor: (category: SessionCategory) => string[],) => {- const cap = groupCaps.get(groupKey) ?? SIDEBAR_PAGE_SIZE;// Row order: the pinned cluster first, then — under manual sort — the stored order// within each pin partition (lib/session-order.ts). Both reorder only rows already// FETCHED: a pinned conversation that lives past the loaded pages does not surface@@ -1402,7 +1453,6 @@ export function Sidebar({order: sessionOrder,recencyOf: (s) => s.lastActiveAt,});- const shownActive = searching ? orderedActive : orderedActive.slice(0, cap);/** Manual sort only (never on a search-filtered view): drag scope + the group's full ordered list, so a drop commits the whole partition. */const dragCtx =effectiveSortMode === "manual" && !searching@@ -1418,18 +1468,18 @@ export function Sidebar({const fullyLoaded =activeAgents.length > 0 &&!activeAgents.some((id) => hasMoreFor(id, "active", fetchScope(groupKey)));- const hiddenActive = searching- ? 0- : hiddenRowCount({- shown: shownActive.length,- loaded: parts.active.length,- total: totals?.active ?? 0,- fullyLoaded,- });- // "Show less" appears once the group is revealed past its first page and there is- // something for it to hide again.- const canCollapse =- !searching && cap > SIDEBAR_PAGE_SIZE && parts.active.length > SIDEBAR_PAGE_SIZE;+ // One page of rows at a time, what the reveal row still hides, and whether "Show less"+ // has anything to fold away: the single rule revealPlan states, applied here and by+ // every folder below.+ const plan = revealPlan({+ cap: groupCaps.get(groupKey) ?? SIDEBAR_PAGE_SIZE,+ loaded: parts.active.length,+ total: totals?.active ?? 0,+ fullyLoaded,+ });+ const shownActive = searching ? orderedActive : orderedActive.slice(0, plan.shown);+ const hiddenActive = searching ? 0 : plan.hidden;+ const canCollapse = !searching && plan.canCollapse;const folders = FOLDER_CATEGORIES.map((category) =>renderFolder(groupKey, category, parts, withAgentHint, agentsFor(category), totals),);diff --git a/packages/web/src/components/ui/group-list.tsx b/packages/web/src/components/ui/group-list.tsxindex 341cef74..a53da716 100644--- a/packages/web/src/components/ui/group-list.tsx+++ b/packages/web/src/components/ui/group-list.tsx@@ -217,7 +217,9 @@ export function GroupPager({/*** Collapsed-by-default lazy folder (subagent / scheduled / archived): the toggle row* shows the label (typically with the group's exact server share), the body renders only- * while open, and an optional "More" row pages the folder independently.+ * while open, and an optional "More" row reveals and pages the folder independently. The+ * "show less" row below it folds the folder back to its first page; the two can stand at+ * once, since a folder revealed part-way still has rows to show AND rows to fold away.*/export function FolderSection({label,@@ -227,6 +229,8 @@ export function FolderSection({moreLabel,pending = false,onMore,+ less = false,+ onLess,children,}: {label: string;@@ -243,6 +247,9 @@ export function FolderSection({/** The folder's "More" fetch in flight. */pending?: boolean;onMore?: () => void;+ /** Show the folder's "show less" row (it is revealed past its first page and has rows to fold away). */+ less?: boolean;+ onLess?: () => void;children?: ReactNode;}) {return (@@ -260,6 +267,9 @@ export function FolderSection({onClick={() => onMore?.()}/>)}+ {open && less && (+ <MoreRow label={S.chat.showLess} ariaLabel={S.chat.showLess} onClick={() => onLess?.()} />+ )}</div>);}diff --git a/packages/web/src/lib/session-grouping.ts b/packages/web/src/lib/session-grouping.tsindex 901d5cc3..f4b5085c 100644--- a/packages/web/src/lib/session-grouping.ts+++ b/packages/web/src/lib/session-grouping.ts@@ -130,6 +130,40 @@ export function hiddenRowCount({return Math.max((fullyLoaded ? loaded : Math.max(total, loaded)) - shown, 0);}+/**+ * The display window of one sidebar list — a group's active rows, or one of its+ * collapsed folders; both obey the same rule and both read it from here. The list shows+ * `SIDEBAR_PAGE_SIZE` rows, every "more" click reveals one page more, and a "show less"+ * stands beside the reveal row (not after it) from the moment the list is revealed past+ * its first page, folding it back to exactly that page. Rows beyond the cap stay in+ * memory — a fetch that returned far more than a page (a time-mode folder fans out over+ * every contributing Agent) is revealed a page at a time instead of all at once.+ *+ * `cap` is the list's current display cap, `loaded` the rows in memory, `total` its+ * exact server share and `fullyLoaded` whether every Agent that could hold one of its+ * rows is fetched out (see hiddenRowCount for why that last one decides the count).+ * "Show less" needs both a raised cap and more loaded rows than a page — otherwise there+ * is nothing for it to fold away.+ */+export function revealPlan({+ cap,+ loaded,+ total,+ fullyLoaded,+}: {+ cap: number;+ loaded: number;+ total: number;+ fullyLoaded: boolean;+}): { shown: number; hidden: number; canCollapse: boolean } {+ const shown = Math.min(Math.max(cap, 0), loaded);+ return {+ shown,+ hidden: hiddenRowCount({ shown, loaded, total, fullyLoaded }),+ canCollapse: cap > SIDEBAR_PAGE_SIZE && loaded > SIDEBAR_PAGE_SIZE,+ };+}+/*** Applies the limit+1 fetch trick: `fetched` came from a request with `limit = pageSize + 1`;* the visible page is the first `pageSize` items, and an overflow item (never shown) provesdiff --git a/packages/web/test/group-paging.test.ts b/packages/web/test/group-paging.test.tsindex 47b66729..ad374da8 100644--- a/packages/web/test/group-paging.test.ts+++ b/packages/web/test/group-paging.test.ts@@ -1,22 +1,26 @@/**- * session-grouping.ts unit tests for the sidebar's two display windows: the PAGE of- * groups the list shows at a time, and the count of conversations one group still hides- * behind its "Show N more chats" row.+ * session-grouping.ts unit tests for the sidebar's display windows: the PAGE of groups the+ * list shows at a time, the count of conversations one group still hides behind its+ * "Show N more chats" row, and the window a single folder reveals through that same row.** The invariants worth pinning: a page number always resolves to a page that exists* (groups come and go under a stored page), search-free slicing never drops or repeats a- * group across pages, and the hidden count is computed from ONE group's own numbers —- * with the loaded rows overriding a server total that drifted above reality, so the- * reveal row can never promise conversations that are not there.+ * group across pages, the hidden count is computed from ONE group's own numbers — with the+ * loaded rows overriding a server total that drifted above reality, so the reveal row can+ * never promise conversations that are not there — and a list (a group's active rows, or+ * one of its folders) reveals one page per click whatever a fetch returned, folding back+ * to exactly that first page and never to nothing.*/import { describe, expect, it } from "vitest";import {SIDEBAR_GROUP_PAGE_SIZE,+ SIDEBAR_PAGE_SIZE,clampGroupPage,groupPageCount,groupPageOf,groupPageSlice,hiddenRowCount,+ revealPlan,} from "../src/lib/session-grouping";const seq = (n: number) => Array.from({ length: n }, (_, i) => i);@@ -99,3 +103,83 @@ describe("hiddenRowCount", () => {expect(hiddenRowCount({ shown: 20, loaded: 8, total: 3, fullyLoaded: false })).toBe(0);});});++describe("revealPlan", () => {+ it("shows one page of a folder whose share is barely fetched, with no way back yet", () => {+ // The reported bug: a fetch that returned 13 rows revealed all 13 at once and then had+ // nothing to fold them back with.+ expect(revealPlan({ cap: 10, loaded: 10, total: 28, fullyLoaded: false })).toEqual({+ shown: 10,+ hidden: 18,+ canCollapse: false,+ });+ });++ it("reveals a page at a time, keeping the rows a fetch over-returned under the cap", () => {+ expect(revealPlan({ cap: 20, loaded: 23, total: 28, fullyLoaded: false })).toEqual({+ shown: 20,+ hidden: 8,+ canCollapse: true,+ });+ });++ it("drops the reveal row and keeps the collapse once the whole share is on screen", () => {+ expect(revealPlan({ cap: 30, loaded: 28, total: 28, fullyLoaded: true })).toEqual({+ shown: 28,+ hidden: 0,+ canCollapse: true,+ });+ });++ it("shows nothing it does not hold: the cap never promises unfetched rows", () => {+ expect(revealPlan({ cap: 20, loaded: 3, total: 3, fullyLoaded: true })).toEqual({+ shown: 3,+ hidden: 0,+ canCollapse: false,+ });+ });++ it("offers no collapse on a folder that fits in its first page", () => {+ const plan = revealPlan({+ cap: SIDEBAR_PAGE_SIZE,+ loaded: SIDEBAR_PAGE_SIZE,+ total: SIDEBAR_PAGE_SIZE,+ fullyLoaded: true,+ });+ expect(plan).toEqual({ shown: SIDEBAR_PAGE_SIZE, hidden: 0, canCollapse: false });+ });++ it("reveals the eleventh row and stops, rather than everything past the page", () => {+ // A list of exactly 11: ten show, the reveal row names the single row it hides (the+ // label's singular branch), and one click lands on 11 with nothing more to reveal.+ expect(revealPlan({ cap: 10, loaded: 10, total: 11, fullyLoaded: false })).toEqual({+ shown: 10,+ hidden: 1,+ canCollapse: false,+ });+ expect(revealPlan({ cap: 20, loaded: 11, total: 11, fullyLoaded: true })).toEqual({+ shown: 11,+ hidden: 0,+ canCollapse: true,+ });+ });++ it("folds back to the first page and not to nothing", () => {+ // What "show less" leaves behind: the cap returns to one page while every fetched row+ // stays in memory, so the window is the first ten again — with the reveal row back,+ // naming the rest — rather than an emptied list.+ expect(+ revealPlan({ cap: SIDEBAR_PAGE_SIZE, loaded: 28, total: 28, fullyLoaded: true }),+ ).toEqual({ shown: SIDEBAR_PAGE_SIZE, hidden: 18, canCollapse: false });+ });++ it("drops a stale total once every contributing Agent is fetched out", () => {+ // Same clause hiddenRowCount applies: counts refresh only on reload, and a folder must+ // not keep a reveal row standing over rows that no longer exist.+ expect(revealPlan({ cap: 10, loaded: 10, total: 42, fullyLoaded: true })).toEqual({+ shown: 10,+ hidden: 0,+ canCollapse: false,+ });+ });+});