Skip to content

Commit f57a875

Browse files
authored
fix(ui): cap sidebar child sessions with show-more, drop Subagent prefix in tree (#110604)
* fix(ui): cap sidebar child sessions at four with show-more, drop Subagent prefix in tree * test(ui): split child-session cap cases under the max-lines budget
1 parent 347ee45 commit f57a875

8 files changed

Lines changed: 242 additions & 3 deletions

File tree

‎ui/src/components/app-sidebar-session-list.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { icons } from "./icons.ts";
2727
import { renderSessionRowBadges } from "./session-row-badges.ts";
2828
import "./elapsed-time.ts";
2929

30+
const SIDEBAR_VISIBLE_CHILD_SESSION_LIMIT = 4;
31+
3032
/** Session-list presentation and catalog renderer wiring. */
3133
export abstract class AppSidebarSessionListElement extends AppSidebarMenusElement {
3234
@state() protected catalogProjectGrouping = loadStoredSidebarCatalogGrouping();
@@ -242,14 +244,43 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
242244

243245
private renderSessionTree(session: SidebarRecentSession): TemplateResult {
244246
const expanded = this.isSessionChildrenExpanded(session);
247+
const showAllChildren = this.fullyShownChildSessionKeys.has(session.key);
248+
// The cap hides quiet children only: the active branch and any branch with
249+
// live runs (runningChildCount is transitive) must stay visible, or an
250+
// auto-expanded parent would omit its own selection or a running session.
251+
const visibleChildren = showAllChildren
252+
? session.children
253+
: session.children.filter(
254+
(child, index) =>
255+
index < SIDEBAR_VISIBLE_CHILD_SESSION_LIMIT ||
256+
child.visuallyActive ||
257+
child.containsActiveDescendant ||
258+
child.hasActiveRun ||
259+
child.status === "running" ||
260+
child.runningChildCount > 0,
261+
);
262+
const hiddenChildCount = session.children.length - visibleChildren.length;
245263
return html`<div class="sidebar-session-tree" data-session-tree=${session.key}>
246264
${this.renderRecentSession(session)}
247265
${expanded
248266
? html`<div
249267
class="sidebar-session-tree__children"
250268
aria-label=${t("sessionsView.childSessions")}
251269
>
252-
${session.children.map((child) => this.renderSessionTree(child))}
270+
${visibleChildren.map((child) => this.renderSessionTree(child))}
271+
${hiddenChildCount > 0
272+
? html`<button
273+
class="sidebar-session-tree__show-more"
274+
type="button"
275+
data-show-more-children=${session.key}
276+
aria-label=${t("sessionsView.showMoreChildren", {
277+
count: String(hiddenChildCount),
278+
})}
279+
@click=${() => this.showAllSessionChildren(session.key)}
280+
>
281+
${t("sessionsView.showMoreChildren", { count: String(hiddenChildCount) })}
282+
</button>`
283+
: nothing}
253284
${session.loadingChildren && session.children.length === 0
254285
? html`<span class="sidebar-session-tree__loading">${t("common.loading")}</span>`
255286
: nothing}

‎ui/src/components/app-sidebar-session-navigation.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export abstract class AppSidebarSessionNavigationElement extends AppSidebarSessi
5353
@state() protected selectedSessionKeys: ReadonlySet<string> = new Set();
5454
@state() protected expandedChildSessionKeys: ReadonlySet<string> = new Set();
5555
@state() protected collapsedActiveChildSessionKeys: ReadonlySet<string> = new Set();
56+
@state() protected fullyShownChildSessionKeys: ReadonlySet<string> = new Set();
5657
@state() protected sessionSortMode: SidebarSessionSortMode = "created";
5758
@state() protected sessionsGrouping: SidebarSessionsGrouping =
5859
loadStoredSidebarSessionsGrouping();
@@ -162,7 +163,9 @@ export abstract class AppSidebarSessionNavigationElement extends AppSidebarSessi
162163
}
163164
return {
164165
key: row.key,
165-
label: resolveSessionDisplayName(row.key, row),
166+
label: resolveSessionDisplayName(row.key, row, {
167+
includeSubagentPrefix: !isChild,
168+
}),
166169
meta: formatSidebarTimestamp(row.updatedAt),
167170
subtitle: resolveSessionWorkSubtitle(row),
168171
href: `${pathForRoute("chat", context?.basePath ?? "")}${searchForSession(row.key)}`,
@@ -618,8 +621,10 @@ export abstract class AppSidebarSessionNavigationElement extends AppSidebarSessi
618621
protected toggleSessionChildren(session: SidebarRecentSession) {
619622
const next = new Set(this.expandedChildSessionKeys);
620623
const collapsedActive = new Set(this.collapsedActiveChildSessionKeys);
624+
const fullyShown = new Set(this.fullyShownChildSessionKeys);
621625
if (this.isSessionChildrenExpanded(session)) {
622626
next.delete(session.key);
627+
fullyShown.delete(session.key);
623628
if (session.containsActiveDescendant) {
624629
collapsedActive.add(session.key);
625630
}
@@ -643,6 +648,11 @@ export abstract class AppSidebarSessionNavigationElement extends AppSidebarSessi
643648
}
644649
this.expandedChildSessionKeys = next;
645650
this.collapsedActiveChildSessionKeys = collapsedActive;
651+
this.fullyShownChildSessionKeys = fullyShown;
652+
}
653+
654+
protected showAllSessionChildren(sessionKey: string) {
655+
this.fullyShownChildSessionKeys = new Set(this.fullyShownChildSessionKeys).add(sessionKey);
646656
}
647657

648658
private projectSessionTree(

‎ui/src/components/app-sidebar.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import "../test-helpers/app-sidebar-cases/catalog-live-events.ts";
88
import "../test-helpers/app-sidebar-cases/catalog-live.ts";
99
import "../test-helpers/app-sidebar-cases/catalog-live-state.ts";
1010
import "../test-helpers/app-sidebar-cases/catalog-pages.ts";
11+
import "../test-helpers/app-sidebar-cases/child-sessions-cap.ts";
1112
import "../test-helpers/app-sidebar-cases/child-sessions.ts";
1213
import "../test-helpers/app-sidebar-cases/group-mutations.ts";
1314
import "../test-helpers/app-sidebar-cases/interactions.ts";

‎ui/src/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ export const en: TranslationMap = {
627627
showChildSessions: "Show {count} child sessions for {session}",
628628
hideChildSessions: "Hide {count} child sessions for {session}",
629629
childSessions: "Child sessions",
630+
showMoreChildren: "Show {count} more",
630631
archived: "Archived",
631632
pinned: "Pinned",
632633
unread: "Unread",

‎ui/src/lib/session-display.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,34 @@ describe("resolveSessionDisplayName", () => {
7777
"node-fleet-…8b2e",
7878
);
7979
});
80+
81+
it("can omit only the subagent prefix while preserving its untitled fallback", () => {
82+
const key = "agent:main:subagent:worker";
83+
expect(resolveSessionDisplayName(key, { label: "Research sources" })).toBe(
84+
"Subagent: Research sources",
85+
);
86+
expect(
87+
resolveSessionDisplayName(
88+
key,
89+
{ label: "Subagent: Research sources" },
90+
{
91+
includeSubagentPrefix: false,
92+
},
93+
),
94+
).toBe("Research sources");
95+
expect(resolveSessionDisplayName(key, undefined, { includeSubagentPrefix: false })).toBe(
96+
"Subagent:",
97+
);
98+
expect(
99+
resolveSessionDisplayName(
100+
"agent:main:cron:daily",
101+
{ label: "Daily" },
102+
{
103+
includeSubagentPrefix: false,
104+
},
105+
),
106+
).toBe("Cron: Daily");
107+
});
80108
});
81109

82110
describe("resolveSessionWorkSubtitle", () => {

‎ui/src/lib/session-display.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type SessionDisplayRow = {
9292
derivedTitle?: string;
9393
} & SessionWorktreeDisplayRow;
9494

95+
type SessionDisplayOptions = {
96+
includeSubagentPrefix?: boolean;
97+
};
98+
9599
function capitalize(s: string): string {
96100
return s.charAt(0).toUpperCase() + s.slice(1);
97101
}
@@ -169,7 +173,11 @@ function parseSessionKey(key: string): SessionKeyInfo {
169173
return { prefix: "", fallbackName: key };
170174
}
171175

172-
export function resolveSessionDisplayName(key: string, row?: SessionDisplayRow): string {
176+
export function resolveSessionDisplayName(
177+
key: string,
178+
row?: SessionDisplayRow,
179+
options: SessionDisplayOptions = {},
180+
): string {
173181
const label = normalizeOptionalString(row?.label) ?? "";
174182
const displayName = normalizeOptionalString(row?.displayName) ?? "";
175183
const derivedTitle = normalizeOptionalString(row?.derivedTitle) ?? "";
@@ -180,6 +188,9 @@ export function resolveSessionDisplayName(key: string, row?: SessionDisplayRow):
180188
return name;
181189
}
182190
const prefixPattern = new RegExp(`^${prefix.replace(/[.*+?^${}()|[\\]\\]/g, "\\$&")}\\s*`, "i");
191+
if (prefix === "Subagent:" && options.includeSubagentPrefix === false) {
192+
return name.replace(prefixPattern, "").trim() || fallbackName;
193+
}
183194
return prefixPattern.test(name) ? name : `${prefix} ${name}`;
184195
};
185196

‎ui/src/styles/layout.css‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,22 @@ html.openclaw-native-macos
15051505
font-size: 11px;
15061506
}
15071507

1508+
.sidebar-session-tree__show-more {
1509+
min-height: 28px;
1510+
padding: 6px 8px;
1511+
border: 0;
1512+
background: transparent;
1513+
color: var(--muted);
1514+
font-size: 11px;
1515+
font-weight: 400;
1516+
text-align: left;
1517+
}
1518+
1519+
.sidebar-session-tree__show-more:hover,
1520+
.sidebar-session-tree__show-more:focus-visible {
1521+
color: var(--text);
1522+
}
1523+
15081524
.sidebar-recent-sessions__group[data-session-section^="catalog:"] > .sidebar-recent-sessions__list {
15091525
gap: 8px;
15101526
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { GatewayBrowserClient } from "../../api/gateway.ts";
3+
import { createGateway, createSessionsHarness, mountSidebar } from "../app-sidebar.ts";
4+
import { waitForFast } from "../wait-for.ts";
5+
import "../../components/app-sidebar.ts";
6+
7+
describe("AppSidebar child session cap", () => {
8+
it("caps visible children until requested and resets the cap after collapse", async () => {
9+
const gateway = createGateway({} as GatewayBrowserClient);
10+
const childKeys = Array.from(
11+
{ length: 6 },
12+
(_, index) => `agent:main:subagent:child-${index + 1}`,
13+
);
14+
const harness = createSessionsHarness("main", ["agent:main:parent"]);
15+
harness.list.mockResolvedValue({
16+
ts: 100_000,
17+
path: "",
18+
count: childKeys.length,
19+
defaults: { modelProvider: null, model: null, contextTokens: null },
20+
sessions: childKeys.map((key, index) => ({
21+
key,
22+
spawnedBy: "agent:main:parent",
23+
kind: "direct" as const,
24+
label: `Subagent: Child ${index + 1}`,
25+
updatedAt: index + 1,
26+
})),
27+
});
28+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
29+
harness.publishList({
30+
result: {
31+
ts: 2,
32+
path: "",
33+
count: 1,
34+
defaults: { modelProvider: null, model: null, contextTokens: null },
35+
sessions: [
36+
{
37+
key: "agent:main:parent",
38+
kind: "direct",
39+
label: "Parent task",
40+
updatedAt: 1,
41+
childSessions: childKeys,
42+
},
43+
],
44+
},
45+
});
46+
await sidebar.updateComplete;
47+
48+
const toggle = sidebar.querySelector<HTMLButtonElement>("[data-child-session-toggle]");
49+
toggle?.click();
50+
await waitForFast(() =>
51+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
52+
);
53+
const showMore = sidebar.querySelector<HTMLButtonElement>("[data-show-more-children]");
54+
expect(showMore?.textContent?.trim()).toBe("Show 2 more");
55+
expect(showMore?.getAttribute("aria-label")).toBe("Show 2 more");
56+
expect(sidebar.textContent).not.toContain("Subagent:");
57+
58+
showMore?.click();
59+
await waitForFast(() =>
60+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(6),
61+
);
62+
expect(sidebar.querySelector("[data-show-more-children]")).toBeNull();
63+
64+
toggle?.click();
65+
await sidebar.updateComplete;
66+
toggle?.click();
67+
await waitForFast(() =>
68+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
69+
);
70+
expect(sidebar.querySelector("[data-show-more-children]")?.textContent).toContain(
71+
"Show 2 more",
72+
);
73+
});
74+
75+
it("keeps live children visible past the cap", async () => {
76+
const gateway = createGateway({} as GatewayBrowserClient);
77+
const childKeys = Array.from(
78+
{ length: 6 },
79+
(_, index) => `agent:main:subagent:child-${index + 1}`,
80+
);
81+
const harness = createSessionsHarness("main", ["agent:main:parent"]);
82+
harness.list.mockResolvedValue({
83+
ts: 100_000,
84+
path: "",
85+
count: childKeys.length,
86+
defaults: { modelProvider: null, model: null, contextTokens: null },
87+
sessions: [
88+
...childKeys.map((key, index) => ({
89+
key,
90+
spawnedBy: "agent:main:parent",
91+
kind: "direct" as const,
92+
label: `Subagent: Child ${index + 1}`,
93+
updatedAt: index + 1,
94+
})),
95+
// Quiet child beyond the cap with a RUNNING grandchild: the branch
96+
// must bypass the cap via the transitive runningChildCount.
97+
{
98+
key: "agent:main:subagent:grandchild",
99+
spawnedBy: "agent:main:subagent:child-6",
100+
kind: "direct" as const,
101+
label: "Subagent: Grandchild run",
102+
updatedAt: 10,
103+
status: "running" as const,
104+
hasActiveRun: true,
105+
},
106+
],
107+
});
108+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
109+
harness.publishList({
110+
result: {
111+
ts: 2,
112+
path: "",
113+
count: 1,
114+
defaults: { modelProvider: null, model: null, contextTokens: null },
115+
sessions: [
116+
{
117+
key: "agent:main:parent",
118+
kind: "direct",
119+
label: "Parent task",
120+
updatedAt: 1,
121+
childSessions: childKeys,
122+
},
123+
],
124+
},
125+
});
126+
await sidebar.updateComplete;
127+
128+
sidebar
129+
.querySelector<HTMLButtonElement>('[data-child-session-toggle="agent:main:parent"]')
130+
?.click();
131+
await waitForFast(() =>
132+
expect(
133+
sidebar.querySelector('[data-session-key="agent:main:subagent:child-6"]'),
134+
).not.toBeNull(),
135+
);
136+
expect(sidebar.querySelector('[data-session-key="agent:main:subagent:child-5"]')).toBeNull();
137+
expect(sidebar.querySelector("[data-show-more-children]")?.textContent?.trim()).toBe(
138+
"Show 1 more",
139+
);
140+
});
141+
});

0 commit comments

Comments
 (0)