Skip to content

Commit c5d4a82

Browse files
authored
feat(ui): show session info in the sidebar hovercard (#125678)
* feat(ui): show session info in the sidebar hovercard The sidebar session hovercard now always opens and shows owner, created and updated times, PR chips with CI state and diff stats, plus a branch and changed-files fallback with “No PR yet”. The progress card renders below when present, and the gateway exposes changedFiles on session PR and branch snapshots. * fix(ui): scope session hovercards to sidebar rows Keep Markdown session links owned by their dedicated preview hovercard by limiting both lazy registration and runtime activation to sidebar session rows. Add browser coverage that fails when the competing sidebar hovercard steals the link trigger. * perf(ui): keep session hovercard data out of startup Reuse the sidebar’s existing session projection from the lazy hovercard runtime instead of publishing a separate startup-loaded registry. This removes the registry lifecycle and its implementation-only tests while keeping the browser ownership regression and restoring the Control UI startup bundle below budget.
1 parent 5fa137e commit c5d4a82

12 files changed

Lines changed: 1007 additions & 38 deletions

‎src/gateway/control-ui-contract.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export type ControlUiSessionPullRequest = {
124124
state: "open" | "draft" | "merged" | "closed";
125125
additions?: number;
126126
deletions?: number;
127+
changedFiles?: number;
127128
/** Latest check-run rollup for the head commit; absent when no checks ran. */
128129
checks?: ControlUiSessionPullRequestChecks;
129130
checksUrl?: string;
@@ -140,6 +141,7 @@ export type ControlUiSessionBranch = {
140141
/** Working-tree diff vs the merge base with the remote default branch. */
141142
additions?: number;
142143
deletions?: number;
144+
changedFiles?: number;
143145
/**
144146
* GitHub "open a pull request for this branch" page. Absent while the
145147
* branch is unpushed or has nothing to compare — the row then only reports

‎src/gateway/control-ui-session-prs-branch.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ describe("session branch diff stats", () => {
152152
branch: "feature",
153153
additions: 4,
154154
deletions: 1,
155+
changedFiles: 3,
155156
createUrl: "https://github.com/openclaw/openclaw/pull/new/feature",
156157
});
157158
});
@@ -191,6 +192,7 @@ describe("session branch diff stats", () => {
191192
branch: "feature",
192193
additions: 1,
193194
deletions: 0,
195+
changedFiles: 1,
194196
});
195197
});
196198

@@ -207,6 +209,7 @@ describe("session branch diff stats", () => {
207209
branch: "feature",
208210
additions: 1,
209211
deletions: 0,
212+
changedFiles: 1,
210213
});
211214
});
212215

@@ -231,6 +234,7 @@ describe("session branch diff stats", () => {
231234
branch: "feature",
232235
additions: 1,
233236
deletions: 0,
237+
changedFiles: 1,
234238
});
235239
});
236240

@@ -286,6 +290,7 @@ describe("session branch diff stats", () => {
286290
branch: "feature",
287291
additions: 1,
288292
deletions: 0,
293+
changedFiles: 1,
289294
createUrl: "https://github.com/openclaw/openclaw/pull/new/feature",
290295
});
291296
});
@@ -326,6 +331,7 @@ describe("session branch diff stats", () => {
326331
branch: "feature",
327332
additions: 1,
328333
deletions: 0,
334+
changedFiles: 1,
329335
createUrl: "https://github.com/openclaw/openclaw/pull/new/feature",
330336
});
331337
});
@@ -366,6 +372,7 @@ describe("session branch diff stats", () => {
366372
branch: "feature",
367373
additions: 1,
368374
deletions: 0,
375+
changedFiles: 1,
369376
});
370377
});
371378

@@ -426,6 +433,7 @@ describe("session branch diff stats", () => {
426433
branch: "feature",
427434
additions: 1,
428435
deletions: 0,
436+
changedFiles: 1,
429437
});
430438
});
431439

‎src/gateway/control-ui-session-prs.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("loadControlUiSessionPullRequests", () => {
5050
{ match: "/pulls?head=", response: () => githubJson([pullListItem()]) },
5151
{
5252
match: "/pulls/103469",
53-
response: () => githubJson({ additions: 4, deletions: 3 }),
53+
response: () => githubJson({ additions: 4, deletions: 3, changed_files: 2 }),
5454
},
5555
{
5656
match: "/check-runs",
@@ -81,6 +81,7 @@ describe("loadControlUiSessionPullRequests", () => {
8181
state: "open",
8282
additions: 4,
8383
deletions: 3,
84+
changedFiles: 2,
8485
checks: { state: "passing", passed: 1, failed: 0, skipped: 1, running: 0 },
8586
checksUrl: "https://github.com/openclaw/openclaw/pull/103469/checks",
8687
},

‎src/gateway/control-ui-session-prs.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,13 @@ async function resolveSessionBranch(
312312
repo: context.repo,
313313
branch: context.branch,
314314
...(facts.creatable ? { createUrl: branchCreateUrl(context) } : {}),
315-
...(facts.stats ? { additions: facts.stats.additions, deletions: facts.stats.deletions } : {}),
315+
...(facts.stats
316+
? {
317+
additions: facts.stats.additions,
318+
deletions: facts.stats.deletions,
319+
changedFiles: facts.stats.changedFiles,
320+
}
321+
: {}),
316322
};
317323
}
318324

@@ -399,7 +405,7 @@ async function fetchDiffCounts(
399405
item: PullListItem,
400406
fetchImpl: typeof fetch,
401407
token: string | undefined,
402-
): Promise<{ additions?: number; deletions?: number }> {
408+
): Promise<{ additions?: number; deletions?: number; changedFiles?: number }> {
403409
const url = `${GITHUB_API_ORIGIN}/repos/${encodeURIComponent(item.owner)}/${encodeURIComponent(item.repo)}/pulls/${item.number}`;
404410
try {
405411
const value = await fetchGitHubJson(url, fetchImpl, token);
@@ -409,6 +415,7 @@ async function fetchDiffCounts(
409415
return {
410416
additions: optionalNumber(value, "additions"),
411417
deletions: optionalNumber(value, "deletions"),
418+
changedFiles: optionalNumber(value, "changed_files"),
412419
};
413420
} catch (error) {
414421
rethrowRateLimit(error);
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { render } from "lit";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+
import type { ControlUiSessionPullRequestSnapshot } from "../../../src/gateway/control-ui-contract.js";
6+
import type { SidebarRecentSession } from "./app-sidebar-session-types.ts";
7+
import { renderSessionHovercard } from "./session-hovercard.ts";
8+
9+
function row(overrides: Partial<SidebarRecentSession> = {}): SidebarRecentSession {
10+
return {
11+
key: "agent:main:work",
12+
label: "Ship the release",
13+
startedAt: Date.now() - 2 * 60 * 60_000,
14+
updatedAt: Date.now() - 5 * 60_000,
15+
owner: {
16+
actor: { type: "human", id: "alice", label: "Alice Baker" },
17+
},
18+
children: [],
19+
...overrides,
20+
} as SidebarRecentSession;
21+
}
22+
23+
function snapshot(
24+
overrides: Partial<ControlUiSessionPullRequestSnapshot> = {},
25+
): ControlUiSessionPullRequestSnapshot {
26+
return {
27+
status: "ready",
28+
pullRequests: [],
29+
rateLimited: false,
30+
...overrides,
31+
};
32+
}
33+
34+
describe("renderSessionHovercard", () => {
35+
beforeEach(() => {
36+
vi.useFakeTimers();
37+
vi.setSystemTime(new Date("2026-08-17T12:00:00Z"));
38+
});
39+
40+
afterEach(() => {
41+
vi.useRealTimers();
42+
});
43+
44+
it("renders synchronous row metadata without inventing a progress section", () => {
45+
const container = document.createElement("div");
46+
render(renderSessionHovercard({ row: row() }), container);
47+
48+
expect(container.querySelector(".session-hovercard__title")?.textContent).toBe(
49+
"Ship the release",
50+
);
51+
expect(container.querySelector(".session-hovercard__avatar")?.textContent).toBe("AB");
52+
const metadata = container.querySelector(".session-hovercard__meta")?.textContent ?? "";
53+
expect(metadata).toContain("Alice Baker");
54+
expect(metadata).toContain("created");
55+
expect(metadata).toContain("updated");
56+
expect(container.querySelector(".session-progress-card")).toBeNull();
57+
expect(container.querySelector(".session-hovercard__divider")).toBeNull();
58+
});
59+
60+
it("renders bounded linked PR chips with state, CI, and diff facts", () => {
61+
const container = document.createElement("div");
62+
render(
63+
renderSessionHovercard({
64+
pullRequests: snapshot({
65+
pullRequests: [
66+
{
67+
number: 101,
68+
owner: "openclaw",
69+
repo: "openclaw",
70+
branch: "feature",
71+
title: "First",
72+
url: "https://github.com/openclaw/openclaw/pull/101",
73+
state: "open",
74+
changedFiles: 2,
75+
additions: 7,
76+
deletions: 3,
77+
checks: { state: "passing", passed: 2, failed: 0, skipped: 0, running: 0 },
78+
},
79+
{
80+
number: 102,
81+
owner: "openclaw",
82+
repo: "openclaw",
83+
branch: "feature",
84+
title: "Second",
85+
url: "https://github.com/openclaw/openclaw/pull/102",
86+
state: "draft",
87+
},
88+
{
89+
number: 103,
90+
owner: "openclaw",
91+
repo: "openclaw",
92+
branch: "feature",
93+
title: "Third",
94+
url: "https://github.com/openclaw/openclaw/pull/103",
95+
state: "merged",
96+
},
97+
{
98+
number: 104,
99+
owner: "openclaw",
100+
repo: "openclaw",
101+
branch: "feature",
102+
title: "Fourth",
103+
url: "https://github.com/openclaw/openclaw/pull/104",
104+
state: "closed",
105+
},
106+
],
107+
}),
108+
}),
109+
container,
110+
);
111+
112+
const links = [...container.querySelectorAll<HTMLAnchorElement>(".session-hovercard__pr-chip")];
113+
expect(links).toHaveLength(3);
114+
expect(links[0]?.href).toBe("https://github.com/openclaw/openclaw/pull/101");
115+
expect(links[0]?.target).toBe("_blank");
116+
expect(links[0]?.rel).toContain("noopener");
117+
expect(links[0]?.querySelector(".session-hovercard__pr-number")?.textContent).toBe("#101");
118+
expect(links[0]?.querySelector(".session-hovercard__pr-state")?.textContent).toBe("Open");
119+
expect(links[0]?.querySelector("[data-checks='passing']")?.textContent).toBe("✓");
120+
expect(links[0]?.querySelector(".session-hovercard__files")?.textContent).toBe("2 files");
121+
expect(links[0]?.querySelector(".session-hovercard__additions")?.textContent).toBe("+7");
122+
expect(links[0]?.querySelector(".session-hovercard__deletions")?.textContent).toBe("−3");
123+
expect(container.querySelector(".session-hovercard__more")?.textContent).toBe("+1 more");
124+
});
125+
126+
it("falls back to branch and diff chips with a create-PR link", () => {
127+
const container = document.createElement("div");
128+
render(
129+
renderSessionHovercard({
130+
row: row({ workSession: true, subtitle: "openclaw/openclaw · feature" }),
131+
pullRequests: snapshot({
132+
branch: {
133+
owner: "openclaw",
134+
repo: "openclaw",
135+
branch: "feature",
136+
changedFiles: 3,
137+
additions: 12,
138+
deletions: 4,
139+
createUrl: "https://github.com/openclaw/openclaw/pull/new/feature",
140+
},
141+
}),
142+
}),
143+
container,
144+
);
145+
146+
expect(container.querySelector(".session-hovercard__branch-chip")?.textContent).toBe(
147+
"openclaw/openclaw · feature",
148+
);
149+
expect(container.querySelector(".session-hovercard__files")?.textContent).toBe("3 files");
150+
expect(container.querySelector(".session-hovercard__additions")?.textContent).toBe("+12");
151+
expect(container.querySelector(".session-hovercard__deletions")?.textContent).toBe("−4");
152+
const createLink = container.querySelector<HTMLAnchorElement>(".session-hovercard__no-pr a");
153+
expect(createLink?.textContent).toBe("No PR yet");
154+
expect(createLink?.href).toBe("https://github.com/openclaw/openclaw/pull/new/feature");
155+
});
156+
});

0 commit comments

Comments
 (0)