Skip to content

Commit da2d9ac

Browse files
committed
fix(ui): cap sidebar child sessions at four with show-more, drop Subagent prefix in tree
1 parent 5057fd9 commit da2d9ac

7 files changed

Lines changed: 234 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/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ export const en: TranslationMap = {
625625
showChildSessions: "Show {count} child sessions for {session}",
626626
hideChildSessions: "Hide {count} child sessions for {session}",
627627
childSessions: "Child sessions",
628+
showMoreChildren: "Show {count} more",
628629
archived: "Archived",
629630
pinned: "Pinned",
630631
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
}

‎ui/src/test-helpers/app-sidebar-cases/child-sessions.ts‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,140 @@ import { waitForFast } from "../wait-for.ts";
1212
import "../../components/app-sidebar.ts";
1313

1414
describe("AppSidebar agent chip", () => {
15+
it("caps visible children until requested and resets the cap after collapse", async () => {
16+
const gateway = createGateway({} as GatewayBrowserClient);
17+
const childKeys = Array.from(
18+
{ length: 6 },
19+
(_, index) => `agent:main:subagent:child-${index + 1}`,
20+
);
21+
const harness = createSessionsHarness("main", ["agent:main:parent"]);
22+
harness.list.mockResolvedValue({
23+
ts: 100_000,
24+
path: "",
25+
count: childKeys.length,
26+
defaults: { modelProvider: null, model: null, contextTokens: null },
27+
sessions: childKeys.map((key, index) => ({
28+
key,
29+
spawnedBy: "agent:main:parent",
30+
kind: "direct" as const,
31+
label: `Subagent: Child ${index + 1}`,
32+
updatedAt: index + 1,
33+
})),
34+
});
35+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
36+
harness.publishList({
37+
result: {
38+
ts: 2,
39+
path: "",
40+
count: 1,
41+
defaults: { modelProvider: null, model: null, contextTokens: null },
42+
sessions: [
43+
{
44+
key: "agent:main:parent",
45+
kind: "direct",
46+
label: "Parent task",
47+
updatedAt: 1,
48+
childSessions: childKeys,
49+
},
50+
],
51+
},
52+
});
53+
await sidebar.updateComplete;
54+
55+
const toggle = sidebar.querySelector<HTMLButtonElement>("[data-child-session-toggle]");
56+
toggle?.click();
57+
await waitForFast(() =>
58+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
59+
);
60+
const showMore = sidebar.querySelector<HTMLButtonElement>("[data-show-more-children]");
61+
expect(showMore?.textContent?.trim()).toBe("Show 2 more");
62+
expect(showMore?.getAttribute("aria-label")).toBe("Show 2 more");
63+
expect(sidebar.textContent).not.toContain("Subagent:");
64+
65+
showMore?.click();
66+
await waitForFast(() =>
67+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(6),
68+
);
69+
expect(sidebar.querySelector("[data-show-more-children]")).toBeNull();
70+
71+
toggle?.click();
72+
await sidebar.updateComplete;
73+
toggle?.click();
74+
await waitForFast(() =>
75+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
76+
);
77+
expect(sidebar.querySelector("[data-show-more-children]")?.textContent).toContain(
78+
"Show 2 more",
79+
);
80+
});
81+
82+
it("keeps live children visible past the cap", async () => {
83+
const gateway = createGateway({} as GatewayBrowserClient);
84+
const childKeys = Array.from(
85+
{ length: 6 },
86+
(_, index) => `agent:main:subagent:child-${index + 1}`,
87+
);
88+
const harness = createSessionsHarness("main", ["agent:main:parent"]);
89+
harness.list.mockResolvedValue({
90+
ts: 100_000,
91+
path: "",
92+
count: childKeys.length,
93+
defaults: { modelProvider: null, model: null, contextTokens: null },
94+
sessions: [
95+
...childKeys.map((key, index) => ({
96+
key,
97+
spawnedBy: "agent:main:parent",
98+
kind: "direct" as const,
99+
label: `Subagent: Child ${index + 1}`,
100+
updatedAt: index + 1,
101+
})),
102+
// Quiet child beyond the cap with a RUNNING grandchild: the branch
103+
// must bypass the cap via the transitive runningChildCount.
104+
{
105+
key: "agent:main:subagent:grandchild",
106+
spawnedBy: "agent:main:subagent:child-6",
107+
kind: "direct" as const,
108+
label: "Subagent: Grandchild run",
109+
updatedAt: 10,
110+
status: "running" as const,
111+
hasActiveRun: true,
112+
},
113+
],
114+
});
115+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
116+
harness.publishList({
117+
result: {
118+
ts: 2,
119+
path: "",
120+
count: 1,
121+
defaults: { modelProvider: null, model: null, contextTokens: null },
122+
sessions: [
123+
{
124+
key: "agent:main:parent",
125+
kind: "direct",
126+
label: "Parent task",
127+
updatedAt: 1,
128+
childSessions: childKeys,
129+
},
130+
],
131+
},
132+
});
133+
await sidebar.updateComplete;
134+
135+
sidebar
136+
.querySelector<HTMLButtonElement>('[data-child-session-toggle="agent:main:parent"]')
137+
?.click();
138+
await waitForFast(() =>
139+
expect(
140+
sidebar.querySelector('[data-session-key="agent:main:subagent:child-6"]'),
141+
).not.toBeNull(),
142+
);
143+
expect(sidebar.querySelector('[data-session-key="agent:main:subagent:child-5"]')).toBeNull();
144+
expect(sidebar.querySelector("[data-show-more-children]")?.textContent?.trim()).toBe(
145+
"Show 1 more",
146+
);
147+
});
148+
15149
it("loads and expands child sessions inline without root session controls", async () => {
16150
const gateway = createGateway({} as GatewayBrowserClient);
17151
const harness = createSessionsHarness("main", ["agent:main:parent"]);

0 commit comments

Comments
 (0)