Skip to content

Commit da7a2b4

Browse files
authored
fix(ui): show session attention on Home (#123759)
* fix(ui): show main-session attention on Home * refactor(ui): keep Home attention boundary private
1 parent 17eb646 commit da7a2b4

7 files changed

Lines changed: 279 additions & 46 deletions

File tree

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
type SidebarZoneEntry,
77
} from "../app-navigation.ts";
88
import { isSessionRouteId } from "../app-route-paths.ts";
9-
import { sessionHasPendingApproval } from "../app/approval-presentation.ts";
109
import { resolveControlUiAuthToken } from "../app/control-ui-auth.ts";
1110
import { isNativeWebChromeHost } from "../app/native-web-chrome.ts";
1211
import { readPresenceEntries, resolveCurrentSelfUser } from "../app/user-profile.ts";
@@ -31,6 +30,10 @@ import type { AppSidebarSessionNavigationElement } from "./app-sidebar-session-n
3130
import type { SidebarRecentSession } from "./app-sidebar-session-types.ts";
3231
import type { SidebarWorkboardBoard } from "./app-sidebar-workboard.ts";
3332
import { icons } from "./icons.ts";
33+
import {
34+
renderSessionAttentionIcon,
35+
sessionAttentionSubtitle,
36+
} from "./session-attention-presentation.ts";
3437
import { renderSessionGlyph, renderSessionUnreadBadge } from "./session-glyph.ts";
3538
import { renderSessionRowBadges } from "./session-row-badges.ts";
3639
import { formatSidebarBuildSubtitle } from "./sidebar-build-chip-format.ts";
@@ -156,21 +159,21 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
156159
const agentId = host.activeChipAgent().activeId;
157160
const mainKey = host.selectedAgentMainSessionKey(agentId);
158161
const mainRow = host.mainSessionRow(agentId);
159-
const approvalNeeded = sessionHasPendingApproval(
160-
host.sessionData.approvalBadgeSnapshot(),
161-
mainKey,
162-
);
163-
const outboxCount = host.outboxCountForSessionKey(mainKey);
162+
const attention = host.resolveHomeSessionAttention(mainKey, mainRow);
163+
const attentionLabel = sessionAttentionSubtitle(attention);
164+
const outboxCount = host.outboxCountForSession(mainKey);
164165
const active =
165166
isSessionRouteId(host.activeRouteId) &&
166167
areUiSessionKeysEquivalent(host.getRouteSessionKey(), mainKey);
167168
const hasComposerDraft = !active && host.hasSessionDraft(mainKey);
168169
const running = mainRow?.hasActiveRun === true;
169170
const unread = mainRow?.unread === true && !active;
170-
// Home shares the sidebar's leading-slot contract: run state rings its icon
171-
// instead of drifting to the row edge, which stays reserved for counts.
171+
// Home rings run state around its leading icon; the trailing slot stays reserved for counts.
172172
const homeGlyph = renderSessionGlyph({
173-
content: html`<span class="nav-item__icon" aria-hidden="true">${icons.home}</span>`,
173+
content:
174+
attention.kind === "none"
175+
? html`<span class="nav-item__icon" aria-hidden="true">${icons.home}</span>`
176+
: renderSessionAttentionIcon(attention),
174177
running,
175178
badge: unread ? renderSessionUnreadBadge() : nothing,
176179
});
@@ -186,6 +189,7 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
186189
preferenceDerivedFace: true,
187190
}).href}
188191
class="nav-item nav-item--home ${active ? "nav-item--active" : ""}"
192+
aria-label=${attentionLabel ? `${t("nav.home")} · ${attentionLabel}` : nothing}
189193
aria-current=${active ? "page" : nothing}
190194
@click=${(event: MouseEvent) => {
191195
if (!shouldHandleNavigationClick(event)) {
@@ -195,8 +199,8 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
195199
host.openMainSession(agentId);
196200
}}
197201
>
198-
${running
199-
? html`<openclaw-tooltip .content=${t("sessionsView.activeRun")}
202+
${attentionLabel || running
203+
? html`<openclaw-tooltip .content=${attentionLabel ?? t("sessionsView.activeRun")}
200204
>${homeGlyph}</openclaw-tooltip
201205
>`
202206
: homeGlyph}
@@ -211,18 +215,8 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
211215
>
212216
</openclaw-tooltip>`
213217
: nothing}
214-
${approvalNeeded || outboxCount > 0 || hasComposerDraft
218+
${outboxCount > 0 || hasComposerDraft
215219
? html`<span class="nav-item__state sidebar-home-session-states">
216-
${approvalNeeded
217-
? html`<openclaw-tooltip .content=${t("sessionsView.approvalNeeded")}>
218-
<span
219-
class="session-approval-badge"
220-
role="img"
221-
aria-label=${t("sessionsView.approvalNeeded")}
222-
>${icons.alertTriangle}</span
223-
>
224-
</openclaw-tooltip>`
225-
: nothing}
226220
${renderSessionRowBadges({ hasAutomation: false, outboxCount, hasComposerDraft })}
227221
</span>`
228222
: nothing}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
22
import type { GatewaySessionRow, SessionsListResult } from "../api/types.ts";
3-
import { SIDEBAR_NAV_ROUTES } from "../app-navigation.ts";
4-
import type { NavigationRouteId } from "../app-navigation.ts";
3+
import { SIDEBAR_NAV_ROUTES, type NavigationRouteId } from "../app-navigation.ts";
54
import type { RouteId } from "../app-route-paths.ts";
65
import type { ApplicationContext } from "../app/context.ts";
76
import { t } from "../i18n/index.ts";
@@ -49,6 +48,7 @@ import {
4948
} from "./app-sidebar-session-types.ts";
5049
import type { SidebarWorkboardBoard } from "./app-sidebar-workboard.ts";
5150
import { resolveCloudWorkerStopAction } from "./cloud-worker-stop.ts";
51+
import type { SessionAttentionController } from "./session-attention-controller.ts";
5252
import {
5353
listSessionCreators,
5454
type SessionCreatedActor,
@@ -57,6 +57,20 @@ import {
5757

5858
type SessionRow = SessionsListResult["sessions"][number];
5959

60+
export function resolveSidebarHomeAttention(
61+
attention: SessionAttentionController,
62+
sessionKey: string,
63+
row: GatewaySessionRow | null,
64+
) {
65+
const known = attention
66+
.knownSessionAttention()
67+
.find((entry) => areUiSessionKeysEquivalent(entry.sessionKey, sessionKey));
68+
return (
69+
known?.attention ??
70+
(row ? attention.resolveSessionAttention(row) : SIDEBAR_SESSION_NO_ATTENTION)
71+
);
72+
}
73+
6074
export function compareSidebarSessionRowsByMode(input: {
6175
a: SessionRow;
6276
b: SessionRow;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
partitionSidebarVisibleSections,
4343
promoteSidebarSessionCreatedOrder,
4444
resolveSidebarAgentChipSubtitle,
45+
resolveSidebarHomeAttention,
4546
resolveSidebarAgentResumeKey,
4647
resolveSidebarMainSessionKey,
4748
toggleSidebarSessionSelection,
@@ -272,10 +273,6 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
272273
);
273274
}
274275

275-
outboxCountForSessionKey(sessionKey: string): number {
276-
return this.outboxCountForSession(sessionKey);
277-
}
278-
279276
getSessionNavigationState(): SidebarSessionNavigationState {
280277
const routeSessionKey = this.getRouteSessionKey();
281278
return buildSidebarSessionNavigationState({
@@ -291,7 +288,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
291288
highlightCurrentSession: isSessionRouteId(this.activeRouteId),
292289
runtimeSampledAtByRow: this.runtimeSampledAtByRow,
293290
loadingChildSessionKeys: this.sessionData.loadingChildSessionKeys,
294-
outboxCountForSessionKey: (sessionKey) => this.outboxCountForSessionKey(sessionKey),
291+
outboxCountForSessionKey: (sessionKey) => this.outboxCountForSession(sessionKey),
295292
hasSessionDraft: (sessionKey) => this.hasSessionDraft(sessionKey),
296293
resolveAttention: (row) => this.attention.resolveSessionAttention(row),
297294
resolveAgentStatusNote: (row) => this.attention.resolveSessionAgentStatus(row)?.note,
@@ -725,6 +722,10 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
725722
});
726723
}
727724

725+
resolveHomeSessionAttention(sessionKey: string, row: GatewaySessionRow | null) {
726+
return resolveSidebarHomeAttention(this.attention, sessionKey, row);
727+
}
728+
728729
/** Gateway row backing the identity card (unread/running state), if loaded. */
729730
mainSessionRow(agentId?: string): GatewaySessionRow | null {
730731
const normalized = normalizeAgentId(agentId ?? this.expandedAgentId());
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import { mkdir } from "node:fs/promises";
2+
import path from "node:path";
3+
import type { QuestionRecord } from "@openclaw/gateway-protocol";
4+
import { expect, it } from "vitest";
5+
import type { GatewaySessionRow, SessionsListResult } from "../api/types.ts";
6+
import {
7+
controlUiSessionUrl,
8+
installMockGateway,
9+
type MockGatewayControls,
10+
} from "../test-helpers/control-ui-e2e.ts";
11+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
12+
13+
const suite = createControlUiE2eSuite({
14+
name: "Control UI Home attention",
15+
startServerBeforeBrowser: true,
16+
trackBrowserContexts: true,
17+
unavailableMessage: (executablePath) =>
18+
`Playwright Chromium is not available at ${executablePath}`,
19+
});
20+
21+
const mainSessionKey = "agent:main:main";
22+
const captureUiProof = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
23+
const proofVariant = process.env.OPENCLAW_HOME_ATTENTION_PROOF_VARIANT || "candidate";
24+
const proofDir = path.join(
25+
process.cwd(),
26+
".artifacts",
27+
"control-ui-e2e",
28+
"home-attention",
29+
proofVariant,
30+
);
31+
32+
function sessionsList(row: GatewaySessionRow): SessionsListResult {
33+
return {
34+
ts: Date.now(),
35+
path: "",
36+
count: 1,
37+
defaults: { modelProvider: "openai", model: "gpt-5.6-luna", contextTokens: null },
38+
sessions: [row],
39+
};
40+
}
41+
42+
function sessionRow(overrides: Partial<GatewaySessionRow> = {}): GatewaySessionRow {
43+
return {
44+
key: mainSessionKey,
45+
kind: "direct",
46+
label: "Home",
47+
displayName: "Quiet control state",
48+
updatedAt: Date.now(),
49+
status: "done",
50+
...overrides,
51+
};
52+
}
53+
54+
async function publishSessionRow(
55+
gateway: MockGatewayControls,
56+
row: GatewaySessionRow,
57+
): Promise<void> {
58+
await gateway.setMethodResponse("sessions.list", sessionsList(row));
59+
const requestCount = (await gateway.getRequests("sessions.list")).length;
60+
await gateway.emitGatewayEvent("sessions.changed", {
61+
key: row.key,
62+
reason: "home-attention-proof",
63+
updatedAt: row.updatedAt,
64+
});
65+
await expect
66+
.poll(async () => (await gateway.getRequests("sessions.list")).length)
67+
.toBeGreaterThan(requestCount);
68+
}
69+
70+
async function captureState(
71+
page: import("playwright").Page,
72+
home: import("playwright").Locator,
73+
name: string,
74+
): Promise<number> {
75+
await page.evaluate(
76+
() =>
77+
new Promise<void>((resolve) => {
78+
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
79+
}),
80+
);
81+
if (captureUiProof) {
82+
await page.screenshot({
83+
animations: "disabled",
84+
fullPage: true,
85+
path: path.join(proofDir, `${name}.png`),
86+
});
87+
}
88+
return home.locator("[data-session-attention]").count();
89+
}
90+
91+
suite.define(() => {
92+
it("projects question, failure, and agent-declared attention onto Home", async () => {
93+
if (captureUiProof) {
94+
await mkdir(proofDir, { recursive: true });
95+
}
96+
const context = await suite.newBrowserContext({
97+
locale: "en-US",
98+
serviceWorkers: "block",
99+
viewport: { height: 900, width: 1280 },
100+
...(captureUiProof
101+
? { recordVideo: { dir: proofDir, size: { height: 900, width: 1280 } } }
102+
: {}),
103+
});
104+
const page = await context.newPage();
105+
const gateway = await installMockGateway(page, {
106+
featureMethods: ["question.get", "question.list", "question.resolve"],
107+
methodResponses: {
108+
"question.list": { questions: [] },
109+
"sessions.list": sessionsList(sessionRow()),
110+
},
111+
sessionKey: mainSessionKey,
112+
});
113+
114+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, mainSessionKey));
115+
await gateway.waitForRequest("sessions.list");
116+
const home = page.locator(".nav-item--home");
117+
await home.waitFor();
118+
const observed = {
119+
quiet: await captureState(page, home, "00-non-attention"),
120+
agent: 0,
121+
question: 0,
122+
error: 0,
123+
};
124+
125+
await publishSessionRow(
126+
gateway,
127+
sessionRow({
128+
displayName: "Declared attention state",
129+
status: "running",
130+
hasActiveRun: true,
131+
agentStatus: {
132+
note: "Blocked: operator input required",
133+
attention: "flag",
134+
expiresAt: Date.now() + 60_000,
135+
},
136+
}),
137+
);
138+
observed.agent = await captureState(page, home, "01-agent-declared-attention");
139+
140+
const now = Date.now();
141+
const question = {
142+
id: "home-attention-question",
143+
agentId: "main",
144+
sessionKey: mainSessionKey,
145+
questions: [
146+
{
147+
questionId: "continue_run",
148+
header: "Continue",
149+
question: "Should the run continue?",
150+
options: [{ label: "Continue", description: "Resume the waiting run." }],
151+
},
152+
],
153+
createdAtMs: now,
154+
expiresAtMs: now + 60_000,
155+
status: "pending",
156+
} satisfies QuestionRecord;
157+
await gateway.emitGatewayEvent("question.requested", question);
158+
await page.getByText("Should the run continue?", { exact: true }).waitFor();
159+
observed.question = await captureState(page, home, "02-question-attention");
160+
161+
await gateway.emitGatewayEvent("question.resolved", {
162+
id: question.id,
163+
status: "cancelled",
164+
});
165+
await expect
166+
.poll(() => page.getByText("Should the run continue?", { exact: true }).count())
167+
.toBe(0);
168+
await publishSessionRow(
169+
gateway,
170+
sessionRow({
171+
displayName: "Failed run state",
172+
endedAt: Date.now(),
173+
lastRunError: "Release validation failed",
174+
status: "failed",
175+
}),
176+
);
177+
observed.error = await captureState(page, home, "03-failed-run-attention");
178+
179+
expect(observed).toEqual({ quiet: 0, agent: 1, question: 1, error: 1 });
180+
});
181+
});

‎ui/src/styles/components.css‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,20 +5630,12 @@ td.data-table-key-col {
56305630
color: var(--accent);
56315631
}
56325632

5633-
.session-row-badge--approval,
5634-
.session-approval-badge {
5633+
.session-row-badge--approval {
56355634
display: inline-flex;
56365635
align-items: center;
56375636
color: var(--warn);
56385637
}
56395638

5640-
.session-approval-badge svg {
5641-
width: 13px;
5642-
height: 13px;
5643-
stroke: currentColor;
5644-
fill: none;
5645-
}
5646-
56475639
.session-row-badge--cloud[data-placement-state="failed"] {
56485640
color: var(--danger);
56495641
}

‎ui/src/styles/layout.css‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,8 +3151,7 @@ wa-dropdown-item.session-menu__item::part(submenu-icon) {
31513151
stroke-linejoin: round;
31523152
}
31533153

3154-
/* Home carries approval and outbox counts at the row's edge; run/unread state
3155-
rings the leading icon instead (see .session-glyph). */
3154+
/* Home keeps outbox/draft counts at the edge; run/unread rings the leading icon. */
31563155
.nav-item__state {
31573156
flex: none;
31583157
margin-left: auto;

0 commit comments

Comments
 (0)