Public: anyone can read this; the crew can change it.
Revert "A forge link that is about to expire says so to its owner, and renews in one tap" #14217
Check · Review · Land · Live — No review yet.
revert-14175 → main 1 commit
7 files
changed +12
−79
docs/features/client-link-times.md −4
| @@ -11,7 +11,3 @@ Each forge row for a link says **sent**, **opened** and **first tell**, each fro | ||
| 11 | 11 | A child that has not sent a heartbeat carrying `firstTellAt` is unknown, not empty, so its row says nothing about first tell rather than a false "not yet". The line appears at its next heartbeat. Only a beat that says `firstTellAt: null` reads "not yet". |
| 12 | 12 | |
| 13 | 13 | Tests: `test/client-list-events.test.ts` (the line, the parse, the earliest issue) and `test/client-list.test.ts` (a beat through `clientRows` onto the page). |
| 14 | ||
| 15 | ## Days left on an unclaimed link (#14155) | |
| 16 | ||
| 17 | An unclaimed forge's row says how long its open link has: "3 days left", "1 day left", "expires today" (`daysLeftWords`, `src/spawn/clients.ts`, read from the link's own expiry the child reports). The terminal's row says the same (`link open, 3 days left`). An expired link answers its person a plain page naming who to ask, with "Ask for a new link"; the owner's "Send a new link" (or "Resend") on the row issues a fresh one and ends the old at once (`test/forge-link-reissue.test.ts`, `test/client-link-days-left.test.ts`). |
src/spawn/clients.ts +2 −18
| @@ -234,11 +234,10 @@ const LINK_STATES: readonly LinkState[] = ["open", "used", "ended"]; | ||
| 234 | 234 | /** The link a child reported, or null when it said nothing usable. */ |
| 235 | 235 | function linkOfBody(v: unknown): LinkInfo | null { |
| 236 | 236 | if (typeof v !== "object" || v === null) return null; |
| 237 | const { state, revokedAt, usedAt, openedAt, expiresAt } = v as Record<string, unknown>; | |
| 237 | const { state, revokedAt } = v as Record<string, unknown>; | |
| 238 | 238 | if (!LINK_STATES.includes(state as LinkState)) return null; |
| 239 | 239 | const iso = (x: unknown): string | null => (typeof x === "string" && !Number.isNaN(Date.parse(x)) ? x : null); |
| 240 | const expires = iso(expiresAt); | |
| 241 | return { state: state as LinkState, revokedAt: iso(revokedAt), usedAt: iso(usedAt), openedAt: iso(openedAt), ...(expires === null ? {} : { expiresAt: expires }) }; | |
| 240 | return { state: state as LinkState, revokedAt: iso(revokedAt), usedAt: iso((v as Record<string, unknown>)["usedAt"]), openedAt: iso((v as Record<string, unknown>)["openedAt"]) }; | |
| 242 | 241 | } |
| 243 | 242 | |
| 244 | 243 | async function probe(app: App, child: Child): Promise<ForgeState | undefined> { |
| @@ -651,21 +650,6 @@ export function attentionOf(r: ClientRow, now: number): Attention | null { | ||
| 651 | 650 | return null; |
| 652 | 651 | } |
| 653 | 652 | |
| 654 | /** | |
| 655 | * "3 days left", "expires today", or "expired": the days an open link has, from its own expiry; | |
| 656 | * null when the link is spent, withdrawn or did not say. Whole days, rounded up, so the last day | |
| 657 | * reads "1 day left" until the final hours say "expires today". | |
| 658 | */ | |
| 659 | export function daysLeftWords(link: LinkInfo | null, now: number): string | null { | |
| 660 | if (link === null || link.expiresAt === undefined || link.state === "used" || link.revokedAt !== null) return null; | |
| 661 | const left = Date.parse(link.expiresAt) - now; | |
| 662 | if (Number.isNaN(left)) return null; | |
| 663 | if (left <= 0) return "expired"; | |
| 664 | if (left < 24 * 3_600_000) return "expires today"; | |
| 665 | const days = Math.ceil(left / 86_400_000); | |
| 666 | return days === 1 ? "1 day left" : `${days} days left`; | |
| 667 | } | |
| 668 | ||
| 669 | 653 | export type StageKey = "sent" | "opened" | "signedin" | "tell"; |
| 670 | 654 | |
| 671 | 655 | /** Where a sent link stands, the time that changed, and whether it is time to send it again. */ |
src/tui/screens/forges.ts +5 −8
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | import type { Ctx, Screen } from "../app/app.ts"; |
| 8 | 8 | import { binding } from "../app/keys.ts"; |
| 9 | import { ATTENTION_WORDS, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, seenOf, seenParts, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts"; | |
| 9 | import { ATTENTION_WORDS, firstScreenOf, CLAIM_WORDS, claimState, seenOf, seenParts, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts"; | |
| 10 | 10 | import { useLine } from "../../spawn/usage.ts"; |
| 11 | 11 | import { timeAgo } from "../../web/ui.ts"; |
| 12 | 12 | import { card } from "../ui/widgets.ts"; |
| @@ -29,11 +29,11 @@ import { appLinkSummary, appLinkWords } from "../../spawn/app_links.ts"; | ||
| 29 | 29 | /** |
| 30 | 30 | * [name, "Not reporting · for Maria · Claimed · 3 apps running"] per row; an empty line when none. |
| 31 | 31 | */ |
| 32 | export function forgeLines(rows: readonly ClientRow[], sender = false, now = Date.now()): [string, string][] { | |
| 32 | export function forgeLines(rows: readonly ClientRow[], sender = false): [string, string][] { | |
| 33 | 33 | if (rows.length === 0) return [["", "You have not sent a forge yet"]]; |
| 34 | 34 | return rows.flatMap((r): [string, string][] => [[ |
| 35 | 35 | r.name, |
| 36 | [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)}`] | |
| 36 | [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), 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)}`] | |
| 37 | 37 | .filter((m): m is string => m !== null) |
| 38 | 38 | .join(" · "), |
| 39 | 39 | ], ...firstScreenLines(r), ...appLinkLines(r), ...addressLines(r)]); |
| @@ -49,12 +49,9 @@ function seenLine(r: ClientRow, sender: boolean): string | null { | ||
| 49 | 49 | * "link open", "link ended (undo with u)": what the sender can do about the link, as /forges shows |
| 50 | 50 | * it. |
| 51 | 51 | */ |
| 52 | function linkWords(link: LinkInfo | null, now: number | null = null): string | null { | |
| 52 | function linkWords(link: LinkInfo | null): string | null { | |
| 53 | 53 | if (link === null || link.state === "used") return null; |
| 54 | const left = now === null ? null : daysLeftWords(link, now); | |
| 55 | if (left === "expired") return "link expired, press n for a new one"; | |
| 56 | if (link.state === "open") return left === null ? "link open" : `link open, ${left}`; | |
| 57 | return undoable(link) ? "link ended, undo with u" : "link ended"; | |
| 54 | return link.state === "open" ? "link open" : undoable(link) ? "link ended, undo with u" : "link ended"; | |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | /** Under a forge not yet claimed: what its person will see first, as /forges says it. */ |
src/web/pages/forges.ts +3 −6
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | import type { Ctx } from "../../http/context.ts"; |
| 10 | 10 | import { claimsBill } from "../../actions/forge_bill.ts"; |
| 11 | 11 | import { billRow } from "./bills.ts"; |
| 12 | import { ATTENTION_WORDS, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, memoryOf, seenOf, seenParts, type Seen, servedRows, dropServed, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts"; | |
| 12 | import { ATTENTION_WORDS, firstScreenOf, CLAIM_WORDS, claimState, memoryOf, seenOf, seenParts, type Seen, servedRows, dropServed, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts"; | |
| 13 | 13 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| 14 | 14 | import { notFoundPage, pageHead } from "../chrome.ts"; |
| 15 | 15 | import { html, type Html } from "../html.ts"; |
| @@ -79,7 +79,6 @@ const XLARGE_SAYS = `${sizeWords("xlarge")}. ${sizesView().sizes.find((x) => x.s | ||
| 79 | 79 | |
| 80 | 80 | export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = false, kept?: string): Html { |
| 81 | 81 | const state = claimState(r); |
| 82 | const daysLeft = state === "no" ? daysLeftWords(r.link, now) : null; | |
| 83 | 82 | const seen = seenOf(r); |
| 84 | 83 | const meta = [ |
| 85 | 84 | r.for === null ? null : html`for ${r.for}`, |
| @@ -144,14 +143,12 @@ export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = f | ||
| 144 | 143 | : html`<span data-attention="${r.attention}">${badge(ATTENTION_WORDS[r.attention], { tone: "attn" })}</span>`}${badge(CLAIM_WORDS[state], { |
| 145 | 144 | ...(state === "yes" ? { tone: "success" as const } : { variant: "outline" as const }), |
| 146 | 145 | })}${state === "no" |
| 147 | ? daysLeft !== null && r.link?.state === "open" | |
| 148 | ? html`<form method="post" action="/forges/${r.name}/claim-link" class="inline">${btn("Renew link", { size: "sm", title: "Issue a fresh link now and end the old one; shown once, on the next page" })}</form>` | |
| 149 | : btn(r.stage?.resend === true ? "Resend" : "Send a new link", { size: "sm", href: `/forges/${r.name}/claim-link`, title: "See who it is for and what stops working, then confirm" }) | |
| 146 | ? btn(r.stage?.resend === true ? "Resend" : "Send a new link", { size: "sm", href: `/forges/${r.name}/claim-link`, title: "See who it is for and what stops working, then confirm" }) | |
| 150 | 147 | : null}${state === "yes" && r.made |
| 151 | 148 | ? btn("Recovery link", { size: "sm", href: `/forges/${r.name}/recovery-link`, title: "For an owner who lost their passkey: see what it does, then confirm" }) |
| 152 | 149 | : null}${r.link === null |
| 153 | 150 | ? null |
| 154 | : html`<span data-link="${r.link.state}">${badge(LINK_WORDS[r.link.state], { variant: "outline" as const })}</span>${state === "no" && daysLeft !== null ? html`<span data-days-left class="muted">${daysLeft}</span>` : null}${r.link.state === "open" | |
| 151 | : html`<span data-link="${r.link.state}">${badge(LINK_WORDS[r.link.state], { variant: "outline" as const })}</span>${r.link.state === "open" | |
| 155 | 152 | ? html`<form method="post" action="/forges/${r.name}/revoke-link" class="inline">${btn("Revoke", { size: "sm", title: "End this link now; you can undo for a minute" })}</form>` |
| 156 | 153 | : undoable(r.link, now) |
| 157 | 154 | ? html`<form method="post" action="/forges/${r.name}/undo-link" class="inline">${btn("Undo", { size: "sm", title: "Bring the link back; possible for a minute after it ended" })}</form>` |
test/client-link-days-left.test.ts deleted −28
| @@ -1,28 +0,0 @@ | ||
| 1 | /** An unclaimed link says how long it has left (#14155); renew and expiry have their own tests. */ | |
| 2 | import { describe, expect, test } from "bun:test"; | |
| 3 | import { daysLeftWords } from "../src/spawn/clients.ts"; | |
| 4 | ||
| 5 | const NOW = Date.parse("2026-11-16T12:00:00Z"); | |
| 6 | const at = (ms: number) => new Date(NOW + ms).toISOString(); | |
| 7 | const H = 3_600_000; | |
| 8 | const link = (over: object) => ({ state: "open" as const, revokedAt: null, expiresAt: at(3 * 24 * H), ...over }); | |
| 9 | ||
| 10 | describe("days left on a link", () => { | |
| 11 | test("counts whole days, rounded up, then says today, then expired", () => { | |
| 12 | expect(daysLeftWords(link({}), NOW)).toBe("3 days left"); | |
| 13 | expect(daysLeftWords(link({ expiresAt: at(2 * 24 * H + H) }), NOW)).toBe("3 days left"); | |
| 14 | expect(daysLeftWords(link({ expiresAt: at(30 * H) }), NOW)).toBe("2 days left"); | |
| 15 | expect(daysLeftWords(link({ expiresAt: at(25 * H) }), NOW)).toBe("2 days left"); | |
| 16 | expect(daysLeftWords(link({ expiresAt: at(24 * H) }), NOW)).toBe("1 day left"); | |
| 17 | expect(daysLeftWords(link({ expiresAt: at(5 * H) }), NOW)).toBe("expires today"); | |
| 18 | expect(daysLeftWords(link({ expiresAt: at(-H), state: "ended" }), NOW)).toBe("expired"); | |
| 19 | }); | |
| 20 | ||
| 21 | test("says nothing for a spent, withdrawn or unreported link", () => { | |
| 22 | expect(daysLeftWords(null, NOW)).toBeNull(); | |
| 23 | expect(daysLeftWords(link({ state: "used" }), NOW)).toBeNull(); | |
| 24 | expect(daysLeftWords(link({ state: "ended", revokedAt: at(-H) }), NOW)).toBeNull(); | |
| 25 | expect(daysLeftWords({ state: "open", revokedAt: null }, NOW)).toBeNull(); | |
| 26 | expect(daysLeftWords(link({ expiresAt: "garbage" }), NOW)).toBeNull(); | |
| 27 | }); | |
| 28 | }); |
test/client-list.test.ts +2 −5
| @@ -213,15 +213,12 @@ describe("the client list", () => { | ||
| 213 | 213 | expect(line).not.toContain('class="card'); |
| 214 | 214 | expect(maria).toContain('href="https://maria--forge.test"'); |
| 215 | 215 | expect(maria).toMatch(/data-claimed="no"/); |
| 216 | // The unclaimed link says how long it has left (#14155). | |
| 217 | expect(maria).toMatch(/<form method="post" action="\/forges\/maria\/claim-link"[^>]*>[\s\S]*?<button/); | |
| 218 | expect(maria).toMatch(/data-days-left[^>]*>(\d+ days? left|expires today)</); | |
| 219 | 216 | expect(html).not.toContain("forges-sent"); |
| 220 | 217 | const lou = html.slice(html.indexOf('data-forge="lou"')); |
| 221 | 218 | expect(lou).toMatch(/data-claimed="unknown"/); |
| 222 | 219 | expect(html).not.toContain("claim-link-box"); |
| 223 | 220 | expect(maria).toContain('class="row"'); |
| 224 | expect(maria).toContain("Renew link"); | |
| 221 | expect(maria).toContain("Send a new link"); | |
| 225 | 222 | expect(lou).toContain("it did not answer just now"); |
| 226 | 223 | // It did not answer, so it carries the one attention badge and leads the list. |
| 227 | 224 | expect(lou).toContain('data-attention="silent"'); |
| @@ -267,7 +264,7 @@ describe("the client list", () => { | ||
| 267 | 264 | test("an unclaimed row offers a fresh link: it replaces the old one, shown once; only an admin may ask", async () => { |
| 268 | 265 | const html = (await (await list(admin)).text()).replace(/\s+/g, " "); |
| 269 | 266 | const maria = html.slice(html.indexOf('data-forge="maria"'), html.indexOf("</li>", html.indexOf('data-forge="maria"'))); |
| 270 | expect(maria).toContain('action="/forges/maria/claim-link"'); | |
| 267 | expect(maria).toContain('href="/forges/maria/claim-link"'); | |
| 271 | 268 | const lou = html.slice(html.indexOf('data-forge="lou"'), html.indexOf("</li>", html.indexOf('data-forge="lou"'))); |
| 272 | 269 | // Whether lou was claimed is unknown, so it offers nothing to send. |
| 273 | 270 | expect(lou).not.toContain("claim-link"); |
test/tui-forges.test.ts −10
| @@ -126,16 +126,6 @@ describe("forges you sent in the terminal", () => { | ||
| 126 | 126 | h.stop(); |
| 127 | 127 | }); |
| 128 | 128 | |
| 129 | test("an unclaimed row says the days its link has left, and says expired", () => { | |
| 130 | const now = Date.parse("2026-11-16T12:00:00Z"); | |
| 131 | const line = (link: ClientRow["link"]) => forgeLines([row({ link })], false, now)[0]![1]; | |
| 132 | const at = (ms: number) => new Date(now + ms).toISOString(); | |
| 133 | expect(line({ state: "open", revokedAt: null, expiresAt: at(3 * 86_400_000) })).toContain("link open, 3 days left"); | |
| 134 | expect(line({ state: "open", revokedAt: null, expiresAt: at(-1000) })).toContain("link expired, press n for a new one"); | |
| 135 | expect(line({ state: "ended", revokedAt: null, expiresAt: at(-1000) })).toContain("link expired"); | |
| 136 | expect(line({ state: "open", revokedAt: null })).toContain("link open"); | |
| 137 | }); | |
| 138 | ||
| 139 | 129 | test("a row says whether its link is open, ended, or can be undone; a used link says nothing", () => { |
| 140 | 130 | const line = (link: ClientRow["link"]) => forgeLines([row({ link })])[0]![1]; |
| 141 | 131 | expect(line({ state: "open", revokedAt: null })).toContain("link open"); |
new above
offline