Multiplayer agent harness for work.
fix(web): show compact dates on older message timestamps (#1506)
Regan Bell5d3b6dc23932
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.tsindex f9f1c2ab5..fe33165f7 100644--- a/plugins/web-ui/src/chat.ts+++ b/plugins/web-ui/src/chat.ts@@ -1,3 +1,4 @@+import { formatMessageTime } from "./message-time.ts";import { messageEntrySeqs, highlightMessage } from "./message-link.ts";import { appEditSlug } from "./app-edit";import { isConnectionReturn } from "./connection-return";@@ -180,6 +181,7 @@ installMarkdownSanitizer();const detachedAgents = new WeakSet<Agent>();interface SettledRowKey {+ day: string;index: number;activity: WorkBlock["activity"] | undefined;status: WorkBlock["status"] | undefined;@@ -1564,9 +1566,11 @@ export function createChatSurface(const speakerLabel = speakerLabelFor(message);const edited = Boolean((message as { edited?: boolean }).edited);const deleted = Boolean((message as { deleted?: boolean }).deleted);+ const day = new Date().toDateString();const hit = settledRowCache.get(message as object);if (hit &&+ hit.day === day &&hit.index === index &&hit.activity === work?.activity &&hit.status === work?.status &&@@ -1585,6 +1589,7 @@ export function createChatSurface(}const tpl = chatMessage(message, index, isStreaming);settledRowCache.set(message as object, {+ day,index,activity: work?.activity,status: work?.status,@@ -1757,7 +1762,7 @@ export function createChatSurface(const forkable = Boolean(index >= 0 && chatState.threadRef && chatState.sessionId && chatState.agent);return html`<div class="message-meta">- ${ts !== undefined ? html`<span class="message-time">${formatClock(ts)}</span>` : nothing}+ ${ts !== undefined ? html`<span class="message-time">${formatMessageTime(ts)}</span>` : nothing}${text? html`<button@@ -1840,14 +1845,6 @@ export function createChatSurface(}}- function formatClock(ms: number): string {- try {- return new Date(ms).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });- } catch {- return "";- }- }-function withReturnTo(url: string): string {const returnTo = deepLinkPath(UI_BASE, "chats", chatState.sessionId);const sep = url.includes("?") ? "&" : "?";diff --git a/plugins/web-ui/src/message-time.ts b/plugins/web-ui/src/message-time.tsnew file mode 100644index 000000000..c755a108f--- /dev/null+++ b/plugins/web-ui/src/message-time.ts@@ -0,0 +1,19 @@+export function formatMessageTime(ms: number, now = Date.now()): string {+ const date = new Date(ms);+ if (!Number.isFinite(date.getTime())) return "";+ const today = new Date(now);+ const time = date.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });+ if (date.toDateString() === today.toDateString()) return time;+ today.setHours(0, 0, 0, 0);+ const weekStart = new Date(today);+ weekStart.setDate(weekStart.getDate() - 6);+ const options: Intl.DateTimeFormatOptions =+ date >= weekStart && date < today+ ? { weekday: "long" }+ : {+ month: "short",+ day: "numeric",+ ...(date.getFullYear() !== today.getFullYear() ? { year: "numeric" } : {}),+ };+ return `${date.toLocaleDateString([], options)} ${time}`;+}diff --git a/plugins/web-ui/test/chat-settled-row-cache.test.ts b/plugins/web-ui/test/chat-settled-row-cache.test.tsindex ad0988397..2b27a2777 100644--- a/plugins/web-ui/test/chat-settled-row-cache.test.ts+++ b/plugins/web-ui/test/chat-settled-row-cache.test.ts@@ -18,6 +18,7 @@ test("live, approval-paused, and subagent rows bypass the cache (their render retest("the cache key covers every mutable render input of a settled row", () => {for (const field of [+ "hit.day === day","hit.index === index","hit.activity === work?.activity","hit.status === work?.status",diff --git a/plugins/web-ui/test/message-time.test.ts b/plugins/web-ui/test/message-time.test.tsnew file mode 100644index 000000000..e33d7ef0e--- /dev/null+++ b/plugins/web-ui/test/message-time.test.ts@@ -0,0 +1,43 @@+import assert from "node:assert/strict";+import test from "node:test";+import { formatMessageTime } from "../src/message-time.ts";++const now = new Date(2026, 8, 21, 19, 13).getTime();+const clock = (date: Date) => date.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });++for (const [label, date, options] of [+ ["today", new Date(2026, 8, 21, 11, 55), null],+ ["yesterday", new Date(2026, 8, 20, 23, 55), { weekday: "long" }],+ ["Friday in the screenshot", new Date(2026, 8, 18, 23, 55), { weekday: "long" }],+ ["six calendar days ago", new Date(2026, 8, 15), { weekday: "long" }],+ ["a week ago", new Date(2026, 8, 14, 23, 55), { month: "short", day: "numeric" }],+ ["last year", new Date(2025, 8, 18, 23, 55), { month: "short", day: "numeric", year: "numeric" }],+ ["a future day", new Date(2026, 8, 22, 11, 55), { month: "short", day: "numeric" }],+] as const) {+ test(`message time includes the right date for ${label}`, () => {+ const prefix = options ? `${date.toLocaleDateString([], options)} ` : "";+ assert.equal(formatMessageTime(date.getTime(), now), `${prefix}${clock(date)}`);+ });+}++test("date labels change at local midnight, not after 24 hours", () => {+ const date = new Date(2026, 8, 20, 23, 55);+ const prefix = date.toLocaleDateString([], { weekday: "long" });+ assert.equal(formatMessageTime(date.getTime(), new Date(2026, 8, 21, 0, 1).getTime()), `${prefix} ${clock(date)}`);+});++test("weekday window uses calendar days across daylight saving changes", () => {+ for (const [today, date] of [+ [new Date(2026, 2, 10, 12), new Date(2026, 2, 4)],+ [new Date(2026, 10, 3, 12), new Date(2026, 9, 28)],+ ]) {+ assert.equal(+ formatMessageTime(date.getTime(), today.getTime()),+ `${date.toLocaleDateString([], { weekday: "long" })} ${clock(date)}`,+ );+ }+});++test("invalid timestamps render no label", () => {+ for (const ms of [NaN, Infinity, -Infinity]) assert.equal(formatMessageTime(ms, now), "");+});