Public: anyone can read this; the crew can change it.
A client's app card says its last change in one plain sentence #15115
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15074-a-client-s-app-card-says-its-last-change → main 5 commits fork 3 threads · 3 unresolved
8 files
changed +116
−40
docs/features/last-change.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Your apps | |
| 3 | row: Last change on an app card | |
| 4 | --- | |
| 5 | # Last change on an app card | |
| 6 | ||
| 7 | A client's app card says its newest merged change in one sentence: "The crew's last change was “the booking form”, | |
| 8 | on Tuesday." Pull numbers, hashes and branch names are stripped; the title is cut at 80 characters; the day is read | |
| 9 | in UTC. An app with nothing shipped says "The crew has not changed anything yet." | |
| 10 | ||
| 11 | Try it: sign in as a client and open `/`. Both doors: the terminal's client home lists each app with the same | |
| 12 | sentence, worded by `lastChangeLine` in `src/story/last_change.ts`. | |
| 13 | ||
| 14 | Pinned by `test/last-change-line.test.ts`. |
src/core/client-apps.ts −12
| @@ -6,7 +6,6 @@ | ||
| 6 | 6 | |
| 7 | 7 | import type { Database } from "bun:sqlite"; |
| 8 | 8 | import type { App } from "../app.ts"; |
| 9 | import { ago } from "../feed/rank.ts"; | |
| 10 | 9 | import { appsRuntime, envsFor } from "../apps/runtime.ts"; |
| 11 | 10 | import { appsForRepos } from "./apps.ts"; |
| 12 | 11 | import { spawnedRepos } from "./next-steps.ts"; |
| @@ -133,14 +132,3 @@ export function cutTitle(title: string): string { | ||
| 133 | 132 | const space = head.lastIndexOf(" "); |
| 134 | 133 | return `${(space > 0 ? head.slice(0, space) : head).trimEnd()}…`; |
| 135 | 134 | } |
| 136 | ||
| 137 | /** | |
| 138 | * `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it | |
| 139 | * so. | |
| 140 | */ | |
| 141 | export function finishedLine(finished: ClientFinished | undefined, now: number): string { | |
| 142 | const title = finished === undefined ? "" : cutTitle(finished.title); | |
| 143 | if (finished === undefined || title === "") return ""; | |
| 144 | const at = Date.parse(finished.at); | |
| 145 | return Number.isNaN(at) ? "" : `Finished ${ago(at, now)}: ${title}`; | |
| 146 | } |
src/story/last_change.ts added +46
| @@ -0,0 +1,46 @@ | ||
| 1 | /** | |
| 2 | * The one plain sentence on a client's app card about its last shipped change: "The crew's last | |
| 3 | * change was “the booking form”, on Tuesday." The title is the pull's, cleaned of identifiers | |
| 4 | * (`plainWords`) and cut at 80 characters; the day is the merge day in UTC. Plain text out: the | |
| 5 | * page escapes it when it draws it. | |
| 6 | */ | |
| 7 | import { plainWords } from "../core/app-crew.ts"; | |
| 8 | import { cutTitle } from "../core/client-apps.ts"; | |
| 9 | ||
| 10 | export const NO_CHANGE_LINE = "The crew has not changed anything yet."; | |
| 11 | const DAY = 86_400_000; | |
| 12 | const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; | |
| 13 | const MONTHS = [ | |
| 14 | "January", "February", "March", "April", "May", "June", | |
| 15 | "July", "August", "September", "October", "November", "December", | |
| 16 | ]; | |
| 17 | ||
| 18 | /** | |
| 19 | * A commit hash (7-40 hex with a digit) or a branch-shaped token ("juniper/fix-menu"): developer | |
| 20 | * words. | |
| 21 | */ | |
| 22 | const DEV_TOKENS = /\b(?=[0-9a-f]*\d)[0-9a-f]{7,40}\b|\b[\w.-]+\/[\w./-]+/gi; | |
| 23 | ||
| 24 | /** | |
| 25 | * The day is read in UTC, not the person's zone (the page knows none): near midnight a client east | |
| 26 | * or west of UTC can see "yesterday" for something that shipped this morning for them. "today", | |
| 27 | * "yesterday", "on Tuesday" within the week, else "on 3 March". | |
| 28 | */ | |
| 29 | function day(at: number, now: number): string { | |
| 30 | const start = (t: number): number => Math.floor(t / DAY) * DAY; | |
| 31 | const back = Math.round((start(now) - start(at)) / DAY); | |
| 32 | const d = new Date(at); | |
| 33 | if (back <= 0) return "today"; | |
| 34 | if (back === 1) return "yesterday"; | |
| 35 | if (back < 7) return `on ${WEEKDAYS[d.getUTCDay()]}`; | |
| 36 | return `on ${d.getUTCDate()} ${MONTHS[d.getUTCMonth()]}${d.getUTCFullYear() === new Date(now).getUTCFullYear() ? "" : ` ${d.getUTCFullYear()}`}`; | |
| 37 | } | |
| 38 | ||
| 39 | /** The sentence for an app's newest merged pull, or the "not yet" one when it has none. */ | |
| 40 | export function lastChangeLine(last: { title: string; at: string } | undefined, now: number): string { | |
| 41 | if (last === undefined) return NO_CHANGE_LINE; | |
| 42 | const title = cutTitle(plainWords(last.title).replace(DEV_TOKENS, "").replace(/\(\s*\)/g, "")); | |
| 43 | const at = Date.parse(last.at); | |
| 44 | if (title === "" || Number.isNaN(at)) return NO_CHANGE_LINE; | |
| 45 | return `The crew's last change was “${title}”, ${day(at, now)}.`; | |
| 46 | } |
src/tui/screens/dashboard.ts +4 −3
| @@ -24,7 +24,8 @@ import { forgeFlakes, forgeLane, forgeNeedList, needTermLine } from "../../actio | ||
| 24 | 24 | import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts"; |
| 25 | 25 | import { forgeHealth } from "../../kernel/guard.ts"; |
| 26 | 26 | import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_verdict.ts"; |
| 27 | import { clientAppRows, clientFinished, finishedLine } from "../../core/client-apps.ts"; | |
| 27 | import { lastChangeLine } from "../../story/last_change.ts"; | |
| 28 | import { clientAppRows, clientFinished } from "../../core/client-apps.ts"; | |
| 28 | 29 | import { appCrew } from "../../core/app-crew.ts"; |
| 29 | 30 | import { nextStepsFor } from "../../core/next-steps.ts"; |
| 30 | 31 | import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts"; |
| @@ -416,11 +417,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 416 | 417 | apps.length === 0 |
| 417 | 418 | ? ["Your apps will appear here."] |
| 418 | 419 | : apps.map((a) => { |
| 419 | const doing = finishedLine(finished.get(a.repo.id), now.getTime()); | |
| 420 | const doing = lastChangeLine(finished.get(a.repo.id), now.getTime()); | |
| 420 | 421 | const mark = a.live === undefined ? "" : " (running, o opens it)"; |
| 421 | 422 | const line = `${a.repo.name}${mark}: ${sentences.get(a.repo.id) ?? IDLE_LINE}.`; |
| 422 | 423 | const crew = crewOf.get(a.repo.id)!.says; |
| 423 | return `${line}${doing === "" ? "" : ` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`; | |
| 424 | return `${line}${` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`; | |
| 424 | 425 | }); |
| 425 | 426 | if (asked) clientLines = [askStatusLine(asked), ...clientLines]; |
| 426 | 427 | ctx.invalidate(); |
src/web/studio/client_home.ts +4 −3
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import { clientLines } from "../../actions/client_line.ts"; |
| 10 | import { lastChangeLine } from "../../story/last_change.ts"; | |
| 10 | 11 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| 11 | import { clientAppRows, clientFinished, finishedLine } from "../../core/client-apps.ts"; | |
| 12 | import { clientAppRows, clientFinished } from "../../core/client-apps.ts"; | |
| 12 | 13 | import type { User } from "../../core/users.ts"; |
| 13 | 14 | import type { Ctx } from "../../http/context.ts"; |
| 14 | 15 | import { mayDirectCrew } from "../../crew/direct.ts"; |
| @@ -27,7 +28,7 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> { | ||
| 27 | 28 | const lines = timePhase(ctx.request, "line", () => clientLines(ctx.app.db, apps.map((a) => a.repo))); |
| 28 | 29 | const rendering = performance.now(); |
| 29 | 30 | const rows = apps.map(({ repo, live }) => { |
| 30 | const done = finishedLine(finished.get(repo.id), now.getTime()); | |
| 31 | const done = lastChangeLine(finished.get(repo.id), now.getTime()); | |
Both doors: the terminal's actions screen still uses finishedLine ("Finished 3 days ago"). Use lastChangeLine there too and add docs/features/<name>.md. |
||
| 31 | 32 | const about = repo.description !== "" ? repo.description : "An app of yours."; |
| 32 | 33 | // The tell form with this app chosen; it sends the person back to `/`. |
| 33 | 34 | const ask = mayDirectCrew(ctx.app.db, repo, user) |
| @@ -49,7 +50,7 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> { | ||
| 49 | 50 | </div> |
| 50 | 51 | <span class="client-app-line"><b>${lines.get(repo.id) ?? ""}</b></span> |
| 51 | 52 | <span class="client-app-about">${about}</span> |
| 52 | ${done !== "" ? html`<span class="client-app-finished muted">${done}</span>` : ""} | |
| 53 | <span class="client-app-finished muted">${done}</span> | |
| 53 | 54 | </li>`; |
| 54 | 55 | }); |
| 55 | 56 | const shown = card( |
test/client-apps.test.ts +1 −11
| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | /** What a client's apps are doing: the work running, else what was last finished (#4007, #6091). */ |
| 2 | 2 | import { beforeEach, describe, expect, test } from "bun:test"; |
| 3 | 3 | import type { Database } from "bun:sqlite"; |
| 4 | import { clientDoings, clientFinished, finishedLine } from "../src/core/client-apps.ts"; | |
| 4 | import { clientDoings, clientFinished } from "../src/core/client-apps.ts"; | |
| 5 | 5 | import { migrations } from "../src/core/schema.ts"; |
| 6 | 6 | import { openDb } from "../src/kernel/db.ts"; |
| 7 | 7 | |
| 8 | const NOW = new Date("2026-10-21T12:00:00.000Z"); | |
| 9 | 8 | let db: Database; |
| 10 | 9 | |
| 11 | 10 | beforeEach(() => { |
| @@ -68,12 +67,3 @@ describe("clientFinished", () => { | ||
| 68 | 67 | expect(clientFinished(db, []).size).toBe(0); |
| 69 | 68 | }); |
| 70 | 69 | }); |
| 71 | ||
| 72 | describe("the lines", () => { | |
| 73 | test("finishedLine spells the age out and is empty with nothing finished", () => { | |
| 74 | const at = new Date(NOW.getTime() - 3 * 86_400_000).toISOString(); | |
| 75 | expect(finishedLine({ title: "Fix the menu", at }, NOW.getTime())).toBe("Finished 3 days ago: Fix the menu"); | |
| 76 | expect(finishedLine(undefined, NOW.getTime())).toBe(""); | |
| 77 | }); | |
| 78 | ||
| 79 | }); |
test/client-home.test.ts +11 −11
| @@ -564,27 +564,27 @@ describe("a client's first screen", () => { | ||
| 564 | 564 | clean(); |
| 565 | 565 | }); |
| 566 | 566 | |
| 567 | test("a change landed this week reads Finished once, not Last change too", async () => { | |
| 567 | test("a change landed this week reads as the crew's last change, once", async () => { | |
| 568 | 568 | clean(); |
| 569 | 569 | seedIssue("i-doing-2", 9002, "pull", "Fix the menu", "closed"); |
| 570 | 570 | child.db |
| 571 | 571 | .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES ('i-doing-2', 'main', 'x', ?1, ?1, ?2)") |
| 572 | 572 | .run("0".repeat(40), new Date(Date.now() - 3 * 86_400_000).toISOString()); |
| 573 | 573 | const r = await row(); |
| 574 | expect(r).toContain("Finished"); | |
| 575 | expect(r).toContain("3 days ago"); | |
| 574 | expect(r).toContain("The crew's last change was"); | |
| 576 | 575 | expect(r).toContain("Fix the menu"); |
| 577 | expect(r).not.toContain("Last change"); | |
| 576 | expect(r).not.toContain("days ago"); | |
| 578 | 577 | clean(); |
| 579 | 578 | }); |
| 580 | 579 | |
| 581 | test("the newest merged pull reads Finished, on that app only, escaped, with its own phase", async () => { | |
| 580 | test("the newest merged pull is the last change, on that app only, escaped, with its own phase", async () => { | |
| 582 | 581 | clean(); |
| 583 | 582 | const maria = ids().maria; |
| 584 | 583 | const other = await createRepo(child, maria, { name: "cafe2", owner: "marias" }); |
| 585 | 584 | if (!other.ok) throw new Error(JSON.stringify(other.error)); |
| 586 | 585 | const none = main(await page(owner)); |
| 587 | expect(none).not.toContain("client-app-finished"); | |
| 586 | expect(none).not.toContain("last change was"); | |
| 587 | expect(none).toContain("has not changed anything yet"); | |
| 588 | 588 | seedIssue("i-doing-4", 9004, "pull", "Older <i>fix</i>", "closed"); |
| 589 | 589 | seedIssue("i-doing-5", 9005, "pull", "Add <b>rye</b> bread", "closed"); |
| 590 | 590 | const ins = child.db.query( |
| @@ -593,15 +593,15 @@ describe("a client's first screen", () => { | ||
| 593 | 593 | ins.run("i-doing-4", "0".repeat(40), new Date(Date.now() - 90 * 86_400_000).toISOString()); |
| 594 | 594 | ins.run("i-doing-5", "0".repeat(40), new Date(Date.now() - 40 * 86_400_000).toISOString()); |
| 595 | 595 | const home = main(await page(owner)); |
| 596 | const line = home.match(/client-app-finished[^>]*>([^]*?)<\/span>/)?.[1] ?? ""; | |
| 597 | expect(line).toContain("Finished"); | |
| 596 | const line = [...home.matchAll(/client-app-finished[^>]*>([^]*?)<\/span>/g)].map((m) => m[1]).find((l) => l?.includes("last change")) ?? ""; | |
| 597 | expect(line).toContain("last change was"); | |
| 598 | 598 | expect(line).toContain("Add <b>rye</b> bread"); |
| 599 | 599 | expect(line).not.toContain("Older"); |
| 600 | 600 | for (const word of ["pull", "branch", "commit", "merge", "CI", "repository", "repositories"]) |
| 601 | 601 | expect(words(line)).not.toMatch(new RegExp(`\\b${word}`, "i")); |
| 602 | expect(home.match(/client-app-finished/g)?.length).toBe(1); | |
| 602 | expect(home.match(/last change was/g)?.length).toBe(1); | |
| 603 | 603 | const cafe = home.slice(home.indexOf('href="/marias/cafe2"')); |
| 604 | expect(cafe.slice(0, cafe.indexOf("</li>"))).not.toContain("Finished"); | |
| 604 | expect(cafe.slice(0, cafe.indexOf("</li>"))).not.toContain("last change was"); | |
| 605 | 605 | const res = await fetch(url("/"), { headers: { cookie: owner } }); |
| 606 | 606 | expect(res.headers.get("server-timing") ?? "").toMatch(/\bfinished;/); |
| 607 | 607 | child.db.query("DELETE FROM repo WHERE id = ?1").run(other.value.id); |
| @@ -649,7 +649,7 @@ describe("a client's first screen", () => { | ||
| 649 | 649 | app.start(); |
| 650 | 650 | await settleApp(app); |
| 651 | 651 | const text = app.screen.toText(); |
| 652 | expect(text).toContain("Finished 3 days ago: Fix the menu"); | |
| 652 | expect(text).toContain("last change was “Fix the menu”"); | |
| 653 | 653 | expect(text).not.toContain("Last change"); |
| 654 | 654 | app.stop(); |
| 655 | 655 | clean(); |
test/last-change-line.test.ts added +36
| @@ -0,0 +1,36 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { html } from "../src/web/html.ts"; | |
| 3 | import { lastChangeLine, NO_CHANGE_LINE } from "../src/story/last_change.ts"; | |
| 4 | ||
| 5 | const NOW = Date.parse("2026-11-21T12:00:00.000Z"); // a Saturday | |
| 6 | ||
| 7 | describe("the last change on an app card", () => { | |
| 8 | test("a ship says its title and its weekday, with no number", () => { | |
| 9 | const line = lastChangeLine({ title: "the booking form (see PR #42)", at: "2026-11-17T09:00:00.000Z" }, NOW); | |
| 10 | expect(line).toBe("The crew's last change was “the booking form”, on Tuesday."); | |
| 11 | expect(line).not.toMatch(/#|\d/); | |
| 12 | }); | |
| 13 | test("recent and old days read plainly", () => { | |
| 14 | expect(lastChangeLine({ title: "Menu", at: "2026-11-21T01:00:00.000Z" }, NOW)).toContain(", today."); | |
| 15 | expect(lastChangeLine({ title: "Menu", at: "2026-11-20T23:00:00.000Z" }, NOW)).toContain(", yesterday."); | |
| 16 | expect(lastChangeLine({ title: "Menu", at: "2026-03-03T09:00:00.000Z" }, NOW)).toContain(", on 3 March."); | |
| 17 | }); | |
| 18 | test("a hash or a branch name never reaches the card", () => { | |
| 19 | const at = "2026-11-17T09:00:00.000Z"; | |
| 20 | expect(lastChangeLine({ title: "Fix 3f9a2bc crash", at }, NOW)).toBe("The crew's last change was “Fix crash”, on Tuesday."); | |
| 21 | expect(lastChangeLine({ title: "Fix juniper/fix-menu crash", at }, NOW)).toBe("The crew's last change was “Fix crash”, on Tuesday."); | |
| 22 | }); | |
outdated
Name says 90, code cuts at 80. Fix the name and assert the real limit. |
||
| 23 | test("no ships yet says so", () => { | |
| 24 | expect(lastChangeLine(undefined, NOW)).toBe(NO_CHANGE_LINE); | |
| 25 | expect(lastChangeLine({ title: "#7", at: "2026-11-17T09:00:00.000Z" }, NOW)).toBe(NO_CHANGE_LINE); | |
| 26 | }); | |
| 27 | test("a long title is cut at 80 and an escaped title cannot become markup", () => { | |
| 28 | const long = lastChangeLine({ title: "word ".repeat(40), at: "2026-11-17T09:00:00.000Z" }, NOW); | |
| 29 | expect(long).toContain("…”"); | |
| 30 | expect(long.length).toBeLessThanOrEqual("The crew's last change was “”, on Tuesday.".length + 80); | |
| 31 | const bad = lastChangeLine({ title: "<script>alert(1)</script> form", at: "2026-11-17T09:00:00.000Z" }, NOW); | |
| 32 | const drawn = html`<span>${bad}</span>`.toString(); | |
| 33 | expect(drawn).not.toContain("<script>"); | |
| 34 | expect(drawn).toContain("<script>"); | |
| 35 | }); | |
| 36 | }); |
new above
offline
Principle 8 / box 2: only plainWords is applied. Also strip 7-40 hex hashes and branch-shaped tokens (a/b-c), and test them.