Skip to content

Commit df9b7a5

Browse files
authored
fix(ui): show accessible last activity on session progress cards (#129520)
* fix(ui): show accessible last activity on session progress cards * fix(ui): validate progress activity timestamps at ingress
1 parent d205216 commit df9b7a5

7 files changed

Lines changed: 180 additions & 25 deletions

File tree

‎docs/tools/progress-card.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ The current chat shows exactly one live card:
9090
- At narrower widths the card appears in the collapsible surface inside the composer.
9191

9292
The placements are mutually exclusive. Hover a session row in the sidebar or a session-reference link in chat to see the same card for that session. All card placements read the same Gateway-backed state and refresh after `progressCard.changed` notifications.
93+
Each placement shows the local time of the last progress update, including seconds.
9394

9495
## Pin the card to the dashboard
9596

‎ui/src/components/session-progress-card.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,38 @@ const progressCard: ProgressCard = {
1818
};
1919

2020
describe("renderSessionProgressCard", () => {
21+
it.each(["board", "composer", "dock", "hovercard", "rail"] as const)(
22+
"shows the last activity time for %s cards with and without checklist steps",
23+
(placement) => {
24+
const container = document.createElement("div");
25+
26+
for (const steps of [progressCard.steps, undefined]) {
27+
render(renderSessionProgressCard({ ...progressCard, steps }, placement), container);
28+
29+
const timestamp = container.querySelector(".session-progress-card time");
30+
expect(timestamp?.getAttribute("datetime")).toBe(
31+
new Date(progressCard.updatedAt).toISOString(),
32+
);
33+
expect(timestamp?.textContent).toMatch(/\d{1,2}:\d{2}:\d{2}/);
34+
expect(timestamp?.getAttribute("aria-label")).toMatch(/^Last activity: /);
35+
expect(timestamp?.getAttribute("title")).toBe(timestamp?.getAttribute("aria-label"));
36+
const accessibleCard =
37+
placement === "composer"
38+
? timestamp?.closest("summary")
39+
: timestamp?.closest(".session-progress-card");
40+
expect(accessibleCard?.getAttribute("aria-label")).toContain(
41+
timestamp?.getAttribute("aria-label"),
42+
);
43+
}
44+
},
45+
);
46+
2147
it("renders sanitized markdown and one accessible typed checklist", () => {
2248
const container = document.createElement("div");
2349
render(renderSessionProgressCard(progressCard, "rail"), container);
2450

2551
const card = container.querySelector(".session-progress-card");
26-
expect(card?.getAttribute("aria-label")).toBe("1 of 3 completed");
52+
expect(card?.getAttribute("aria-label")).toMatch(/^1 of 3 completed\. Last activity: /);
2753
expect(card?.querySelector("strong")?.textContent).toBe("Focused change");
2854
expect(card?.querySelector("progress")?.getAttribute("value")).toBe("1");
2955
expect(card?.querySelectorAll(".session-progress-card__count")).toHaveLength(0);

‎ui/src/components/session-progress-card.ts‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ProgressCard, ProgressCardStep } from "@openclaw/gateway-protocol"
22
import { html, nothing } from "lit";
33
import { unsafeHTML } from "lit/directives/unsafe-html.js";
44
import { t } from "../i18n/index.ts";
5+
import { formatTimeMs } from "../lib/format.ts";
56
import { icons } from "./icons.ts";
67
import { toSanitizedMarkdownHtml } from "./markdown.ts";
78

@@ -98,6 +99,19 @@ export function renderSessionProgressCard(
9899
total: String(counts.total),
99100
})
100101
: t("sessionProgressCard.noteLabel");
102+
const activityTime = formatTimeMs(card.updatedAt, {
103+
hour: "numeric",
104+
minute: "2-digit",
105+
second: "2-digit",
106+
});
107+
const activityLabel = t("sessionProgressCard.lastActivity", { time: activityTime });
108+
const accessibleLabel = `${countLabel}. ${activityLabel}`;
109+
const lastActivity = html`<time
110+
datetime=${new Date(card.updatedAt).toISOString()}
111+
aria-label=${activityLabel}
112+
title=${activityLabel}
113+
>${activityTime}</time
114+
>`;
101115
const dismissible = Boolean(
102116
onDismiss && card.steps?.length && card.steps.every((step) => step.status === "completed"),
103117
);
@@ -123,7 +137,7 @@ export function renderSessionProgressCard(
123137
class="session-progress-card session-progress-card--composer"
124138
data-progress-card-placement="composer"
125139
>
126-
<summary class="session-progress-card__summary" aria-label=${countLabel}>
140+
<summary class="session-progress-card__summary" aria-label=${accessibleLabel}>
127141
<span
128142
class="session-progress-card__current-marker"
129143
data-status=${currentStatus}
@@ -133,11 +147,9 @@ export function renderSessionProgressCard(
133147
<span class="session-progress-card__current"
134148
>${current?.step ?? t("sessionProgressCard.noteLabel")}</span
135149
>
136-
${counts
137-
? html`<span class="session-progress-card__count"
138-
>${counts.completed}/${counts.total}</span
139-
>`
140-
: nothing}
150+
<span class="session-progress-card__count"
151+
>${counts ? html`${counts.completed}/${counts.total} · ` : nothing}${lastActivity}</span
152+
>
141153
${dismiss}
142154
<span class="session-progress-card__chevron" aria-hidden="true">${icons.chevronDown}</span>
143155
</summary>
@@ -147,17 +159,15 @@ export function renderSessionProgressCard(
147159
return html`<section
148160
class="session-progress-card session-progress-card--${placement}"
149161
data-progress-card-placement=${placement}
150-
aria-label=${countLabel}
162+
aria-label=${accessibleLabel}
151163
>
152-
${counts
153-
? html`<div class="session-progress-card__heading">
154-
<span>${t("sessionProgressCard.title")}</span>
155-
<span class="session-progress-card__heading-actions">
156-
<span>${counts.completed}/${counts.total}</span>
157-
${dismiss}
158-
</span>
159-
</div>`
160-
: nothing}
164+
<div class="session-progress-card__heading">
165+
<span>${t("sessionProgressCard.title")}</span>
166+
<span class="session-progress-card__heading-actions">
167+
${lastActivity} ${counts ? html`<span>${counts.completed}/${counts.total}</span>` : nothing}
168+
${dismiss}
169+
</span>
170+
</div>
161171
${renderBody(card)}
162172
</section>`;
163173
}

‎ui/src/e2e/session-progress-live-placement.e2e.test.ts‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mkdir } from "node:fs/promises";
22
import path from "node:path";
3+
import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion";
34
import type { Page } from "playwright";
45
import { expect, it } from "vitest";
56
import {
@@ -35,6 +36,7 @@ const suite = createChatFlowE2eSuite();
3536
suite.define(() => {
3637
it("keeps one live card placement and a compact transcript receipt", async () => {
3738
const sessionKey = "agent:main:progress-placement";
39+
const updatedAt = Date.now() - 5 * 60_000;
3840
const plan = [
3941
{ step: "Inspect", status: "completed" },
4042
{ step: "Implement", status: "in_progress" },
@@ -79,15 +81,15 @@ suite.define(() => {
7981
revision: 2,
8082
sessionKey,
8183
steps: plan,
82-
updatedAt: 2,
84+
updatedAt,
8385
},
8486
},
8587
"sessions.list": chatSessionListResponse([
8688
{
8789
key: sessionKey,
8890
kind: "direct",
8991
label: "Progress placement",
90-
updatedAt: 2,
92+
updatedAt,
9193
},
9294
]),
9395
},
@@ -98,6 +100,28 @@ suite.define(() => {
98100
await expect.poll(() => gateway.getRequests("progressCard.get")).toHaveLength(1);
99101

100102
const visiblePane = page.locator("openclaw-chat-pane.chat-pane-cache__pane--visible");
103+
const expectVisibleLastActivity = async (placement: "composer" | "dock" | "rail") => {
104+
const card = visiblePane.locator(`[data-progress-card-placement="${placement}"]`);
105+
const timestamp = card.locator("time");
106+
await expect
107+
.poll(() => timestamp.getAttribute("datetime"))
108+
.toBe(new Date(updatedAt).toISOString());
109+
await expect.poll(() => timestamp.getAttribute("aria-label")).toMatch(/^Last activity: /);
110+
await expect.poll(() => timestamp.textContent()).toMatch(/\d{1,2}:\d{2}:\d{2}/);
111+
await expect.poll(() => timestamp.isVisible()).toBe(true);
112+
const accessibleCard = placement === "composer" ? card.locator("summary") : card;
113+
await expect
114+
.poll(() => accessibleCard.getAttribute("aria-label"))
115+
.toContain("Last activity:");
116+
const timestampBounds = await timestamp.boundingBox();
117+
const cardBounds = await card.boundingBox();
118+
if (!timestampBounds || !cardBounds) {
119+
throw new Error("The progress card and last activity time must both remain visible");
120+
}
121+
expect(timestampBounds.x + timestampBounds.width).toBeLessThanOrEqual(
122+
cardBounds.x + cardBounds.width,
123+
);
124+
};
101125
// Wide enough for the composer gutter to hold the card: it docks beside
102126
// the composer instead of stacking inside it.
103127
await page.setViewportSize({ height: 900, width: 1600 });
@@ -123,6 +147,7 @@ suite.define(() => {
123147
);
124148
})
125149
.toBe(true);
150+
await expectVisibleLastActivity("dock");
126151
await captureProof(page, "dock-beside-composer.png");
127152

128153
await page.setViewportSize({ height: 900, width: 1280 });
@@ -143,6 +168,7 @@ suite.define(() => {
143168
await expect
144169
.poll(() => visiblePane.locator(".chat-thread").textContent())
145170
.not.toContain("Implementation is moving.");
171+
await expectVisibleLastActivity("rail");
146172
await captureProof(page, "rail-visible.png");
147173

148174
await page.setViewportSize({ height: 900, width: 560 });
@@ -161,6 +187,7 @@ suite.define(() => {
161187
await expect
162188
.poll(() => visiblePane.locator('[data-progress-card-placement="composer"]').isVisible())
163189
.toBe(true);
190+
await expectVisibleLastActivity("composer");
164191
await captureProof(page, "composer-adjacent.png");
165192
},
166193
);
@@ -237,8 +264,25 @@ suite.define(() => {
237264
await expectMarkerCentered();
238265
await captureProof(page, `completed-${colorScheme}-before.png`);
239266

267+
await gateway.setMethodResponse("progressCard.put", {
268+
card: {
269+
revision: 4,
270+
sessionKey,
271+
steps: plan,
272+
updatedAt: MAX_DATE_TIMESTAMP_MS + 1,
273+
},
274+
});
275+
await card.getByRole("button", { name: "Dismiss progress card" }).click();
276+
await expect.poll(() => gateway.getRequests("progressCard.put")).toHaveLength(1);
277+
await page.getByText("Could not dismiss the progress card. Try again.").waitFor();
278+
await expect.poll(() => card.isVisible()).toBe(true);
279+
await expect
280+
.poll(() => card.locator("time").getAttribute("datetime"))
281+
.toBe(new Date(3).toISOString());
282+
283+
await gateway.setMethodResponse("progressCard.put", { card: null });
240284
await card.getByRole("button", { name: "Dismiss progress card" }).click();
241-
const dismissRequest = await gateway.waitForRequest("progressCard.put");
285+
const dismissRequest = await gateway.waitForRequest("progressCard.put", { after: 1 });
242286
expect(dismissRequest.params).toEqual({ sessionKey, expectedRevision: 3 });
243287
await expect.poll(() => card.count()).toBe(0);
244288

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ export const en: TranslationMap = {
240240
widgetUnavailable: "Session progress is unavailable.",
241241
widgetAccessDenied: "Select a session you can access or change sharing for this session.",
242242
countLabel: "{completed} of {total} completed",
243+
lastActivity: "Last activity: {time}",
243244
stepLabel: "{step}, {status}",
244245
status: {
245246
completed: "completed",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion";
2+
import { describe, expect, it, vi } from "vitest";
3+
import type { ApplicationGateway } from "../app/gateway.ts";
4+
import { sessionProgressCardsForGateway } from "./session-progress-cards.ts";
5+
6+
const sessionKey = "agent:main:progress-date-boundary";
7+
8+
function createProgressCard(updatedAt: number) {
9+
return { sessionKey, revision: 1, updatedAt, markdown: "Progress update" };
10+
}
11+
12+
function createGateway() {
13+
const request = vi.fn();
14+
const gateway = {
15+
snapshot: {
16+
client: { request },
17+
phase: "connected",
18+
hello: { features: { methods: ["progressCard.get", "progressCard.put"] } },
19+
},
20+
subscribe: () => () => undefined,
21+
subscribeEvents: () => () => undefined,
22+
} as unknown as ApplicationGateway;
23+
return { gateway, request };
24+
}
25+
26+
describe("session progress card Gateway response boundary", () => {
27+
it.each([-MAX_DATE_TIMESTAMP_MS, MAX_DATE_TIMESTAMP_MS])(
28+
"accepts the inclusive JavaScript Date boundary %i",
29+
async (updatedAt) => {
30+
const { gateway, request } = createGateway();
31+
request.mockResolvedValueOnce({ card: createProgressCard(updatedAt) });
32+
33+
const store = sessionProgressCardsForGateway(gateway);
34+
await expect(store.load(sessionKey)).resolves.toMatchObject({ updatedAt });
35+
expect(store.get(sessionKey)?.updatedAt).toBe(updatedAt);
36+
},
37+
);
38+
39+
it.each([-MAX_DATE_TIMESTAMP_MS - 1, MAX_DATE_TIMESTAMP_MS + 1])(
40+
"rejects an out-of-range timestamp from progressCard.get: %i",
41+
async (updatedAt) => {
42+
const { gateway, request } = createGateway();
43+
request.mockResolvedValueOnce({ card: createProgressCard(updatedAt) });
44+
45+
const store = sessionProgressCardsForGateway(gateway);
46+
await expect(store.load(sessionKey)).rejects.toThrow(
47+
"Progress card response did not match the requested session",
48+
);
49+
expect(store.get(sessionKey)).toBeUndefined();
50+
expect(store.getError(sessionKey)).toBe("unavailable");
51+
},
52+
);
53+
54+
it.each([-MAX_DATE_TIMESTAMP_MS - 1, MAX_DATE_TIMESTAMP_MS + 1])(
55+
"rejects an out-of-range timestamp from progressCard.put: %i",
56+
async (updatedAt) => {
57+
const { gateway, request } = createGateway();
58+
const existingCard = createProgressCard(Date.now());
59+
request
60+
.mockResolvedValueOnce({ card: existingCard })
61+
.mockResolvedValueOnce({ card: createProgressCard(updatedAt) });
62+
63+
const store = sessionProgressCardsForGateway(gateway);
64+
await store.load(sessionKey);
65+
await expect(store.dismiss(existingCard)).rejects.toThrow(
66+
"Progress card response did not match the requested session",
67+
);
68+
expect(store.get(sessionKey)?.updatedAt).toBe(existingCard.updatedAt);
69+
},
70+
);
71+
});

‎ui/src/lib/session-progress-cards.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
ProgressCardPutResult,
55
ProgressCardStep,
66
} from "@openclaw/gateway-protocol";
7+
import { asDateTimestampMs } from "@openclaw/normalization-core/number-coercion";
78
import { isRecord } from "@openclaw/normalization-core/record-coerce";
89
import { GatewayRequestError } from "../api/gateway.ts";
910
import type { ApplicationGateway } from "../app/gateway.ts";
@@ -60,7 +61,7 @@ function parseProgressCard(value: unknown, sessionKey: string): ProgressCard | n
6061
}
6162
const markdown = card.markdown;
6263
const revision = card.revision;
63-
const updatedAt = card.updatedAt;
64+
const updatedAt = asDateTimestampMs(card.updatedAt);
6465
const rawSteps = card.steps;
6566
if (
6667
card.sessionKey !== sessionKey ||
@@ -69,7 +70,7 @@ function parseProgressCard(value: unknown, sessionKey: string): ProgressCard | n
6970
typeof revision !== "number" ||
7071
!Number.isInteger(revision) ||
7172
revision < 1 ||
72-
typeof updatedAt !== "number" ||
73+
updatedAt === undefined ||
7374
!Number.isInteger(updatedAt)
7475
) {
7576
throw new Error("Progress card response did not match the requested session");
@@ -301,12 +302,13 @@ function createStore(gateway: ApplicationGateway): SessionProgressCardStore {
301302
sessionKey: card.sessionKey,
302303
expectedRevision: card.revision,
303304
});
304-
const dismissed = result.card === null;
305+
const resultCard = parseProgressCard(result, card.sessionKey);
306+
const dismissed = resultCard === null;
305307
if (dismissed && cache.get(card.sessionKey)?.revision === card.revision) {
306308
remember(card.sessionKey, { card: null, revision: null });
307309
notify();
308-
} else if (result.card) {
309-
remember(card.sessionKey, { card: result.card, revision: result.card.revision });
310+
} else if (resultCard) {
311+
remember(card.sessionKey, { card: resultCard, revision: resultCard.revision });
310312
notify();
311313
}
312314
return dismissed;

0 commit comments

Comments
 (0)