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

A client's app card says its last change in one plain sentence #15115

Merged opened this

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

Merged

scout/forge:scout/15074-a-client-s-app-card-says-its-last-change → main 5 commits fork 3 threads · 3 unresolved

  • Merged. scout/15074-a-client-s-app-card-says-its-last-change was merged into main as 7a0490b.

Review

Sign in to review this change.
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 @@
66
77 import type { Database } from "bun:sqlite";
88 import type { App } from "../app.ts";
9 import { ago } from "../feed/rank.ts";
109 import { appsRuntime, envsFor } from "../apps/runtime.ts";
1110 import { appsForRepos } from "./apps.ts";
1211 import { spawnedRepos } from "./next-steps.ts";
@@ -133,14 +132,3 @@ export function cutTitle(title: string): string {
133132 const space = head.lastIndexOf(" ");
134133 return `${(space > 0 ? head.slice(0, space) : head).trimEnd()}…`;
135134 }
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);
outdated

Principle 8 / box 2: only plainWords is applied. Also strip 7-40 hex hashes and branch-shaped tokens (a/b-c), and test them.

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
2424 import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts";
2525 import { forgeHealth } from "../../kernel/guard.ts";
2626 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";
2829 import { appCrew } from "../../core/app-crew.ts";
2930 import { nextStepsFor } from "../../core/next-steps.ts";
3031 import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts";
@@ -416,11 +417,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
416417 apps.length === 0
417418 ? ["Your apps will appear here."]
418419 : 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());
420421 const mark = a.live === undefined ? "" : " (running, o opens it)";
421422 const line = `${a.repo.name}${mark}: ${sentences.get(a.repo.id) ?? IDLE_LINE}.`;
422423 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)}.`;
424425 });
425426 if (asked) clientLines = [askStatusLine(asked), ...clientLines];
426427 ctx.invalidate();
src/web/studio/client_home.ts +4 −3
@@ -7,8 +7,9 @@
77 */
88
99 import { clientLines } from "../../actions/client_line.ts";
10 import { lastChangeLine } from "../../story/last_change.ts";
1011 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";
1213 import type { User } from "../../core/users.ts";
1314 import type { Ctx } from "../../http/context.ts";
1415 import { mayDirectCrew } from "../../crew/direct.ts";
@@ -27,7 +28,7 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
2728 const lines = timePhase(ctx.request, "line", () => clientLines(ctx.app.db, apps.map((a) => a.repo)));
2829 const rendering = performance.now();
2930 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.

3132 const about = repo.description !== "" ? repo.description : "An app of yours.";
3233 // The tell form with this app chosen; it sends the person back to `/`.
3334 const ask = mayDirectCrew(ctx.app.db, repo, user)
@@ -49,7 +50,7 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
4950 </div>
5051 <span class="client-app-line"><b>${lines.get(repo.id) ?? ""}</b></span>
5152 <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>
5354 </li>`;
5455 });
5556 const shown = card(
test/client-apps.test.ts +1 −11
@@ -1,11 +1,10 @@
11 /** What a client's apps are doing: the work running, else what was last finished (#4007, #6091). */
22 import { beforeEach, describe, expect, test } from "bun:test";
33 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";
55 import { migrations } from "../src/core/schema.ts";
66 import { openDb } from "../src/kernel/db.ts";
77
8 const NOW = new Date("2026-10-21T12:00:00.000Z");
98 let db: Database;
109
1110 beforeEach(() => {
@@ -68,12 +67,3 @@ describe("clientFinished", () => {
6867 expect(clientFinished(db, []).size).toBe(0);
6968 });
7069 });
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", () => {
564564 clean();
565565 });
566566
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 () => {
568568 clean();
569569 seedIssue("i-doing-2", 9002, "pull", "Fix the menu", "closed");
570570 child.db
571571 .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)")
572572 .run("0".repeat(40), new Date(Date.now() - 3 * 86_400_000).toISOString());
573573 const r = await row();
574 expect(r).toContain("Finished");
575 expect(r).toContain("3 days ago");
574 expect(r).toContain("The crew&#39;s last change was");
576575 expect(r).toContain("Fix the menu");
577 expect(r).not.toContain("Last change");
576 expect(r).not.toContain("days ago");
578577 clean();
579578 });
580579
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 () => {
582581 clean();
583582 const maria = ids().maria;
584583 const other = await createRepo(child, maria, { name: "cafe2", owner: "marias" });
585584 if (!other.ok) throw new Error(JSON.stringify(other.error));
586585 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");
588588 seedIssue("i-doing-4", 9004, "pull", "Older <i>fix</i>", "closed");
589589 seedIssue("i-doing-5", 9005, "pull", "Add <b>rye</b> bread", "closed");
590590 const ins = child.db.query(
@@ -593,15 +593,15 @@ describe("a client's first screen", () => {
593593 ins.run("i-doing-4", "0".repeat(40), new Date(Date.now() - 90 * 86_400_000).toISOString());
594594 ins.run("i-doing-5", "0".repeat(40), new Date(Date.now() - 40 * 86_400_000).toISOString());
595595 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");
598598 expect(line).toContain("Add &lt;b&gt;rye&lt;/b&gt; bread");
599599 expect(line).not.toContain("Older");
600600 for (const word of ["pull", "branch", "commit", "merge", "CI", "repository", "repositories"])
601601 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);
603603 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");
605605 const res = await fetch(url("/"), { headers: { cookie: owner } });
606606 expect(res.headers.get("server-timing") ?? "").toMatch(/\bfinished;/);
607607 child.db.query("DELETE FROM repo WHERE id = ?1").run(other.value.id);
@@ -649,7 +649,7 @@ describe("a client's first screen", () => {
649649 app.start();
650650 await settleApp(app);
651651 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”");
653653 expect(text).not.toContain("Last change");
654654 app.stop();
655655 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("&lt;script&gt;");
35 });
36 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs