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

opened this

Check · Review · Land · Live — No review yet. Next: reviewer, no review yet.

Ready to land

revert-14175 → main 1 commit

Review

Sign in to review this change.
7 files changed +12 −79
src/spawn/clients.ts +2 −18
@@ -234,11 +234,10 @@ const LINK_STATES: readonly LinkState[] = ["open", "used", "ended"];
234234 /** The link a child reported, or null when it said nothing usable. */
235235 function linkOfBody(v: unknown): LinkInfo | null {
236236 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>;
238238 if (!LINK_STATES.includes(state as LinkState)) return null;
239239 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"]) };
242241 }
243242
244243 async function probe(app: App, child: Child): Promise<ForgeState | undefined> {
@@ -651,21 +650,6 @@ export function attentionOf(r: ClientRow, now: number): Attention | null {
651650 return null;
652651 }
653652
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
669653 export type StageKey = "sent" | "opened" | "signedin" | "tell";
670654
671655 /** 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 @@
66
77 import type { Ctx, Screen } from "../app/app.ts";
88 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";
1010 import { useLine } from "../../spawn/usage.ts";
1111 import { timeAgo } from "../../web/ui.ts";
1212 import { card } from "../ui/widgets.ts";
@@ -29,11 +29,11 @@ import { appLinkSummary, appLinkWords } from "../../spawn/app_links.ts";
2929 /**
3030 * [name, "Not reporting · for Maria · Claimed · 3 apps running"] per row; an empty line when none.
3131 */
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][] {
3333 if (rows.length === 0) return [["", "You have not sent a forge yet"]];
3434 return rows.flatMap((r): [string, string][] => [[
3535 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)}`]
3737 .filter((m): m is string => m !== null)
3838 .join(" · "),
3939 ], ...firstScreenLines(r), ...appLinkLines(r), ...addressLines(r)]);
@@ -49,12 +49,9 @@ function seenLine(r: ClientRow, sender: boolean): string | null {
4949 * "link open", "link ended (undo with u)": what the sender can do about the link, as /forges shows
5050 * it.
5151 */
52 function linkWords(link: LinkInfo | null, now: number | null = null): string | null {
52 function linkWords(link: LinkInfo | null): string | null {
5353 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";
5855 }
5956
6057 /** 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 @@
99 import type { Ctx } from "../../http/context.ts";
1010 import { claimsBill } from "../../actions/forge_bill.ts";
1111 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";
1313 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
1414 import { notFoundPage, pageHead } from "../chrome.ts";
1515 import { html, type Html } from "../html.ts";
@@ -79,7 +79,6 @@ const XLARGE_SAYS = `${sizeWords("xlarge")}. ${sizesView().sizes.find((x) => x.s
7979
8080 export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = false, kept?: string): Html {
8181 const state = claimState(r);
82 const daysLeft = state === "no" ? daysLeftWords(r.link, now) : null;
8382 const seen = seenOf(r);
8483 const meta = [
8584 r.for === null ? null : html`for ${r.for}`,
@@ -144,14 +143,12 @@ export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = f
144143 : html`<span data-attention="${r.attention}">${badge(ATTENTION_WORDS[r.attention], { tone: "attn" })}</span>`}${badge(CLAIM_WORDS[state], {
145144 ...(state === "yes" ? { tone: "success" as const } : { variant: "outline" as const }),
146145 })}${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" })
150147 : null}${state === "yes" && r.made
151148 ? 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" })
152149 : null}${r.link === null
153150 ? 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"
155152 ? 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>`
156153 : undoable(r.link, now)
157154 ? 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-list.test.ts +2 −5
@@ -213,15 +213,12 @@ describe("the client list", () => {
213213 expect(line).not.toContain('class="card');
214214 expect(maria).toContain('href="https://maria--forge.test"');
215215 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)</);
219216 expect(html).not.toContain("forges-sent");
220217 const lou = html.slice(html.indexOf('data-forge="lou"'));
221218 expect(lou).toMatch(/data-claimed="unknown"/);
222219 expect(html).not.toContain("claim-link-box");
223220 expect(maria).toContain('class="row"');
224 expect(maria).toContain("Renew link");
221 expect(maria).toContain("Send a new link");
225222 expect(lou).toContain("it did not answer just now");
226223 // It did not answer, so it carries the one attention badge and leads the list.
227224 expect(lou).toContain('data-attention="silent"');
@@ -267,7 +264,7 @@ describe("the client list", () => {
267264 test("an unclaimed row offers a fresh link: it replaces the old one, shown once; only an admin may ask", async () => {
268265 const html = (await (await list(admin)).text()).replace(/\s+/g, " ");
269266 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"');
271268 const lou = html.slice(html.indexOf('data-forge="lou"'), html.indexOf("</li>", html.indexOf('data-forge="lou"')));
272269 // Whether lou was claimed is unknown, so it offers nothing to send.
273270 expect(lou).not.toContain("claim-link");
test/tui-forges.test.ts −10
@@ -126,16 +126,6 @@ describe("forges you sent in the terminal", () => {
126126 h.stop();
127127 });
128128
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
139129 test("a row says whether its link is open, ended, or can be undone; a used link says nothing", () => {
140130 const line = (link: ClientRow["link"]) => forgeLines([row({ link })])[0]![1];
141131 expect(line({ state: "open", revokedAt: null })).toContain("link open");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs