Skip to content

Commit dad377c

Browse files
authored
feat(ui): group native session catalog rows by project in the sidebar (#109575)
* feat(ui): group native session catalog rows by project in the sidebar Codex and Claude session catalogs in the Control UI sidebar now group each host's sessions by project folder, mirroring Claude Code desktop: any cwd at or under <repo>/.claude/worktrees/<name> folds into the origin repo. A folder toggle icon in the catalog header flattens the list; grouping defaults to on and persists via localStorage (openclaw:sidebar:sessions:catalog-grouping). * chore(ui): drop generated i18n fallback metadata from source PR Post-rebase main forbids catalog fallback metadata in source PRs; the post-merge locale-refresh workflow reconciles foreign catalog parity. * chore(ui): keep CatalogProjectGroup type module-local knip dead-export gate: no external importers; callers rely on the inferred return shape of groupCatalogSessionsByProject. * test(scripts): drop retired workspace-state.json expectation Opportunistic CI fix: b6535fb/905395a3ff5 retired workspace-state seeding from scripts/e2e/parallels/agent-workspace.ts but the smoke-model test still asserted the removed string, breaking checks-node-compact-small-2 on every branch. * test(scripts): restore mainline retired-state regression guard Rebase conflict resolution wrongly kept this branch's older removal; main's 2256387 comment plus not.toContain assertion is the canonical fix.
1 parent ff9b291 commit dad377c

9 files changed

Lines changed: 307 additions & 10 deletions

File tree

‎docs/nodes/index.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ upgrade when those commands first appear. The Gateway invokes them through the
304304
normal plugin node policy and isolates failures by host.
305305

306306
Paired-node rows appear as a **Codex** group in the normal sessions sidebar.
307+
Within each host, rows group by project folder by default; a working directory
308+
under `.claude/worktrees/<name>` folds into its origin repository. Use the
309+
folder icon in the catalog header to flatten or restore the project groups.
310+
The same grouping applies to the Claude sessions catalog.
307311
By default, selecting a row opens the normal Chat pane and reads its persisted transcript
308312
through bounded, cursor-paginated
309313
`thread/turns/list` calls with full item projection. Use the row menu, the viewer header, or the **Open Codex/Claude sessions in** preference to start `codex resume <thread-id>` in the operator terminal on the computer that owns the session. The paired-node terminal path is an allowlisted PTY relay owned by the Codex plugin, not arbitrary node command execution.

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import type {
1515
CatalogSessionKey,
1616
} from "../lib/sessions/catalog-key.ts";
1717
import { buildCatalogSessionKey } from "../lib/sessions/catalog-key.ts";
18+
import {
19+
groupCatalogSessionsByProject,
20+
type CatalogProjectGrouping,
21+
} from "../lib/sessions/catalog-project-grouping.ts";
1822
import { searchForSession } from "../lib/sessions/index.ts";
1923
import type { NewSessionTarget } from "../pages/new-session/location.ts";
2024
import { shouldHandleNavigationClick } from "./app-sidebar-nav-menus.ts";
@@ -93,9 +97,11 @@ type SessionCatalogGroupsParams = {
9397
newSessionAgentId: string;
9498
collapsedSections: ReadonlySet<string>;
9599
loadingMoreCatalogIds: ReadonlySet<string>;
100+
projectGrouping: CatalogProjectGrouping;
96101
liveRows: readonly GatewaySessionRow[];
97102
renderLiveRow: (row: GatewaySessionRow, display: CatalogBackingSessionDisplay) => unknown;
98103
onToggleSection: (sectionId: string) => void;
104+
onToggleProjectGrouping: () => void;
99105
onLoadMore: (catalogId: string) => void;
100106
onOpenNewSession?: (agentId: string, target?: NewSessionTarget) => void;
101107
onNavigate?: (routeId: NavigationRouteId, options?: ApplicationNavigationOptions) => void;
@@ -208,6 +214,17 @@ export function renderSessionCatalogGroups(params: SessionCatalogGroupsParams) {
208214
>${hasError ? icons.alertTriangle : rows.length}</span
209215
>
210216
</button>
217+
<button
218+
type="button"
219+
class="sidebar-session-sort sidebar-session-catalog-grouping"
220+
aria-pressed=${String(params.projectGrouping === "project")}
221+
data-session-catalog-grouping-toggle=${catalog.id}
222+
title=${t("chat.sidebar.groupCatalogSessionsByProject")}
223+
aria-label=${t("chat.sidebar.groupCatalogSessionsByProject")}
224+
@click=${() => params.onToggleProjectGrouping()}
225+
>
226+
${icons.folder}
227+
</button>
211228
${canCreateSession
212229
? html`<button
213230
type="button"
@@ -255,6 +272,8 @@ function renderCatalogHostGroup(
255272
params: SessionCatalogGroupsParams,
256273
) {
257274
const errorHelp = host.error ? `[${host.error.code}] ${host.error.message}` : undefined;
275+
const projectGroups =
276+
params.projectGrouping === "project" ? groupCatalogSessionsByProject(host.sessions) : null;
258277
return html`
259278
<section class="sidebar-session-catalog-host" data-session-catalog-host=${host.hostId}>
260279
<div
@@ -272,9 +291,30 @@ function renderCatalogHostGroup(
272291
>
273292
</div>
274293
<div class="sidebar-session-catalog-host__sessions" role="list" aria-label=${host.label}>
275-
${host.sessions.map((session) =>
276-
renderCatalogSessionRow(catalog, host, session, liveRowsByKey, params),
277-
)}
294+
${projectGroups
295+
? html`${projectGroups.groups.map(
296+
(group) => html`
297+
<div
298+
class="sidebar-session-catalog-project__head"
299+
data-session-catalog-project=${group.key}
300+
title=${group.title}
301+
>
302+
<span class="sidebar-session-catalog-project__label">${group.label}</span>
303+
<span class="sidebar-session-catalog-project__count" aria-hidden="true"
304+
>${group.sessions.length}</span
305+
>
306+
</div>
307+
${group.sessions.map((session) =>
308+
renderCatalogSessionRow(catalog, host, session, liveRowsByKey, params),
309+
)}
310+
`,
311+
)}
312+
${projectGroups.ungrouped.map((session) =>
313+
renderCatalogSessionRow(catalog, host, session, liveRowsByKey, params),
314+
)}`
315+
: host.sessions.map((session) =>
316+
renderCatalogSessionRow(catalog, host, session, liveRowsByKey, params),
317+
)}
278318
</div>
279319
</section>
280320
`;

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { html, nothing, type TemplateResult } from "lit";
2+
import { state } from "lit/decorators.js";
23
import { keyed } from "lit/directives/keyed.js";
34
import { titleForRoute } from "../app-navigation.ts";
45
import { pathForRoute } from "../app-route-paths.ts";
@@ -18,9 +19,11 @@ import {
1819
} from "./app-sidebar-session-catalogs.ts";
1920
import {
2021
limitSidebarSessionRows,
22+
loadStoredSidebarCatalogGrouping,
2123
SIDEBAR_SESSION_PAGE_SIZE,
2224
SIDEBAR_SESSION_SEE_LESS_THRESHOLD,
2325
sidebarSessionMetaId,
26+
storeSidebarCatalogGrouping,
2427
type SidebarRecentSession,
2528
} from "./app-sidebar-session-types.ts";
2629
import { icons } from "./icons.ts";
@@ -29,6 +32,8 @@ import "./elapsed-time.ts";
2932

3033
/** Session-list presentation and catalog renderer wiring. */
3134
export abstract class AppSidebarSessionListElement extends AppSidebarMenusElement {
35+
@state() protected catalogProjectGrouping = loadStoredSidebarCatalogGrouping();
36+
3237
private renderSessionState(session: SidebarRecentSession) {
3338
if (session.hasActiveRun || (session.isChild && session.status === "running")) {
3439
return html`<span
@@ -51,7 +56,7 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
5156
if (!status) {
5257
return nothing;
5358
}
54-
const state =
59+
const statusBadge =
5560
status === "done"
5661
? { icon: icons.check, label: t("sessionsView.statusDone") }
5762
: status === "killed"
@@ -61,13 +66,13 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
6166
: status === "failed"
6267
? { icon: icons.alertTriangle, label: t("sessionsView.statusFailed") }
6368
: null;
64-
return state
69+
return statusBadge
6570
? html`<span
6671
class="sidebar-child-session__status sidebar-child-session__status--${status}"
6772
role="img"
68-
aria-label=${state.label}
69-
title=${state.label}
70-
>${state.icon}</span
73+
aria-label=${statusBadge.label}
74+
title=${statusBadge.label}
75+
>${statusBadge.icon}</span
7176
>`
7277
: nothing;
7378
}
@@ -540,13 +545,19 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
540545
newSessionAgentId: this.expandedAgentId(),
541546
collapsedSections: this.collapsedSessionSections,
542547
loadingMoreCatalogIds: this.loadingMoreSessionCatalogIds,
548+
projectGrouping: this.catalogProjectGrouping,
543549
liveRows: [
544550
...(this.sessionsResult?.sessions ?? []),
545551
...Object.values(this.sessionRowsByAgent).flat(),
546552
],
547553
renderLiveRow: (row, display) =>
548554
this.renderRecentSession(navigationState.toSidebarSession(row), display),
549555
onToggleSection: (sectionId) => this.toggleSessionSection(sectionId),
556+
onToggleProjectGrouping: () => {
557+
const next = this.catalogProjectGrouping === "project" ? "none" : "project";
558+
storeSidebarCatalogGrouping(next);
559+
this.catalogProjectGrouping = next;
560+
},
550561
onLoadMore: (catalogId) => void this.loadMoreSessionCatalog(catalogId),
551562
onOpenNewSession: this.onOpenNewSession,
552563
onNavigate: this.onNavigate,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { GatewayBrowserClient } from "../api/gateway.ts";
22
import type { SessionRunStatus } from "../api/types.ts";
33
import type { RouteId } from "../app-route-paths.ts";
44
import type { ApplicationContext } from "../app/context.ts";
5+
import {
6+
normalizeCatalogProjectGrouping,
7+
type CatalogProjectGrouping,
8+
} from "../lib/sessions/catalog-project-grouping.ts";
59
import {
610
normalizeSidebarSessionsGrouping,
711
type SidebarSessionsGrouping,
@@ -94,6 +98,7 @@ export function sidebarSessionMetaId(key: string): string {
9498
}
9599

96100
const SIDEBAR_SESSION_GROUPING_STORAGE_KEY = "openclaw:sidebar:sessions:grouping";
101+
const SIDEBAR_SESSION_CATALOG_GROUPING_STORAGE_KEY = "openclaw:sidebar:sessions:catalog-grouping";
97102
const SIDEBAR_SESSION_SHOW_CRON_STORAGE_KEY = "openclaw:sidebar:sessions:show-cron";
98103
const SIDEBAR_SESSION_COLLAPSED_SECTIONS_STORAGE_KEY =
99104
"openclaw:sidebar:sessions:collapsed-sections";
@@ -121,6 +126,12 @@ export function loadStoredSidebarSessionsGrouping(): SidebarSessionsGrouping {
121126
);
122127
}
123128

129+
export function loadStoredSidebarCatalogGrouping(): CatalogProjectGrouping {
130+
return normalizeCatalogProjectGrouping(
131+
getSafeLocalStorage()?.getItem(SIDEBAR_SESSION_CATALOG_GROUPING_STORAGE_KEY),
132+
);
133+
}
134+
124135
export function loadStoredSidebarSessionsShowCron(): boolean {
125136
return getSafeLocalStorage()?.getItem(SIDEBAR_SESSION_SHOW_CRON_STORAGE_KEY) === "true";
126137
}
@@ -143,6 +154,10 @@ export function storeSidebarSessionsGrouping(grouping: SidebarSessionsGrouping)
143154
getSafeLocalStorage()?.setItem(SIDEBAR_SESSION_GROUPING_STORAGE_KEY, grouping);
144155
}
145156

157+
export function storeSidebarCatalogGrouping(value: CatalogProjectGrouping) {
158+
getSafeLocalStorage()?.setItem(SIDEBAR_SESSION_CATALOG_GROUPING_STORAGE_KEY, value);
159+
}
160+
146161
export function storeSidebarSessionsShowCron(show: boolean) {
147162
getSafeLocalStorage()?.setItem(SIDEBAR_SESSION_SHOW_CRON_STORAGE_KEY, String(show));
148163
}

‎ui/src/e2e/codex-sessions.e2e.test.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const suite = available || !allowMissing ? describe : describe.skip;
1818
let browser: Browser;
1919
let server: ControlUiE2eServer;
2020
const captureUiProofEnabled = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
21+
const catalogGroupingStorageKey = "openclaw:sidebar:sessions:catalog-grouping";
2122
const uiProofArtifactDir = path.join(
2223
process.cwd(),
2324
".artifacts",
@@ -90,6 +91,7 @@ suite("Codex native session catalog", () => {
9091

9192
it("groups sessions by host and hides empty offline nodes", async () => {
9293
const page = await browser.newPage({ viewport: { height: 1100, width: 1440 } });
94+
await page.addInitScript((key) => localStorage.removeItem(key), catalogGroupingStorageKey);
9395
await installMockGateway(page, {
9496
featureMethods: ["chat.metadata", "chat.startup", "sessions.catalog.list"],
9597
methodResponses: {
@@ -109,6 +111,25 @@ suite("Codex native session catalog", () => {
109111
{
110112
threadId: "thread-local",
111113
name: "Local planning session",
114+
cwd: "/Users/dev/openclaw",
115+
status: "idle",
116+
archived: false,
117+
canContinue: true,
118+
canArchive: true,
119+
},
120+
{
121+
threadId: "thread-worktree",
122+
name: "Worktree fix session",
123+
cwd: "/Users/dev/openclaw/.claude/worktrees/fix-1",
124+
status: "idle",
125+
archived: false,
126+
canContinue: true,
127+
canArchive: true,
128+
},
129+
{
130+
threadId: "thread-other",
131+
name: "Other project session",
132+
cwd: "/Users/dev/other",
112133
status: "idle",
113134
archived: false,
114135
canContinue: true,
@@ -164,11 +185,50 @@ suite("Codex native session catalog", () => {
164185
expect(await section.locator('[data-session-catalog-host="node:build"]').count()).toBe(1);
165186
expect(await section.getByText("Offline Workstation", { exact: true }).count()).toBe(0);
166187
expect(await section.getByText("Offline Laptop", { exact: true }).count()).toBe(0);
188+
const projectHeads = section.locator("[data-session-catalog-project]");
189+
await expect.poll(() => projectHeads.count()).toBe(2);
190+
const openclawProject = section.locator(
191+
'[data-session-catalog-project="/Users/dev/openclaw"]',
192+
);
193+
expect(
194+
await openclawProject.locator(".sidebar-session-catalog-project__label").textContent(),
195+
).toBe("openclaw");
196+
expect(
197+
await openclawProject.locator(".sidebar-session-catalog-project__count").textContent(),
198+
).toBe("2");
199+
expect(
200+
await section
201+
.locator('[data-session-catalog-project="/Users/dev/other"]')
202+
.locator(".sidebar-session-catalog-project__label")
203+
.textContent(),
204+
).toBe("other");
205+
expect(await section.getByText("Worktree fix session", { exact: true }).count()).toBe(1);
167206
const toggle = section.locator(".sidebar-session-group-toggle");
168207
expect(await toggle.getAttribute("title")).toBeNull();
169208
await expect
170209
.poll(() => section.locator(".sidebar-session-group-count").textContent())
171-
.toBe("2");
210+
.toBe("4");
211+
212+
const groupingToggle = section.locator('[data-session-catalog-grouping-toggle="codex"]');
213+
await groupingToggle.click();
214+
await expect.poll(() => projectHeads.count()).toBe(0);
215+
expect(await section.locator("[data-session-key]").count()).toBe(4);
216+
expect(
217+
await page.evaluate((key) => localStorage.getItem(key), catalogGroupingStorageKey),
218+
).toBe("none");
219+
if (captureUiProofEnabled) {
220+
await mkdir(uiProofArtifactDir, { recursive: true });
221+
await section.screenshot({
222+
animations: "disabled",
223+
path: path.join(uiProofArtifactDir, "04-flat-session-hosts.png"),
224+
});
225+
}
226+
227+
await groupingToggle.click();
228+
await expect.poll(() => projectHeads.count()).toBe(2);
229+
expect(
230+
await page.evaluate((key) => localStorage.getItem(key), catalogGroupingStorageKey),
231+
).toBe("project");
172232

173233
if (captureUiProofEnabled) {
174234
await mkdir(uiProofArtifactDir, { recursive: true });

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,6 +3626,7 @@ export const en: TranslationMap = {
36263626
updateGateway: "Update Gateway",
36273627
allSessions: "All sessions",
36283628
chats: "Chats",
3629+
groupCatalogSessionsByProject: "Group by project",
36293630
openSessionMenu: "Open session menu",
36303631
sortBy: "Sort by",
36313632
sortCreated: "Created",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { SessionCatalogSession } from "../../../../packages/gateway-protocol/src/index.ts";
3+
import {
4+
groupCatalogSessionsByProject,
5+
normalizeCatalogProjectGrouping,
6+
} from "./catalog-project-grouping.ts";
7+
8+
describe("normalizeCatalogProjectGrouping", () => {
9+
it.each([
10+
["project", "project"],
11+
["none", "none"],
12+
[undefined, "project"],
13+
[null, "project"],
14+
["garbage", "project"],
15+
] as const)("normalizes %s to %s", (raw, expected) => {
16+
expect(normalizeCatalogProjectGrouping(raw)).toBe(expected);
17+
});
18+
});
19+
20+
describe("groupCatalogSessionsByProject", () => {
21+
it("groups distinct cwd values and preserves first-occurrence and session order", () => {
22+
const result = groupCatalogSessionsByProject([
23+
session("b-1", "/work/bravo"),
24+
session("a-1", "/work/alpha"),
25+
session("b-2", "/work/bravo"),
26+
]);
27+
28+
expect(result.groups.map((group) => group.key)).toEqual(["/work/bravo", "/work/alpha"]);
29+
expect(result.groups.map((group) => group.label)).toEqual(["bravo", "alpha"]);
30+
expect(result.groups[0]?.sessions.map((item) => item.threadId)).toEqual(["b-1", "b-2"]);
31+
});
32+
33+
it.each([
34+
["/Users/dev/openclaw/.claude/worktrees/fix-1", "/Users/dev/openclaw"],
35+
["/Users/dev/openclaw/.claude/worktrees/fix-1/ui/src", "/Users/dev/openclaw"],
36+
["C:\\Users\\dev\\openclaw\\.claude\\worktrees\\fix-1", "C:\\Users\\dev\\openclaw"],
37+
])("folds worktree cwd %s into %s", (worktreeCwd, expectedProject) => {
38+
const result = groupCatalogSessionsByProject([
39+
session("direct", expectedProject),
40+
session("worktree", worktreeCwd),
41+
]);
42+
43+
expect(result.groups).toHaveLength(1);
44+
expect(result.groups[0]?.key).toBe(expectedProject);
45+
expect(result.groups[0]?.sessions.map((item) => item.threadId)).toEqual(["direct", "worktree"]);
46+
});
47+
48+
it("leaves missing and blank cwd values ungrouped", () => {
49+
const result = groupCatalogSessionsByProject([
50+
session("missing"),
51+
session("blank", " "),
52+
session("grouped", "/work/project"),
53+
]);
54+
55+
expect(result.ungrouped.map((item) => item.threadId)).toEqual(["missing", "blank"]);
56+
});
57+
58+
it.each([
59+
[" /Users/dev/openclaw/// ", "/Users/dev/openclaw", "openclaw"],
60+
["C:\\Users\\dev\\openclaw\\", "C:\\Users\\dev\\openclaw", "openclaw"],
61+
])("normalizes %s to key %s with label %s", (cwd, expectedKey, expectedLabel) => {
62+
const result = groupCatalogSessionsByProject([session("one", cwd)]);
63+
64+
expect(result.groups[0]).toMatchObject({
65+
key: expectedKey,
66+
label: expectedLabel,
67+
title: expectedKey,
68+
});
69+
});
70+
});
71+
72+
function session(threadId: string, cwd?: string): SessionCatalogSession {
73+
return {
74+
threadId,
75+
cwd,
76+
status: "idle",
77+
archived: false,
78+
canContinue: true,
79+
canArchive: true,
80+
};
81+
}

0 commit comments

Comments
 (0)