Public: anyone can read this; the crew can change it.

A post in the feed says how long ago its run finished in plain words, and the words never change width on refresh #14713

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14704-a-post-in-the-feed-says-how-long-ago-its → main 7 commits fork 2 threads · 2 unresolved

  • Merged. scout/14704-a-post-in-the-feed-says-how-long-ago-its was merged into main as aa9f9a0.

Review

Sign in to review this change.
7 files changed +91 −3
docs/design/areas/feed.md +4
@@ -13,3 +13,7 @@
1313 `.feed-empty` wraps the one empty block of a feed with no posts. It holds `FIRST_POST_PX` (206 px) so the post arriving moves nothing below it when it is the shortest kind. The number is summed in `src/web/studio/feed_style.ts` from the stylesheet, not measured in a browser: 2 card borders + head 42 (10+10 padding, 21 line, 1 border) + body 83 (14+14 padding, 21 headline, 12 gap, 36 Like button) + foot 65 (10+10 padding, 44 summary, 1 border). A post with a longer headline, a picture or a wrapped head at 360 px is taller and shifts what is below it whatever is reserved. Styled in `src/web/studio/feed_style.ts`.
1414
1515 The tell box takes the cursor from a small script in `feedJs` only when the feed is empty and the device has a fine pointer and is 900 px or wider; on a phone the keyboard would cover the sentences, and a screen reader hears the page first.
16
17 ## Run age
18
19 `.age` sits on the `<time>` of a run post and holds `min-width: 10ch`, the width of its longest words (`59 min ago`), so the age never changes width as it grows older, a phone's 360 px byline included. It says elapsed time only (`4 min ago`, `1 d ago`); the headline says whether the run finished or failed.
src/feed/finished_label.ts added +19
@@ -0,0 +1,19 @@
1 /**
2 * How long ago a run ended, by elapsed time only: `4 min ago`, `1 d ago`. The post's
3 * own headline says whether it finished or failed, so the label never claims either.
4 * The longest shape is `59 min ago` (10 characters); the slot is sized to it.
5 */
6 export const AGE_SLOT_CH = 10;
7
8 /** An unreadable or future instant says nothing rather than a wrong thing. */
9 export function finishedLabel(iso: string, now: number = Date.now()): string {
10 const ms = now - Date.parse(iso);
11 if (!Number.isFinite(ms)) return "";
12 const s = Math.max(0, Math.floor(ms / 1000));
13 if (s < 60) return `${s} s ago`;
14 const min = Math.floor(s / 60);
outdated

'yesterday' is just 24-48 h elapsed, not the calendar day, and the same module says 'finished' for failed runs. Use elapsed words ('1 d ago') or calendar days, and drop 'finished' for runs that failed.

15 if (min < 60) return `${min} min ago`;
16 const h = Math.floor(min / 60);
17 if (h < 24) return `${h} h ago`;
18 return `${Math.floor(h / 24)} d ago`;
19 }
src/web/studio/feed.ts +3 −1
@@ -19,6 +19,7 @@ import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.t
1919 import { placementsOf, type Placement } from "../../core/placements.ts";
2020 import { recentThoughts, type Thought } from "../../core/thoughts.ts";
2121 import { appFilterOf, APP_UNKNOWN_LINE, ONLY_LEAD, type AppFilter } from "../../feed/app_filter.ts";
22 import { finishedLabel } from "../../feed/finished_label.ts";
2223 import { parseCursor, readFeedPage } from "../../feed/feed.ts";
2324 import { parseShow, SHOW_VALUES, type Show } from "../../feed/mine.ts";
2425 import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts";
@@ -175,10 +176,11 @@ export function feedCard(
175176 const headline = item.kind === "run" && run === undefined
176177 ? html`<p class="break">${item.what}</p>`
177178 : html`<p class="break"><a href="${item.link}" data-feed-open>${item.what}</a></p>`;
179 const aged = item.kind === "run" && run !== undefined ? finishedLabel(item.at) : "";
178180 const head = html`${avatar(item.actor ?? item.app)}
179181 <strong class="break">${item.actor ?? item.app}</strong
180182 >${nameMark(item.actor === null ? undefined : marks.get(item.actor))}
outdated

Principle 3/UX: the long variable-width label sits in time[datetime], which reserves 7ch (base.ts:192), so the text still changes width as it ages, which is exactly what the issue forbids. Pass a class with a min-width for the longest label ('finished 40 d ago'), and verify it at 360px. Also the link has aria-label 'Open post', which hides the age from screen readers; move the age outside the link or drop the override.

181 <span class="muted small break"><a href="/feed?app=${item.app}" class="muted" data-filter-app>${item.app}</a> · <a href="${permalinkOf(item.link)}" class="muted permalink" aria-label="Open post" data-permalink>${time(item.at)}</a></span>
183 <span class="muted small break"><a href="/feed?app=${item.app}" class="muted" data-filter-app>${item.app}</a> · <a href="${permalinkOf(item.link)}" class="muted permalink" aria-label="${aged === "" ? "Open post" : `Open post, ${aged}`}" data-permalink>${aged === "" ? time(item.at) : time(item.at, { text: aged, class: "age" })}</a></span>
182184 ${settledBadge(item.settled)}
183185 <span class="spacer"></span>
184186 <span class="badge">${KIND_LABEL[item.kind]}</span>`;
src/web/style/base.ts +4
@@ -1,3 +1,5 @@
1 import { AGE_SLOT_CH } from "../../feed/finished_label.ts";
2
13 /**
24 * Layer 1 and 2 of the stylesheet: the cascade layers themselves, the
35 * theme-independent constants, the reset, the type scale, and the page shell
@@ -190,6 +192,8 @@ export const utilities = /* css */ `
190192 /* A relative time is a <time datetime title>. It reserves 7ch, so "9m ago" turning
191193 into "10m ago" or "just now" into "1m ago" does not move the line. */
192194 time[datetime] { display: inline-block; min-width: 7ch; text-align: start; font-variant-numeric: tabular-nums; white-space: nowrap; }
195 /* A run post's age keeps one slot, sized to its longest words ("59 min ago"), so it never changes width as it ages. */
196 time[datetime].age { min-width: ${AGE_SLOT_CH}ch; }
193197 .grow { flex: 1; min-width: 0; }
194198 .spacer { flex: 1; }
195199 .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
test/feed-age.test.ts +1 −1
@@ -7,7 +7,7 @@ import type { FeedItem } from "../src/feed/rank.ts";
77 import { feedCard } from "../src/web/studio/feed.ts";
88
99 const at = "2026-03-04T05:06:07.000Z";
10 const item = { id: "e1", kind: "run", app: "alice/notes", actor: "scribe", at, what: "x", reason: "y", link: "/alice/notes/runs/r1" } as FeedItem;
10 const item = { id: "e1", kind: "tell", app: "alice/notes", actor: "scribe", at, what: "x", reason: "y", link: "/alice/notes/issues/1" } as FeedItem;
1111 const hours = (n: number) => new Date(Date.parse(at) + n * 3_600_000 + 60_000);
1212
1313 afterEach(() => setSystemTime());
test/feed-run-time.test.ts added +59
@@ -0,0 +1,59 @@
1 /** A run post says how long ago it finished, server-side, with the full time in title (#14704). */
2 import { afterEach, describe, expect, setSystemTime, test } from "bun:test";
3 import { AGE_SLOT_CH, finishedLabel } from "../src/feed/finished_label.ts";
4 import type { FeedItem } from "../src/feed/rank.ts";
5 import { feedCard } from "../src/web/studio/feed.ts";
6
7 const now = Date.parse("2026-03-10T12:00:00.000Z");
8 const ago = (ms: number) => new Date(now - ms).toISOString();
9 const run = (at: string, what = "a build run finished") =>
10 ({ id: "e1", kind: "run", app: "alice/notes", actor: "scribe", at, what, reason: "y", link: "/alice/notes/runs/r1" }) as FeedItem;
11
12 afterEach(() => setSystemTime());
13
14 describe("run label", () => {
15 const S = 1000, M = 60 * S, H = 60 * M, D = 24 * H;
16 test.each([
17 [30 * S, "30 s ago"],
18 [4 * M, "4 min ago"],
19 [3 * H, "3 h ago"],
20 [23 * H + 50 * M, "23 h ago"],
21 [47 * H, "1 d ago"],
22 [49 * H, "2 d ago"],
23 [2 * D, "2 d ago"],
24 [40 * D, "40 d ago"],
25 ])("%d ms", (ms, label) => {
26 expect(finishedLabel(ago(ms), now)).toBe(label);
27 setSystemTime(now);
28 const text = feedCard(run(ago(ms))).text;
29 expect(text).toContain(`title="${new Date(now - ms).toISOString().slice(0, 16).replace("T", " ")} UTC"`);
30 expect(text).toContain(`>${label}</time`);
31 });
32
33 test("the age keeps a slot as wide as its longest words, and screen readers hear it", async () => {
34 setSystemTime(now);
35 const text = feedCard(run(ago(4 * M))).text;
36 expect(text).toContain('class="age"');
37 expect(text).toContain('aria-label="Open post, 4 min ago"');
38 expect(finishedLabel(ago(59 * M), now).length).toBeLessThanOrEqual(AGE_SLOT_CH);
39 expect(finishedLabel(ago(999 * D), now).length).toBeLessThanOrEqual(AGE_SLOT_CH);
40 const { utilities: css } = await import("../src/web/style/base.ts");
41 expect(css).toContain(`time[datetime].age { min-width: ${AGE_SLOT_CH}ch; }`);
42 });
43
44 test("garbage says nothing", () => expect(finishedLabel("nope", now)).toBe(""));
45
46 test("output is escaped", () => {
47 setSystemTime(now);
48 const text = feedCard({ ...run(ago(60_000), "<img src=x onerror=alert(1)>"), actor: "<b>x</b>" }).text;
49 expect(text).not.toContain("<img src=x");
50 expect(text).not.toContain("<b>x</b>");
51 expect(text).toContain("&lt;img");
52 });
53
54 test("a non-run post keeps its short age", () => {
55 setSystemTime(now);
56 const item = { ...run(ago(3 * 3_600_000)), kind: "tell", link: "/alice/notes/issues/1" } as FeedItem;
57 expect(feedCard(item).text).toContain(">3h ago<");
58 });
59 });
test/feed-time-title.test.ts +1 −1
@@ -5,7 +5,7 @@ import type { FeedItem } from "../src/feed/rank.ts";
55 import { feedCard, thoughtCard } from "../src/web/studio/feed.ts";
66
77 const at = "2026-03-04T05:06:07.000Z";
8 const stamp = /<time datetime="2026-03-04T05:06:07\.000Z"\s+title="2026-03-04 05:06 UTC"\s*>/;
8 const stamp = /<time(?: class="age")? datetime="2026-03-04T05:06:07\.000Z"\s+title="2026-03-04 05:06 UTC"\s*>/;
99
1010 describe("feed card times", () => {
1111 test("a post's time is a <time> with its exact UTC", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs