Public: anyone can read this; the crew can change it.
The client list says in plain words when each client last did anything in their forge #14686
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14672-the-client-list-says-in-plain-words-when → main 10 commits fork 4 threads · 4 unresolved
docs/features/client-last-activity.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | --- | |
| 2 | topic: Hosting forges for others, and getting paid | |
| 3 | row: Each client row says never opened, opened today or last seen N days ago | |
| 4 | --- | |
| 5 | # The client row's last activity (#14672) | |
| 6 | ||
| 7 | Each made forge's row on `/forges` says when a person last did anything in it: **never opened**, **opened today**, **last seen yesterday** or **last seen 3 days ago**. The words come from one function, `lastActivityWords` (`src/spawn/client_words.ts`), reading the `lastActivityAt` the list already loads: no new call. | |
| 8 | ||
| 9 | - One phrase per row: when the row already carries the seen line (sent · opened · last seen), that line says it and these words are left out, on the page and in the terminal (`rowActivityWords`). | |
| 10 | - Days are whole UTC days (23:59 yesterday is yesterday, 00:01 today is today). A time in the future reads as today; a value that is not a time reads as never opened. | |
| 11 | - The terminal client list (`/forges` screen) shows the same words to the sender, and only to the sender, as the page does (the page is the sender's own list). They replace the older "a person last did something …" line, which a guest in the terminal still gets; the exact time is the span's `title` on the page. | |
| 12 | ||
| 13 | Tests: `test/client-seen.test.ts`. |
src/spawn/client_words.ts +24
| @@ -31,3 +31,27 @@ export function clientLines(rows: readonly ClientRow[]): ClientLine[] { | ||
| 31 | 31 | }; |
| 32 | 32 | }); |
| 33 | 33 | } |
| 34 | ||
| 35 | const DAY_MS = 86_400_000; | |
| 36 | ||
| 37 | /** | |
| 38 | * What the owner reads in the client row about the forge's own last activity: "never opened", | |
| 39 | * "opened today" or "last seen 3 days ago". Days are whole UTC days; a time in the future (a clock | |
| 40 | * that runs ahead) reads as today, and a value that is not a time reads as never opened. | |
| 41 | */ | |
| 42 | export function lastActivityWords(lastActivityAt: string | null, now: number): string { | |
| 43 | const at = lastActivityAt === null ? NaN : Date.parse(lastActivityAt); | |
| 44 | if (!Number.isFinite(at)) return "never opened"; | |
| 45 | const days = Math.floor(now / DAY_MS) - Math.floor(at / DAY_MS); | |
| 46 | if (days <= 0) return "opened today"; | |
| 47 | if (days === 1) return "last seen yesterday"; | |
| 48 | return `last seen ${days} days ago`; | |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * The row's one last-activity phrase, or null: a forge not made yet has none, and when the seen | |
| 53 | * line ("sent · opened · last seen") is on the row it already says it, so nothing says it twice. | |
| 54 | */ | |
| 55 | export function rowActivityWords(r: Pick<ClientRow, "made" | "lastActivityAt">, seenOnRow: boolean, now: number): string | null { | |
| 56 | return !r.made || seenOnRow ? null : lastActivityWords(r.lastActivityAt, now); | |
| 57 | } |
src/tui/screens/forges.ts +13 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | import type { Ctx, Screen } from "../app/app.ts"; |
| 8 | 8 | import { binding } from "../app/keys.ts"; |
| 9 | import { rowActivityWords } from "../../spawn/client_words.ts"; | |
| 9 | 10 | import { ATTENTION_WORDS, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, seenOf, seenParts, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts"; |
| 10 | 11 | import { useLine } from "../../spawn/usage.ts"; |
| 11 | 12 | import { timeAgo } from "../../web/ui.ts"; |
| @@ -35,12 +36,23 @@ export function forgeLines(rows: readonly ClientRow[], sender = false, now = Dat | ||
| 35 | 36 | if (rows.length === 0) return [["", "You have not sent a forge yet"]]; |
| 36 | 37 | return rows.flatMap((r): [string, string][] => [[ |
| 37 | 38 | r.name, |
outdated
The sender branch now shows |
||
| 38 | [r.made ? (r.awake === true ? "awake" : "asleep") : null, r.made && r.where.inProcess ? r.where.says : null, r.stopped ?? null, crewHeldWords(r), r.attention === null ? null : ATTENTION_WORDS[r.attention], r.for === null ? null : `for ${r.for}`, CLAIM_WORDS[claimState(r)], linkWords(r.link, claimState(r) === "no" ? now : null), runningWords(r), seenLine(r, sender) !== null && r.stage?.key !== "tell" && r.stage?.resend !== true ? null : r.stage?.words ?? null, seenLine(r, sender), r.nextStep.words, spendWords(r)?.words ?? null, monthWords(r)?.words ?? null, creditWords(r), graceWords(r), useLine(r.size, r.use), r.made ? diskWords(r.disk) : null, r.made && seenLine(r, sender) === null ? (r.lastActivityAt === null ? "no person has done anything here" : `a person last did something ${timeAgo(r.lastActivityAt)}`) : null, claimedWords(r), keepWords(r), r.archive === null || r.archive === undefined ? null : `proposed for archive: ${r.archive.why}`, r.lastHeartbeatAt === null ? "no heartbeat yet" : `heartbeat ${timeAgo(r.lastHeartbeatAt)}`] | |
| 39 | [r.made ? (r.awake === true ? "awake" : "asleep") : null, r.made && r.where.inProcess ? r.where.says : null, r.stopped ?? null, crewHeldWords(r), r.attention === null ? null : ATTENTION_WORDS[r.attention], r.for === null ? null : `for ${r.for}`, CLAIM_WORDS[claimState(r)], linkWords(r.link, claimState(r) === "no" ? now : null), runningWords(r), seenLine(r, sender) !== null && r.stage?.key !== "tell" && r.stage?.resend !== true ? null : r.stage?.words ?? null, seenLine(r, sender), r.nextStep.words, spendWords(r)?.words ?? null, monthWords(r)?.words ?? null, creditWords(r), graceWords(r), useLine(r.size, r.use), r.made ? diskWords(r.disk) : null, activityPiece(r, sender, now), claimedWords(r), keepWords(r), r.archive === null || r.archive === undefined ? null : `proposed for archive: ${r.archive.why}`, r.lastHeartbeatAt === null ? "no heartbeat yet" : `heartbeat ${timeAgo(r.lastHeartbeatAt)}`] | |
| 39 | 40 | .filter((m): m is string => m !== null) |
| 40 | 41 | .join(" · "), |
| 41 | 42 | ], ...firstScreenLines(r), ...appLinkLines(r), ...addressLines(r)]); |
| 42 | 43 | } |
| 43 | 44 | |
| 45 | /** | |
| 46 | * The row's one last-activity phrase: the sender reads the page's words unless the seen line | |
| 47 | * already says it; a guest, who never gets the seen line, keeps the older "a person last did | |
| 48 | * something". | |
| 49 | */ | |
| 50 | function activityPiece(r: ClientRow, sender: boolean, now: number): string | null { | |
| 51 | if (sender) return rowActivityWords(r, seenLine(r, sender) !== null, now); | |
| 52 | if (!r.made) return null; | |
| 53 | return r.lastActivityAt === null ? "no person has done anything here" : `a person last did something ${timeAgo(r.lastActivityAt)}`; | |
| 54 | } | |
| 55 | ||
| 44 | 56 | /** "sent 3d ago · opened 1d ago · last seen 2h ago", as /forges says it; for an admin only. */ |
| 45 | 57 | function seenLine(r: ClientRow, sender: boolean): string | null { |
| 46 | 58 | const seen = sender ? seenOf(r) : null; |
src/web/pages/forges.ts +9 −1
| @@ -35,6 +35,7 @@ import { REACH_SETTINGS, reachByForge, type ForgeReach } from "../../actions/chi | ||
| 35 | 35 | import { forgeReachRows } from "./hosted-forges.ts"; |
| 36 | 36 | import { keptWords, readHosted } from "../../snapshot/hosted.ts"; |
| 37 | 37 | import { archiveForge, archivedForges, restoreForge, type ArchiveRecord } from "../../spawn/archive.ts"; |
| 38 | import { rowActivityWords } from "../../spawn/client_words.ts"; | |
| 38 | 39 | import { CLIENT_STATES, CLIENT_STATE_EMPTY, CLIENT_STATE_WORDS, narrowByState, parseClientState, stateCounts } from "../../spawn/client_state.ts"; |
| 39 | 40 | import { parseClientQuery, searchClients } from "../../spawn/client_search.ts"; |
| 40 | 41 | import { claimedWords, isForgeSort, keepWords, SORT_WORDS, sortForges, type ForgeSort } from "../../spawn/keep_words.ts"; |
| @@ -77,6 +78,12 @@ function seenWords(seen: Seen): Html { | ||
| 77 | 78 | return html`<span data-seen data-opened="${seen.opened ? "yes" : "no"}">${parts.map((p, i) => (i === 0 ? p : html` · ${p}`))}</span>`; |
| 78 | 79 | } |
| 79 | 80 | |
| 81 | /** The row's one last-activity phrase; the exact moment stays in the title. */ | |
| 82 | function activityNote(r: ClientRow, seenOnRow: boolean, now: number): Html | null { | |
| 83 | const words = rowActivityWords(r, seenOnRow, now); | |
| 84 | return words === null ? null : html`<span data-last-activity title="${r.lastActivityAt ?? "no activity yet"}">${words}</span>`; | |
| 85 | } | |
| 86 | ||
| 80 | 87 | const XLARGE_SAYS = `${sizeWords("xlarge")}. ${sizesView().sizes.find((x) => x.size === "xlarge")?.says ?? ""}`; |
| 81 | 88 | |
| 82 | 89 | export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = false, kept?: string): Html { |
| @@ -105,7 +112,8 @@ export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = f | ||
| 105 | 112 | ? null |
| 106 | 113 | : html`<span data-stage="${r.stage.key}"${r.stage.resend ? html` data-resend` : null}>${r.stage.words}${r.stage.at === null ? null : html` ${time(r.stage.at)}`}</span>`, |
| 107 | 114 | seen === null ? null : seenWords(seen), |
| 108 | r.made && seen === null ? (r.lastActivityAt === null ? html`<span data-activity>no one has done anything here yet</span>` : html`<span data-activity>a person last did something ${time(r.lastActivityAt)}</span>`) : null, | |
| 115 | // One phrase for the fact; the exact moment stays in the title. | |
| 116 | activityNote(r, seen !== null, now), | |
| 109 | 117 | claimedWords(r) === null ? null : html`<span data-claimed-by>${claimedWords(r)}</span>`, |
| 110 | 118 | keepWords(r) === null ? null : html`<span data-keep>${keepWords(r)}</span>`, |
| 111 | 119 | r.made && kept !== undefined ? html`<span data-backed-up>${kept}</span>` : null, |
test/client-seen.test.ts added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { lastActivityWords } from "../src/spawn/client_words.ts"; | |
| 3 | import type { ClientRow } from "../src/spawn/clients.ts"; | |
| 4 | import { forgeLines } from "../src/tui/screens/forges.ts"; | |
| 5 | import { forgeRow } from "../src/web/pages/forges.ts"; | |
| 6 | ||
| 7 | const NOW = Date.parse("2026-11-20T12:00:00Z"); | |
| 8 | const DAY = 86_400_000; | |
| 9 | const ago = (ms: number) => new Date(NOW - ms).toISOString(); | |
| 10 | ||
| 11 | const row = (over: Partial<ClientRow>): ClientRow => ({ | |
| 12 | name: "maria", | |
| 13 | placement: "cell", | |
| 14 | where: { placement: "cell", inProcess: false, says: "runs in its own sandbox", movable: false, held: false }, | |
| 15 | url: "https://maria.test", | |
| 16 | for: "Maria's bakery", | |
| 17 | apps: [], | |
| 18 | stage: null, | |
| 19 | sentAt: null, | |
| 20 | made: true, | |
| 21 | claimed: false, | |
outdated
Move these imports to the top of the file. Add a test that renders forgeRow for a made row and expects the data-last-activity span (and its absence for a not-made row); today the page change is untested. |
||
| 22 | lastActivityAt: null, | |
| 23 | running: null, | |
| 24 | reach: null, | |
| 25 | link: null, | |
outdated
Avoid the |
||
| 26 | attention: null, | |
| 27 | spendTodayUsd: null, | |
| 28 | ceilingUsd: null, | |
| 29 | size: "small", | |
| 30 | use: { kind: "shared" }, | |
| 31 | disk: { own: false, path: "/d/children/c" }, | |
| 32 | lastHeartbeatAt: null, | |
| 33 | nextStep: { key: "unreported", words: "has not reported yet", lastTellAt: null }, | |
| 34 | ...over, | |
| 35 | }); | |
| 36 | ||
| 37 | describe("lastActivityWords", () => { | |
| 38 | test("never opened without activity or with a value that is no time", () => { | |
| 39 | expect(lastActivityWords(null, NOW)).toBe("never opened"); | |
| 40 | expect(lastActivityWords("junk", NOW)).toBe("never opened"); | |
| 41 | }); | |
| 42 | test("today, yesterday, days ago", () => { | |
| 43 | expect(lastActivityWords(ago(60_000), NOW)).toBe("opened today"); | |
| 44 | expect(lastActivityWords(ago(DAY), NOW)).toBe("last seen yesterday"); | |
| 45 | expect(lastActivityWords(ago(3 * DAY), NOW)).toBe("last seen 3 days ago"); | |
| 46 | }); | |
| 47 | test("the UTC midnight boundary: 23:59 yesterday is yesterday, 00:01 today is today", () => { | |
| 48 | const midnight = Date.parse("2026-11-20T00:00:00Z"); | |
| 49 | const at = midnight + 2 * 60_000; | |
| 50 | expect(lastActivityWords("2026-11-19T23:59:00Z", at)).toBe("last seen yesterday"); | |
| 51 | expect(lastActivityWords("2026-11-20T00:01:00Z", at)).toBe("opened today"); | |
| 52 | }); | |
| 53 | test("a clock in the future reads as today", () => { | |
| 54 | expect(lastActivityWords(ago(-5 * DAY), NOW)).toBe("opened today"); | |
| 55 | }); | |
| 56 | }); | |
| 57 | ||
| 58 | describe("a row with the seen line says its last activity once", () => { | |
| 59 | const claimed = row({ claimed: true, sentAt: ago(5 * DAY), lastActivityAt: ago(3 * DAY), link: { state: "used", revokedAt: null, usedAt: ago(4 * DAY), openedAt: ago(4 * DAY) } }); | |
| 60 | const count = (s: string) => s.split("last seen").length - 1; | |
| 61 | test("on the page", () => { | |
| 62 | const h = String(forgeRow(claimed, NOW)); | |
| 63 | expect(h).toContain("data-seen"); | |
| 64 | expect(h).not.toContain("data-last-activity"); | |
| 65 | expect(count(h)).toBe(1); | |
| 66 | }); | |
| 67 | test("in the terminal, for the sender", () => { | |
| 68 | const line = forgeLines([claimed], true, NOW)[0]![1]; | |
| 69 | expect(count(line)).toBe(1); | |
| 70 | expect(line).not.toContain("3 days ago"); | |
| 71 | }); | |
| 72 | }); | |
| 73 | ||
| 74 | describe("both doors say the same words, once", () => { | |
| 75 | const r = row({ lastActivityAt: ago(3 * DAY) }); | |
| 76 | test("the web row has the span, with the exact time in the title", () => { | |
| 77 | const h = String(forgeRow(r, NOW)); | |
| 78 | expect(h).toContain("data-last-activity"); | |
| 79 | expect(h).toContain("last seen 3 days ago"); | |
| 80 | expect(h).toContain(`title="${r.lastActivityAt}"`); | |
| 81 | expect(h).not.toContain("a person last did something"); | |
| 82 | expect(h).not.toContain("no one has done anything"); | |
| 83 | }); | |
| 84 | test("a row not made has no span", () => { | |
| 85 | expect(String(forgeRow(row({ made: false }), NOW))).not.toContain("data-last-activity"); | |
| 86 | }); | |
| 87 | test("the terminal says it to the sender, with no second phrase; a guest keeps the old line", () => { | |
| 88 | const line = forgeLines([r], true, NOW)[0]![1]; | |
| 89 | expect(line).toContain("last seen 3 days ago"); | |
| 90 | expect(line).not.toContain("a person last did something"); | |
| 91 | expect(forgeLines([row({})], true, NOW)[0]![1]).toContain("never opened"); | |
| 92 | expect(forgeLines([r], false, NOW)[0]![1]).not.toContain("last seen 3 days ago"); | |
| 93 | }); | |
| 94 | }); |
Both doors: the page shows the phrase for every made row, the terminal only when sender is true, and the doc says 'admin view'. Pick one rule and apply it in both. Same duplicate as the page: the 'no person has done anything here' / 'a person last did something' entry just before it says the same; replace it rather than add beside it.