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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14704-a-post-in-the-feed-says-how-long-ago-its → main 7 commits fork 2 threads · 2 unresolved
7 files
changed +91
−3
docs/design/areas/feed.md +4
| @@ -13,3 +13,7 @@ | ||
| 13 | 13 | `.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`. |
| 14 | 14 | |
| 15 | 15 | 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); | |
| 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 | ||
| 19 | 19 | import { placementsOf, type Placement } from "../../core/placements.ts"; |
| 20 | 20 | import { recentThoughts, type Thought } from "../../core/thoughts.ts"; |
| 21 | 21 | import { appFilterOf, APP_UNKNOWN_LINE, ONLY_LEAD, type AppFilter } from "../../feed/app_filter.ts"; |
| 22 | import { finishedLabel } from "../../feed/finished_label.ts"; | |
| 22 | 23 | import { parseCursor, readFeedPage } from "../../feed/feed.ts"; |
| 23 | 24 | import { parseShow, SHOW_VALUES, type Show } from "../../feed/mine.ts"; |
| 24 | 25 | import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts"; |
| @@ -175,10 +176,11 @@ export function feedCard( | ||
| 175 | 176 | const headline = item.kind === "run" && run === undefined |
| 176 | 177 | ? html`<p class="break">${item.what}</p>` |
| 177 | 178 | : 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) : ""; | |
| 178 | 180 | const head = html`${avatar(item.actor ?? item.app)} |
| 179 | 181 | <strong class="break">${item.actor ?? item.app}</strong |
| 180 | 182 | >${nameMark(item.actor === null ? undefined : marks.get(item.actor))} |
outdated
Principle 3/UX: the long variable-width label sits in |
||
| 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> | |
| 182 | 184 | ${settledBadge(item.settled)} |
| 183 | 185 | <span class="spacer"></span> |
| 184 | 186 | <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 | ||
| 1 | 3 | /** |
| 2 | 4 | * Layer 1 and 2 of the stylesheet: the cascade layers themselves, the |
| 3 | 5 | * theme-independent constants, the reset, the type scale, and the page shell |
| @@ -190,6 +192,8 @@ export const utilities = /* css */ ` | ||
| 190 | 192 | /* A relative time is a <time datetime title>. It reserves 7ch, so "9m ago" turning |
| 191 | 193 | into "10m ago" or "just now" into "1m ago" does not move the line. */ |
| 192 | 194 | 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; } | |
| 193 | 197 | .grow { flex: 1; min-width: 0; } |
| 194 | 198 | .spacer { flex: 1; } |
| 195 | 199 | .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"; | ||
| 7 | 7 | import { feedCard } from "../src/web/studio/feed.ts"; |
| 8 | 8 | |
| 9 | 9 | 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; | |
| 11 | 11 | const hours = (n: number) => new Date(Date.parse(at) + n * 3_600_000 + 60_000); |
| 12 | 12 | |
| 13 | 13 | 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("<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"; | ||
| 5 | 5 | import { feedCard, thoughtCard } from "../src/web/studio/feed.ts"; |
| 6 | 6 | |
| 7 | 7 | 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*>/; | |
| 9 | 9 | |
| 10 | 10 | describe("feed card times", () => { |
| 11 | 11 | test("a post's time is a <time> with its exact UTC", () => { |
new above
offline
'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.