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

A client list row says in plain words what was sent to the client and when, with no internal state names #16073

Merged opened this

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

Merged

mason/forge:mason/16050-a-client-list-row-says-in-plain-words-wh → main 0 commits fork 6 threads · 6 unresolved

  • Merged. mason/16050-a-client-list-row-says-in-plain-words-wh was merged into main as bf19789.

Review

Sign in to review this change.
11 files changed +145 −19
docs/features/client-row-words.md added +15
@@ -0,0 +1,15 @@
1 ---
2 topic: Agents: MCP, git, or the terminal
3 row: A client row in plain words
4 ---
5 # A client row in plain words
6
7 Each row of the client list says what was sent and when, in one sentence: "Sent the Morning Paper app, 3 days ago".
8 The sentence is built in `sentWords` (`src/spawn/client_words.ts`), so the page and the terminal read the same.
9
10 - Page: open `/forges`; the sentence leads the row, and the raw app slugs are not repeated beside it.
11 - Terminal: the forges screen opens each row with the same sentence.

Non-blocking: say the terminal shows the sentence to the sender only, never to a guest.

12 - When the send time is missing or still to come, the row says only what was sent.
13 - The old "sent …" part of the opened/last seen line is gone: the sentence says it.
14 - No internal word (listed in `test/client-words-plain.test.ts`) may appear in a row; `test/client-words-plain.test.ts` renders the whole
15 row on the page and in the terminal and checks it against that list.
src/http/mcp/tools/forges.ts +1 −1
@@ -39,7 +39,7 @@ export const tool: Tool = {
3939 }
4040 if (args["kind"] !== undefined) {
4141 if (args["kind"] === "clients") {
42 const lines = clientLines(await clientRows(ctx.app));
42 const lines = clientLines(await clientRows(ctx.app), Date.now());
4343 return good({ says: sentSays(lines.length), clients: lines });
4444 }
4545 if (args["kind"] !== "refused") return bad("invalid", "kind is refused or clients");
src/spawn/client_words.ts +28 −1
@@ -21,9 +21,11 @@ export interface ClientLine {
2121 tellAt: string | null;
2222 pulls: number | null;
2323 next: string;
24 /** "Sent the Morning Paper app, 3 days ago": what went to the client and when, in plain words. */
25 says: string | null;
2426 }
2527
26 export function clientLines(rows: readonly ClientRow[]): ClientLine[] {
28 export function clientLines(rows: readonly ClientRow[], now: number = Date.now()): ClientLine[] {
2729 return rows.map((r) => {
2830 const seen = seenOf(r);
2931 return {
@@ -39,6 +41,7 @@ export function clientLines(rows: readonly ClientRow[]): ClientLine[] {
3941 tellAt: r.stage?.key === "crew" ? r.nextStep.lastTellAt : null,
4042 pulls: r.crew?.pulls ?? null,
4143 next: r.nextStep.key === "going" && r.nextStep.lastTellAt ? `going: last tell ${r.nextStep.lastTellAt}` : r.nextStep.words,
44 says: sentWords(r, now),
4245 };
4346 });
4447 }
@@ -66,3 +69,27 @@ export function lastActivityWords(lastActivityAt: string | null, now: number): s
6669 export function rowActivityWords(r: Pick<ClientRow, "made" | "lastActivityAt">, seenOnRow: boolean, now: number): string | null {
6770 return !r.made || seenOnRow ? null : lastActivityWords(r.lastActivityAt, now);
6871 }
72
73 const titleCase = (slug: string): string => slug.split(/[-_\s]+/).filter((w) => w !== "").map((w) => w[0]!.toUpperCase() + w.slice(1)).join(" ");
74
75 function listWords(names: readonly string[]): string {
76 if (names.length <= 1) return names[0] ?? "";
77 return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
78 }
79
80 /**
81 * What was sent to the client and when, as the row says it: "Sent the Morning Paper app, 3 days
82 * ago". Days are whole UTC days; a send with no usable time (or one in the future) says only what
83 * was sent, and a forge not made yet has no sentence.
84 */
85 export function sentWords(r: Pick<ClientRow, "made" | "apps" | "sentAt">, now: number): string | null {
86 if (!r.made) return null;
87 const names = r.apps.map(titleCase).filter((n) => n !== "");
88 const what = names.length === 0 ? "a forge of their own" : names.length === 1 ? `the ${names[0]} app` : `the ${listWords(names)} apps`;
89 const at = r.sentAt === null ? NaN : Date.parse(r.sentAt);
90 const days = Math.floor(now / DAY_MS) - Math.floor(at / DAY_MS);
91 // A time that is not one, or that is still to come, is not said: only what was sent.
92 if (!Number.isFinite(at) || days < 0) return `Sent ${what}`;
93 const when = days <= 0 ? "today" : days === 1 ? "yesterday" : `${days} days ago`;
94 return `Sent ${what}, ${when}`;
95 }
src/spawn/clients.ts −1
@@ -772,7 +772,6 @@ export function seenOf(r: Pick<ClientRow, "made" | "claimed" | "sentAt" | "first
772772 /** The one line as parts to join with " · ": the words, and the instant to say beside them. */
773773 export function seenParts(s: Seen): { words: string; at: string | null }[] {
774774 return [
775 ...(s.sentAt === null ? [] : [{ words: "sent", at: s.sentAt }]),
776775 s.opened ? { words: s.openedAt === null ? "opened (time not noted)" : "opened", at: s.openedAt } : { words: "opened: not yet", at: null },
777776 // Nothing while unknown (undefined); "not yet" only once the child has said there is none.
778777 ...(s.firstTellAt === undefined ? [] : [s.firstTellAt === null ? { words: "first tell: not yet", at: null } : { words: "first tell", at: s.firstTellAt }]),
src/tui/screens/forges.ts +2 −2
@@ -6,7 +6,7 @@
66
77 import type { Ctx, Screen } from "../app/app.ts";
88 import { binding } from "../app/keys.ts";
9 import { rowActivityWords } from "../../spawn/client_words.ts";
9 import { rowActivityWords, sentWords } from "../../spawn/client_words.ts";
1010 import { ATTENTION_WORDS, crewCountWords, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, seenOf, seenParts, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts";
1111 import { useLine } from "../../spawn/usage.ts";
1212 import { timeAgo } from "../../web/ui.ts";
@@ -38,7 +38,7 @@ export function forgeLines(rows: readonly ClientRow[], sender = false, now = Dat
3838 if (rows.length === 0) return [["", "You have not sent a forge yet"]];
3939 return rows.flatMap((r): [string, string][] => [[
4040 r.name,
41 [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?.key !== "crew" && r.stage?.resend !== true ? null : r.stage?.words ?? null, r.stage?.key === "crew" && r.nextStep.lastTellAt !== null ? `last tell ${timeAgo(r.nextStep.lastTellAt)}` : null, crewCountWords(r.crew), 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)}`]
41 [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], sender ? sentWords(r, now) : null, 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?.key !== "crew" && r.stage?.resend !== true ? null : r.stage?.words ?? null, r.stage?.key === "crew" && r.nextStep.lastTellAt !== null ? `last tell ${timeAgo(r.nextStep.lastTellAt)}` : null, crewCountWords(r.crew), 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 ? "not checked in yet" : `checked in ${timeAgo(r.lastHeartbeatAt)}`]
outdated

High: sentWords(r, now) is not gated on sender. The terminal withholds the send time from guests (seenLine only reads seenOf when sender), so this exposes it to them. Use sender ? sentWords(r, now) : null and add a guest test.

4242 .filter((m): m is string => m !== null)
4343 .join(" · "),
4444 ], ...firstScreenLines(r), ...appLinkLines(r), ...addressLines(r)]);
src/web/pages/forges.ts +3 −2
@@ -37,7 +37,7 @@ import { REACH_SETTINGS, reachByForge, type ForgeReach } from "../../actions/chi
3737 import { forgeReachRows } from "./hosted-forges.ts";
3838 import { keptWords, readHosted } from "../../snapshot/hosted.ts";
3939 import { archiveForge, archivedForges, restoreForge, type ArchiveRecord } from "../../spawn/archive.ts";
40 import { rowActivityWords } from "../../spawn/client_words.ts";
40 import { rowActivityWords, sentWords } from "../../spawn/client_words.ts";
4141 import { CLIENT_STATES, CLIENT_STATE_EMPTY, CLIENT_STATE_WORDS, narrowByState, parseClientState, stateCounts } from "../../spawn/client_state.ts";
4242 import { weekLine } from "../../spawn/client_week.ts";
4343 import { parseClientQuery, searchClients } from "../../spawn/client_search.ts";
@@ -93,9 +93,10 @@ export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = f
9393 const state = claimState(r);
9494 const daysLeft = state === "no" ? daysLeftWords(r.link, now) : null;
9595 const seen = seenOf(r);
96 const sentSays = sentWords(r, now);
9697 const meta = [
98 sentSays === null ? null : html`<span data-sent-says>${sentSays}</span>`,

Principle 1 and 8: this sentence duplicates what the sent/opened/last seen line and the apps list below already say, and the row still carries internal state words. Replace them, not add.

9799 r.for === null ? null : html`for ${r.for}`,
98 r.apps.length === 0 ? null : html`${r.apps.join(", ")}`,
99100 appLinkSummary(r.appLinks ?? []) === null ? null : html`<span data-app-links>${appLinkSummary(r.appLinks ?? [])}</span>`,
outdated

Principle 1: raw slugs repeat the apps the sentence already names. Remove.

100101 state === "unknown" ? html`it did not answer just now` : null,
101102 crewHeldWords(r) === null ? null : html`<span data-crew-held="${NO_KEY_HELD}">${crewHeldWords(r)}</span>`,
test/client-list-events.test.ts +1 −1
@@ -27,7 +27,7 @@ const words = (r: ClientRow) => seenParts(seenOf(r)!).map((p) => `${p.words}${p.
2727 describe("the client list's three times", () => {
2828 test("empty ones say not yet", () => {
2929 const w = words(row({ claimed: false, firstTellAt: null, link: { state: "open", revokedAt: null, usedAt: null, openedAt: null } }));
30 expect(w).toEqual(["sent 2026-11-01T00:00:00.000Z", "opened: not yet", "first tell: not yet"]);
30 expect(w).toEqual(["opened: not yet", "first tell: not yet"]);
3131 });
3232
3333 test("a first tell not yet reported says nothing, not \"not yet\"", () => {
test/client-list.test.ts +2 −3
@@ -206,10 +206,9 @@ describe("the client list", () => {
206206 const maria = html.slice(html.indexOf('data-forge="maria"'));
207207 expect(maria).toContain("Maria&#39;s bakery");
208208 expect(maria).toContain("alice/bakery");
209 // One plain line first: for whom, then the apps; the state facts follow.
209 // One plain line first: what was sent and for whom; the state facts follow.
210210 const line = maria.slice(0, maria.indexOf("</li>"));
211 expect(line.indexOf("Maria&#39;s bakery")).toBeLessThan(line.indexOf("alice/bakery"));
212 expect(line.indexOf("alice/bakery")).toBeLessThan(line.indexOf("has not reported yet"));
211 expect(line.indexOf("Maria&#39;s bakery")).toBeLessThan(line.indexOf("has not reported yet"));
213212 expect(line).not.toContain('class="card');
214213 expect(maria).toContain('href="https://maria--forge.test"');
215214 expect(maria).toMatch(/data-claimed="no"/);
test/client-words-plain.test.ts added +83
@@ -0,0 +1,83 @@
1 import { describe, expect, test } from "bun:test";
2 import { clientLines, sentWords } from "../src/spawn/client_words.ts";
3 import { clientsCsv, CLIENTS_CSV_HEADER } from "../src/spawn/clients_csv.ts";
4 import type { ClientRow } from "../src/spawn/clients.ts";
5 import { forgeLines } from "../src/tui/screens/forges.ts";
6 import { forgeRow } from "../src/web/pages/forges.ts";
7
8 const INTERNAL_WORDS: readonly string[] = ["stage", "signedin", "unreported", "attention", "silent", "nextstep", "heartbeat", "null", "undefined"];
9
10 /** The first internal word in the text (whole words, any case), or null when it has none. */
11 function internalWordIn(text: string): string | null {
12 const lower = text.toLowerCase();
13 return INTERNAL_WORDS.find((w) => new RegExp(`\\b${w}\\b`).test(lower)) ?? null;
14 }
15
16 const NOW = Date.parse("2026-11-20T12:00:00Z");
17 const DAY = 86_400_000;
18 const ago = (ms: number) => new Date(NOW - ms).toISOString();
19
20 const row = (over: Partial<ClientRow> = {}): ClientRow =>
outdated

This list is only applied to the new sentence, which cannot contain these words, so the test cannot fail. Apply it to the full row on the page and in the terminal, and share the list.

21 ({
22 name: "maria", placement: "cell", where: { placement: "cell", inProcess: false, says: "runs in its own sandbox", movable: false, held: false },
23 url: "https://maria.test", for: "Maria", apps: ["morning-paper"], stage: null, sentAt: ago(3 * DAY), made: true, claimed: false,
24 lastActivityAt: null, running: null, reach: null, link: null, attention: null, spendTodayUsd: null, ceilingUsd: null, size: "small",
25 use: { kind: "shared" }, disk: { own: false, path: "/d/children/c" }, lastHeartbeatAt: null,
26 nextStep: { key: "unreported", words: "has not reported yet", lastTellAt: null }, ...over,
27 }) as ClientRow;
28
29 describe("a row says what was sent and when", () => {
30 test("reads like a sentence", () => {
31 expect(sentWords(row(), NOW)).toBe("Sent the Morning Paper app, 3 days ago");
32 expect(sentWords(row({ sentAt: ago(DAY) }), NOW)).toBe("Sent the Morning Paper app, yesterday");
33 expect(sentWords(row({ sentAt: ago(60_000) }), NOW)).toBe("Sent the Morning Paper app, today");
34 expect(sentWords(row({ apps: ["a-b", "cafe"] }), NOW)).toBe("Sent the A B and Cafe apps, 3 days ago");
35 expect(sentWords(row({ apps: [] }), NOW)).toBe("Sent a forge of their own, 3 days ago");
36 expect(sentWords(row({ sentAt: null }), NOW)).toBe("Sent the Morning Paper app");
37 expect(sentWords(row({ made: false }), NOW)).toBeNull();
38 });
39
40 test("a send time still to come is not said", () => {
41 expect(sentWords(row({ sentAt: ago(-3 * DAY) }), NOW)).toBe("Sent the Morning Paper app");
42 });
43
44 test("no internal word appears anywhere in the whole row, on the page or in the terminal", () => {
45 const link = { state: "used", usedAt: ago(DAY), openedAt: ago(DAY), revokedAt: null } as ClientRow["link"];
46 const states = [
47 row(), row({ claimed: true }), row({ claimed: null }), row({ sentAt: "junk" }), row({ apps: [] }), row({ made: false }),
48 row({ claimed: true, link, lastActivityAt: ago(DAY), lastHeartbeatAt: ago(60_000) }),
49 row({ link: { state: "open", usedAt: null, openedAt: null, revokedAt: null } as ClientRow["link"] }),
50 ];
51 for (const r of states) {
52 const page = forgeRow(r, NOW).toString().replace(/<[^>]*>/g, " ");
53 const term = forgeLines([r], true, NOW).map((l) => l.join(" ")).join(" ");
54 expect(internalWordIn(page)).toBeNull();
55 expect(internalWordIn(term)).toBeNull();
56 }
57 });
58
59 test("the row says what was sent once, and shows no raw app name beside it", () => {
60 const page = forgeRow(row(), NOW).toString();
61 const meta = page.slice(page.indexOf("row-meta"), page.indexOf("row-trail"));
62 expect(meta.split("Morning Paper").length - 1).toBe(1);
63 expect(meta).not.toContain("morning-paper");
64 expect(page).not.toMatch(/sent \d/i);
65 });
66
67 test("the terminal says it to the sender and never to a guest", () => {
68 expect(forgeLines([row()], true, NOW)[0]![1]).toContain("Sent the Morning Paper app, 3 days ago");
69 const guest = forgeLines([row()], false, NOW).map((l) => l.join(" ")).join(" ");
70 expect(guest).not.toContain("Sent");
71 expect(guest).not.toContain("Morning Paper");
72 });
73
74 test("the page row and the client lines carry it", () => {
75 expect(forgeRow(row(), NOW).toString()).toContain("Sent the Morning Paper app, 3 days ago");
76 expect(clientLines([row()], NOW)[0]!.says).toBe("Sent the Morning Paper app, 3 days ago");
77 });
78
79 test("the CSV keeps its columns", () => {
80 expect(CLIENTS_CSV_HEADER).toEqual(["client", "forge", "sent at", "state", "last seen"]);
81 expect(clientsCsv([row()]).split(/\r?\n/)[0]).toBe("client,forge,sent at,state,last seen");
82 });
83 });
test/tui-forges.test.ts +6 −4
@@ -270,7 +270,7 @@ describe("forges you sent in the terminal", () => {
270270 expect(line).toContain("memory 310 MiB of 512 MiB");
271271 expect(line).toContain("cpu 0.4 of 1 core");
272272 expect(line).toContain("disk 100 MiB of 2 GiB");
273 expect(line).toContain("heartbeat just now");
273 expect(line).toContain("checked in just now");
274274 const idle = row({ size: "small", use: { kind: "idle", limits: { cpu: 1, memoryMiB: 512, diskMiB: 2048 } } });
275275 expect(forgeLines([idle])[0]![1]).toContain("memory not running");
276276 });
@@ -279,20 +279,22 @@ describe("forges you sent in the terminal", () => {
279279 const up = { total: 3, running: 3, notRunning: [] };
280280 const down = { total: 2, running: 1, notRunning: [{ slug: "notes", why: "build failed" }] };
281281 expect(forgeLines([row({ running: up })])).toEqual([
282 ["maria", "asleep · for Maria's bakery · Not claimed yet · 3 apps running · has not reported yet · small · shared · shared disk · no person has done anything here · disk measuring · no memory (asleep) · no credit lent · no heartbeat yet"],
282 ["maria", "asleep · for Maria's bakery · Not claimed yet · 3 apps running · has not reported yet · small · shared · shared disk · no person has done anything here · disk measuring · no memory (asleep) · no credit lent · not checked in yet"],
outdated

These rows are built with the default sender=false and expect 'Sent a forge of their own', so the leak is pinned as correct. Expect the sentence only with sender=true, and its absence for a guest.

283283 ["", ` ${firstScreenLine([])}`],
284284 ]);
285285 expect(forgeLines([row({ claimed: true, running: down, for: null })])).toEqual([
286 ["maria", "asleep · Claimed · 1 app running · notes: build failed · has not reported yet · small · shared · shared disk · no person has done anything here · disk measuring · no memory (asleep) · no credit lent · no heartbeat yet"],
286 ["maria", "asleep · Claimed · 1 app running · notes: build failed · has not reported yet · small · shared · shared disk · no person has done anything here · disk measuring · no memory (asleep) · no credit lent · not checked in yet"],
287287 ]);
288288 expect(forgeLines([row({ claimed: null })])[0]![1]).toContain("Unknown");
289289 expect(forgeLines([row({ made: false })])[0]![1]).toContain("Still being made");
290290 expect(forgeLines([row({ attention: "down", claimed: true, for: null })])).toEqual([
291 ["maria", "asleep · App down · Claimed · has not reported yet · small · shared · shared disk · no person has done anything here · disk measuring · no memory (asleep) · no credit lent · no heartbeat yet"],
291 ["maria", "asleep · App down · Claimed · has not reported yet · small · shared · shared disk · no person has done anything here · disk measuring · no memory (asleep) · no credit lent · not checked in yet"],
292292 ]);
293293 expect(forgeLines([row({})])[0]![1]).not.toMatch(/Not reporting|App down|Unclaimed/);
294294 expect(forgeLines([row({ nextStep: { key: "tell", words: "no tell yet", lastTellAt: null } })])[0]![1]).toContain("no tell yet");
295295 expect(JSON.stringify(forgeLines([row({})]))).not.toContain("http");
296 expect(forgeLines([row({})], true)[0]![1]).toContain("Sent a forge of their own");
297 expect(forgeLines([row({})])[0]![1]).not.toContain("Sent");
296298 expect(runningWords(row({ running: { total: 0, running: 0, notRunning: [] } }))).toBeNull();
297299 });
298300 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs