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

A forge made for a client can be sent again: a fresh link replaces the old one and the old one stops working #13181

Merged opened this

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

Merged

scout/forge:scout/13166-a-forge-made-for-a-client-can-be-sent-ag → main 9 commits fork

  • Merged. scout/13166-a-forge-made-for-a-client-can-be-sent-ag was merged into main as 5cbaa85.

Review

Sign in to review this change.
12 files changed +423 −81
src/actions/spawn.ts +38 −7
@@ -774,18 +774,49 @@ export async function reissueClaim(
774774 deps: { readonly request: Request; readonly url: URL },
775775 ): Promise<Result<{ readonly name: string; readonly claimUrl: string }, SpawnError | { readonly kind: "not_found" }>> {
776776 if (crossOrigin(deps.request, deps.url, app.log)) return err({ kind: "cross_origin" });
777 const allowed = await mayReissue(app, actor, name);
778 if (!allowed.ok) return allowed;
779 const { user, child } = allowed.value;
780 const made = await reissueClaimFor(app, name);
781 if (made.ok)
782 app.bus.append({ kind: "forge.claim_reissued", actorId: user.id, payload: { name, for: child?.for ?? null } });
783 return made;
784 }
785
786 /** Who may send a forge's link again: the account that made it, or a site admin. */
787 async function mayReissue(app: App, actor: User | undefined, name: string): Promise<Result<{ readonly user: User; readonly child: Child | undefined }, SpawnError>> {
777788 const user = requireUser(actor);
778789 if (!user.ok) return err({ kind: "unauthorized" });
779790 // The account that spawned the child may reveal its link again until it is
780791 // claimed (#12105), agent or person; so may a site admin.
781 if (!user.value.isAdmin) {
782 const ledger = /^[a-z0-9-]{1,39}$/.test(name) ? await readLedger(app, name) : undefined;
783 if (ledger === undefined || ledger.ownerId === undefined || ledger.ownerId !== user.value.id)
784 return err({ kind: "forbidden" });
792 const child = /^[a-z0-9-]{1,39}$/.test(name) ? await childNamed(app, name) : undefined;
793 if (!user.value.isAdmin && (child === undefined || child.ownerId === undefined || child.ownerId !== user.value.id))
794 return err({ kind: "forbidden" });
795 return ok({ user: user.value, child });
796 }
797
798 /** What sending a new link would do, changing nothing: who it is for and what stops working. */
799 export async function previewReissue(
800 app: App,
801 actor: User | undefined,
802 name: string,
803 ): Promise<Result<{ readonly name: string; readonly for: string | null; readonly says: string }, SpawnError | { readonly kind: "not_found" }>> {
804 const allowed = await mayReissue(app, actor, name);
805 if (!allowed.ok) return allowed;
806 const child = allowed.value.child;
807 if (child === undefined || !child.done) return err({ kind: "not_found" });
808 const kid = createApp({ dataDir: childDirOf(app, child.bodyId) });
809 try {
810 if (hasAdmin(kid.db))
811 return err({ kind: "refused", reason: "claimed", message: `${name} is already claimed; ask its owner to invite you` });
812 } finally {
813 kid.close();
785814 }
786 const made = await reissueClaimFor(app, name);
787 if (made.ok) app.bus.append({ kind: "forge.claim_reissued", actorId: user.value.id, payload: { name } });
788 return made;
815 return ok({
816 name,
817 for: child.for,
818 says: `A new link for ${child.for ?? name}. The link sent earlier stops working at once; the new one is shown once and works once.`,
819 });
789820 }
790821
791822 /**
src/http/api/forges.ts +16 −5
@@ -12,7 +12,7 @@ import { usdWords } from "../../spawn/credit.ts";
1212 import { fundingOf, fundingWords, refreshFunding } from "../../spawn/funding.ts";
1313 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
1414 import { clientRows, listed } from "../../spawn/clients.ts";
15 import { reissueDoor, spawnDoor } from "../../spawn/door.ts";
15 import { previewDoor, reissueDoor, spawnDoor } from "../../spawn/door.ts";
1616 import { checkMove } from "../../spawn/move_check.ts";
1717 import { moveToCell } from "../../spawn/move_cell.ts";
1818 import { sizesView } from "../../spawn/sizes.ts";
@@ -23,7 +23,10 @@ import { holds, weakEtag } from "../etag.ts";
2323 import { apiError, body, forbidden, json, requireScope } from "../respond.ts";
2424 import type { Router } from "../router.ts";
2525
26 /** A table any page or agent may read: the same JSON for everyone, so an ETag and five minutes' cache. */
26 /**
27 * A table any page or agent may read: the same JSON for everyone, so an ETag and five minutes'
28 * cache.
29 */
2730 function publicTable(ctx: Ctx, phase: string, view: () => unknown): Response {
2831 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
2932 const text = timePhase(ctx.request, phase, () => JSON.stringify(view()));
@@ -63,7 +66,8 @@ export function forgeRoutes(router: Router<Handler>): void {
6366 if (denied) return denied;
6467 if (!ctx.auth.user?.isAdmin) return forbidden();
6568 const items = await timePhaseAsync(ctx.request, "read", async () => {
66 // The row, and beside it what the list always carried: which template a child came from, where it is placed.
69 // The row, and beside it what the list always carried: which template a child came from,
70 // where it is placed.
6771 const [rows, children] = await Promise.all([clientRows(ctx.app), listChildren(ctx.app)]);
6872 const kept = new Map(children.map((c) => [c.name, c]));
6973 return rows.map((row) => {
@@ -93,7 +97,8 @@ export function forgeRoutes(router: Router<Handler>): void {
9397 return json(door.body, door.status);
9498 });
9599
96 // The dollars this forge lends a child on its own model credential (#10484): a site admin sets the cap.
100 // The dollars this forge lends a child on its own model credential (#10484): a site admin sets
101 // the cap.
97102 router.add("PUT", "/api/v1/forges/:name/credit", async (ctx) => {
98103 if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return forbidden();
99104 const denied = requireScope(ctx, "rw");
@@ -153,7 +158,13 @@ export function forgeRoutes(router: Router<Handler>): void {
153158 router.add("POST", "/api/v1/forges/:name/claim-link", async (ctx) => {
154159 const denied = requireScope(ctx, "rw");
155160 if (denied) return denied;
156 const door = await reissueDoor(ctx, ctx.auth.user!, ctx.params["name"] ?? "");
161 const name = ctx.params["name"] ?? "";
162 // `dryRun: true` says who it is for and what stops working, and changes nothing.
163 if ((await body(ctx.request))["dryRun"] === true) {
164 const seen = await previewDoor(ctx, ctx.auth.user!, name);
165 return json(seen.body, seen.status);
166 }
167 const door = await reissueDoor(ctx, ctx.auth.user!, name);
157168 return json(door.body, door.status);
158169 });
159170 }
src/http/mcp/shared.ts +28 −8
@@ -58,7 +58,10 @@ export const badBlocked = (error: string, blocked: Blocked): Answer => ({
5858 next: blockedFields(blocked),
5959 });
6060
61 /** The refusal for a `limit` that is not a whole number from 1 to LIST_LIMIT_MAX, as the HTTP list routes say it; undefined when it is absent or fine. */
61 /**
62 * The refusal for a `limit` that is not a whole number from 1 to LIST_LIMIT_MAX, as the HTTP list
63 * routes say it; undefined when it is absent or fine.
64 */
6265 export const badLimit = (limit: unknown): Answer | undefined =>
6366 limit === undefined ||
6467 (typeof limit === "number" && Number.isInteger(limit) && limit >= 1 && limit <= LIST_LIMIT_MAX)
@@ -67,7 +70,10 @@ export const badLimit = (limit: unknown): Answer | undefined =>
6770
6871 export interface Tool {
6972 readonly name: string;
70 /** Its line in /llms.txt's `## MCP tools`: markdown, one line; absent, the line reads `description`. */
73 /**
74 * Its line in /llms.txt's `## MCP tools`: markdown, one line; absent, the line reads
75 * `description`.
76 */
7177 readonly doc?: string;
7278 readonly description: string;
7379 readonly inputSchema: Record<string, unknown>;
@@ -86,10 +92,15 @@ export interface Tool {
8692 run(ctx: Ctx, user: User, args: Args): Promise<Answer> | Answer;
8793 }
8894
89 /** What an everyday account calling an admin's tool by name is told: not here, and the one sentence on what to do next. */
95 /**
96 * What an everyday account calling an admin's tool by name is told: not here, and the one sentence
97 * on what to do next.
98 */
9099 export const notAdminTool = (name: string): string => `no tool named ${name} for this account. ${SIGN_IN_AS_ADMIN}`;
91100
92 /** Whether this caller is shown the tool and may call it: one rule for the manifest and dispatch. */
101 /**
102 * Whether this caller is shown the tool and may call it: one rule for the manifest and dispatch.
103 */
93104 export const visible = (tool: Tool, ctx: Ctx, user: User): boolean =>
94105 (tool.adminOnly !== true || user.isAdmin) &&
95106 (tool.needsAdminScope !== true || scopeAllows(ctx.auth.scope ?? "ro", "admin"));
@@ -104,7 +115,10 @@ export const plansOnly = (tool: Tool, args: Args): boolean =>
104115 export const NEEDS_CONFIRM =
105116 "this write follows text read as data and the person's newest words do not ask for it, so nothing was done. With an id in `needs_confirm`, Confirm and Cancel buttons are already in the thread: say in one sentence what it would do and point at them. With null nothing was kept: say so, and do not call it held";
106117
107 /** Most undoable writes one ask lets go after fenced text; past it each is held, so a steered agent cannot run on a yes. */
118 /**
119 * Most undoable writes one ask lets go after fenced text; past it each is held, so a steered agent
120 * cannot run on a yes.
121 */
108122 export const ASKED_WRITES_MAX = 8;
109123
110124 /** The confirm a held call draws in the person's thread, with its buttons; its sentence. */
@@ -378,7 +392,7 @@ export const REVEAL_ARG = {
378392 "true: show the secret link.",
379393 } as const;
380394 export const LINK_KEPT =
381 "The claim link is a secret, so it is not in this conversation: a person admin of this forge gets a fresh one on /forges (Send a fresh link) and hands it to the child's person. Send reveal: true only to have it here on purpose.";
395 "The claim link is a secret, so it is not in this conversation: a person admin of this forge gets a fresh one on /forges (Send a new link) and hands it to the child's person. Send reveal: true only to have it here on purpose.";
382396 export const LINK_REVEALED =
383397 "claimUrl is a live secret, now in this conversation: whoever holds it takes the child. Hand it only to the child's person; the secret is in its #fragment, so send it whole.";
384398
@@ -401,7 +415,10 @@ export function issueArg(ctx: Ctx, repo: Repo, args: Args, key: string) {
401415
402416 export const isAnswer = (v: Repo | Answer): v is Answer => "ok" in v;
403417
404 /** Boards are a forge admin's who is a person, as the API gates them: anyone else is forbidden, not told what is there. */
418 /**
419 * Boards are a forge admin's who is a person, as the API gates them: anyone else is forbidden, not
420 * told what is there.
421 */
405422 export const boardRefused = (): Answer => bad("forbidden", "boards are for a forge admin who is a person");
406423 export const mayBoards = (user: User): boolean => user.isAdmin && user.kind !== "agent";
407424 export function boardFailed(e: BoardError): Answer {
@@ -410,6 +427,9 @@ export function boardFailed(e: BoardError): Answer {
410427 return bad(e, BOARD_NOT_SAVED);
411428 }
412429
413 /** Orders by name's code points, never the machine's locale: the tool list reads the same everywhere. */
430 /**
431 * Orders by name's code points, never the machine's locale: the tool list reads the same
432 * everywhere.
433 */
414434 export const byName = (a: { readonly name: string }, b: { readonly name: string }): number =>
415435 a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
src/spawn/door.ts +18 −1
@@ -12,7 +12,15 @@ import { nameShapeVerdict } from "./name_verdict.ts";
1212 import { linkRequestVisitor } from "../perf/visitor_link.ts";
1313 import { startWatch, probeOf, type Probe } from "./live.ts";
1414 import { firstProof, reachWords, settleChild } from "./reach.ts";
15 import { forgeNameVerdict, founderClash, reissueClaim, spawnForge, takenReason, type SpawnError } from "../actions/spawn.ts";
15 import {
16 forgeNameVerdict,
17 founderClash,
18 previewReissue,
19 reissueClaim,
20 spawnForge,
21 takenReason,
22 type SpawnError,
23 } from "../actions/spawn.ts";
1624 import type { App } from "../app.ts";
1725 import { maxChildren } from "../core/capacity.ts";
1826 import { getAgentByName } from "../core/agents.ts";
@@ -446,6 +454,15 @@ export async function reissueDoor(ctx: Ctx, user: User, name: string): Promise<D
446454 return spawnWords(made.error);
447455 }
448456
457 /** What a new claim link would do (who for, what stops working), changing nothing. */
458 export async function previewDoor(ctx: Ctx, user: User, name: string): Promise<Door> {
459 const seen = await previewReissue(ctx.app, user, name);
460 if (seen.ok) return { status: 200, body: { dryRun: true, ...seen.value } };
461 if (seen.error.kind === "not_found")
462 return { status: 404, body: { error: "not_found", message: `no child forge named ${name}` } };
463 return spawnWords(seen.error);
464 }
465
449466 /** Take a child's unclaimed link back, or undo that within the minute: an admin's, same-origin. */
450467 export async function changeDoor(ctx: Ctx, user: User, name: string, act: "revoke" | "undo"): Promise<Door> {
451468 if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return spawnWords({ kind: "cross_origin" });
src/tui/screens/forges.ts +29 −7
@@ -23,9 +23,12 @@ import type { App } from "../../app.ts";
2323 import { undoable, type LinkInfo } from "../../spawn/claim.ts";
2424 import { confirmScreen, pickerScreen } from "./common.ts";
2525 import type { Session } from "../session.ts";
26 import { offerNewLink } from "./claim_link.ts";
2627 import { appLinkSummary, appLinkWords } from "../../spawn/app_links.ts";
2728
28 /** [name, "Not reporting · for Maria · Claimed · 3 apps running"] per row; an empty line when none. */
29 /**
30 * [name, "Not reporting · for Maria · Claimed · 3 apps running"] per row; an empty line when none.
31 */
2932 export function forgeLines(rows: readonly ClientRow[], sender = false): [string, string][] {
3033 if (rows.length === 0) return [["", "You have not sent a forge yet"]];
3134 return rows.flatMap((r): [string, string][] => [[
@@ -42,7 +45,10 @@ function seenLine(r: ClientRow, sender: boolean): string | null {
4245 return seen === null ? null : seenParts(seen).map((p) => (p.at === null ? p.words : `${p.words} ${timeAgo(p.at)}`)).join(" · ");
4346 }
4447
45 /** "link open", "link ended (undo with u)": what the sender can do about the link, as /forges shows it. */
48 /**
49 * "link open", "link ended (undo with u)": what the sender can do about the link, as /forges shows
50 * it.
51 */
4652 function linkWords(link: LinkInfo | null): string | null {
4753 if (link === null || link.state === "used") return null;
4854 return link.state === "open" ? "link open" : undoable(link) ? "link ended, undo with u" : "link ended";
@@ -60,7 +66,10 @@ function appLinkLines(r: ClientRow): [string, string][] {
6066 return [...(head === null ? [] : [["", ` ${head}`] as [string, string]]), ...(r.appLinks ?? []).map((l): [string, string] => ["", ` ${appLinkWords(l)}`])];
6167 }
6268
63 /** Under a forge that is running, not reachable: each public address and what it answered (#7959), as /forges lists them. */
69 /**
70 * Under a forge that is running, not reachable: each public address and what it answered (#7959),
71 * as /forges lists them.
72 */
6473 function addressLines(r: ClientRow): [string, string][] {
6574 if (r.reach === null || r.reach.ok) return [];
6675 return r.reach.proofs.map((p): [string, string] => ["", ` ${p.ok ? "reachable" : "NOT REACHABLE"} ${p.url.replace(/^https?:\/\//, "")}: ${p.says}`]);
@@ -74,7 +83,10 @@ export function fitLines(lines: [string, string][], room: number): [string, stri
7483 return kept;
7584 }
7685
77 /** The `o` picker's rows, as /forges's Forge code rows say them: whose code each runs, and its last rollback. */
86 /**
87 * The `o` picker's rows, as /forges's Forge code rows say them: whose code each runs, and its last
88 * rollback.
89 */
7890 export function ownCodePicks(app: App, rows: readonly ClientRow[]): { id: string; label: string; hint: string }[] {
7991 return rows
8092 .filter((r) => r.made)
@@ -94,7 +106,8 @@ export function forgesScreen(ctx: Ctx, rows: readonly ClientRow[], session?: Ses
94106 if (items.length === 0 || session === undefined) return;
95107 ctx.push(pickerScreen(ctx, screen, { title, items, onPick: (ids) => { if (ids[0] !== undefined) act(ids[0]); } }));
96108 };
97 // Revoke and Undo are the page's buttons, through the same action (`changeLink`): an admin's, for the rows that allow it.
109 // Revoke and Undo are the page's buttons, through the same action (`changeLink`): an admin's, for
110 // the rows that allow it.
98111 const changeOne = (act: "revoke" | "undo"): void => {
99112 const user = session?.user;
100113 if (session === undefined || user?.isAdmin !== true) return;
@@ -112,7 +125,8 @@ export function forgesScreen(ctx: Ctx, rows: readonly ClientRow[], session?: Ses
112125 }),
113126 );
114127 };
115 // "Use its own code" and back: the page's switch, through the same action (`ownCode`), an admin's.
128 // "Use its own code" and back: the page's switch, through the same action (`ownCode`), an
129 // admin's.
116130 const switchCode = (): void => {
117131 const user = session?.user;
118132 if (session === undefined || user?.isAdmin !== true) return;
@@ -151,9 +165,16 @@ export function forgesScreen(ctx: Ctx, rows: readonly ClientRow[], session?: Ses
151165 }),
152166 );
153167 };
168 // "Send a new link" on a row not yet claimed: the page's preview and confirm (`offerNewLink`).
169 const newLink = (): void => {
170 if (session === undefined || session.user?.isAdmin !== true) return;
171 const items = rows.filter((r) => r.made && claimState(r) !== "yes").map((r) => ({ id: r.name, label: r.name, hint: r.for === null ? "not claimed" : `for ${r.for}` }));
172 if (items.length === 0) return ctx.toast("No forge is waiting to be claimed");
173 ctx.push(pickerScreen(ctx, screen, { title: "A new link for which forge?", items, onPick: (ids) => { if (ids[0] !== undefined) runAsync(ctx, () => offerNewLink(ctx, session, ids[0]!, screen)); } }));
174 };
154175 const screen: Screen = {
155176 title: "Forges you sent",
156 keys: [binding(["s"], "stop one (sleep now)"), binding(["a"], "archive"), binding(["r"], "restore"), binding(["x"], "remove one"), binding(["l"], "end a link"), binding(["u"], "undo an ended link"), binding(["o"], "own code or this forge's"), binding(["m"], "move into a sandbox"), binding(["esc"], "close")],
177 keys: [binding(["s"], "stop"), binding(["a"], "archive"), binding(["r"], "restore"), binding(["x"], "remove"), binding(["n"], "new link"), binding(["l"], "end a link"), binding(["u"], "undo an ended link"), binding(["o"], "own code or this forge's"), binding(["m"], "move"), binding(["esc"], "close")],
157178 render(area, s) {
158179 const c = ctx.theme.c;
159180 const w = Math.min(100, Math.max(30, area.w - 6));
@@ -167,6 +188,7 @@ export function forgesScreen(ctx: Ctx, rows: readonly ClientRow[], session?: Ses
167188 if (e.key === "esc" || e.key === "q") ctx.pop();
168189 else if (e.key === "s" && session !== undefined)
169190 choose("Stop which forge?", (name) => void stopForge(session.app, name).then((done) => ctx.toast(done.says, done.ok ? "success" : "danger")));
191 else if (e.key === "n") newLink();
170192 else if (e.key === "l") changeOne("revoke");
171193 else if (e.key === "u") changeOne("undo");
172194 else if (e.key === "o") switchCode();
src/web/pages/forges.ts +36 −19
@@ -15,7 +15,7 @@ import { notFoundPage, pageHead } from "../chrome.ts";
1515 import { html, type Html } from "../html.ts";
1616 import { page, redirect } from "../layout.ts";
1717 import { undoable } from "../../spawn/claim.ts";
18 import { changeDoor, reissueDoor } from "../../spawn/door.ts";
18 import { changeDoor, previewDoor, reissueDoor } from "../../spawn/door.ts";
1919 import { readForm } from "../form.ts";
2020 import { badge, btn, row, time } from "../ui.ts";
2121 import { noRoom } from "../../spawn/door.ts";
@@ -137,9 +137,7 @@ export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = f
137137 : html`<span data-attention="${r.attention}">${badge(ATTENTION_WORDS[r.attention], { tone: "attn" })}</span>`}${badge(CLAIM_WORDS[state], {
138138 ...(state === "yes" ? { tone: "success" as const } : { variant: "outline" as const }),
139139 })}${state === "no"
140 ? html`<form method="post" action="/forges/${r.name}/claim-link">
141 ${btn(r.stage?.resend === true ? "Resend" : "Send a fresh link", { size: "sm", title: "A new claim link; the old one stops working" })}
142 </form>`
140 ? 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" })
143141 : null}${r.link === null
144142 ? null
145143 : html`<span data-link="${r.link.state}">${badge(LINK_WORDS[r.link.state], { variant: "outline" as const })}</span>${r.link.state === "open"
@@ -210,7 +208,10 @@ function sealedLine(ctx: Ctx): Html | null {
210208 return html`<p class="muted small" data-sealed>Every forge here runs in its own sandbox, and this forge opens none in its own process${at === 0 ? "" : html` (since ${new Date(at).toISOString().slice(0, 10)})`}.</p>`;
211209 }
212210
213 /** The link to the refused first asks, only when there are any, with their count; it shares the paragraph of the other link so the page gains no block. */
211 /**
212 * The link to the refused first asks, only when there are any, with their count; it shares the
213 * paragraph of the other link so the page gains no block.
214 */
214215 function refusedLink(ctx: Ctx): Html | null {
215216 if (!mayReadRefusals(ctx.auth.user)) return null;
216217 const n = countRefusals(ctx.app.db, Date.now());
@@ -279,20 +280,28 @@ export async function forgesPage(ctx: Ctx): Promise<Response> {
279280 // GET /forges/:name/claim-link — the button for the account that sent the forge, who
280281 // has no /forges list (#12105). Nothing is minted until it is pressed; whether this
281282 // account may is the door's answer, not this page's.
282 export function forgeLinkForm(ctx: Ctx): Response {
283 if (ctx.auth.user === undefined) return notFoundPage(ctx);
283 export async function forgeLinkForm(ctx: Ctx): Promise<Response> {
284 const user = ctx.auth.user;
285 if (user === undefined) return notFoundPage(ctx);
284286 const name = ctx.params["name"] ?? "";
285 const response = page({
286 ctx,
287 title: "A fresh link",
288 body: html`<div class="narrow-wide" data-forges>
289 ${pageHead(`A fresh link for ${name}`)}
287 const seen = await previewDoor(ctx, user, name);
288 const says = String(seen.body["says"] ?? seen.body["message"]);
289 const response = page(
290 {
291 ctx,
292 title: "A new link",
293 body: html`<div class="narrow-wide" data-forges>
294 ${pageHead(`A new link for ${name}`)}
290295 <section class="settings-block">
291 <p>The link you have stops working; the new one is shown once.</p>
292 <form method="post" action="/forges/${name}/claim-link">${btn("Send a fresh link", { title: "A new claim link; the old one stops working" })}</form>
296 <p data-preview>${says}</p>
297 ${seen.status < 400
298 ? html`<form method="post" action="/forges/${name}/claim-link">${btn("Send a new link", { title: "Issue the new link and end the old one" })}</form>`
299 : btn("Forges you sent", { href: "/forges", size: "sm" })}
293300 </section>
294301 </div>`,
295 });
302 },
303 seen.status,
304 );
296305 response.headers.set("cache-control", "no-store");
297306 return response;
298307 }
@@ -415,7 +424,10 @@ export async function forgeLinkSubmit(ctx: Ctx): Promise<Response> {
415424
416425 const LINK_WORDS = { open: "Link open", used: "Link used", ended: "Link ended" } as const;
417426
418 /** What `/forges?link=…&forge=…` says after a revoke or undo: fixed words, and only for a forge in the list. */
427 /**
428 * What `/forges?link=…&forge=…` says after a revoke or undo: fixed words, and only for a forge in
429 * the list.
430 */
419431 function receipt(ctx: Ctx, rows: readonly ClientRow[]): Html | null {
420432 const name = ctx.url.searchParams.get("forge") ?? "";
421433 if (!rows.some((r) => r.name === name)) return null;
@@ -427,7 +439,8 @@ function receipt(ctx: Ctx, rows: readonly ClientRow[]): Html | null {
427439 return says === undefined ? null : html`<p role="status" class="muted" data-receipt>${says}</p>`;
428440 }
429441
430 // POST /forges/:name/revoke-link and /undo-link — take the link back, or bring it back for a minute; then the row, with a receipt.
442 // POST /forges/:name/revoke-link and /undo-link — take the link back, or bring it back for a
443 // minute; then the row, with a receipt.
431444 function linkChange(act: "revoke" | "undo") {
432445 return async (ctx: Ctx): Promise<Response> => {
433446 const user = ctx.auth.user;
@@ -533,7 +546,10 @@ const CODE_WORDS = {
533546 refused: "stays on this forge's code: only a forge in its own cell, with a forge repository, can run its own.",
534547 } as const;
535548
536 /** What `/forges?code=…&forge=…` says after the switch: fixed words, and only for a forge in the list. */
549 /**
550 * What `/forges?code=…&forge=…` says after the switch: fixed words, and only for a forge in the
551 * list.
552 */
537553 function codeReceipt(ctx: Ctx, names: readonly string[]): Html | null {
538554 const name = ctx.url.searchParams.get("forge") ?? "";
539555 const code = ctx.url.searchParams.get("code") ?? "";
@@ -572,7 +588,8 @@ async function ownCodeSection(ctx: Ctx): Promise<Html | null> {
572588 </section>`;
573589 }
574590
575 // POST /forges/:name/own-code — the owner's switch: `on` is "on" or "off"; then back to the list, with a receipt.
591 // POST /forges/:name/own-code — the owner's switch: `on` is "on" or "off"; then back to the list,
592 // with a receipt.
576593 export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> {
577594 const user = ctx.auth.user;
578595 if (!user?.isAdmin) return notFoundPage(ctx);
test/client-list.test.ts +2 −2
@@ -216,7 +216,7 @@ describe("the client list", () => {
216216 expect(lou).toMatch(/data-claimed="unknown"/);
217217 expect(html).not.toContain("claim-link-box");
218218 expect(maria).toContain('class="row"');
219 expect(maria).toContain("Send a fresh link");
219 expect(maria).toContain("Send a new link");
220220 expect(lou).toContain("it did not answer just now");
221221 // It did not answer, so it carries the one attention badge and leads the list.
222222 expect(lou).toContain('data-attention="silent"');
@@ -246,7 +246,7 @@ describe("the client list", () => {
246246 test("an unclaimed row offers a fresh link: it replaces the old one, shown once; only an admin may ask", async () => {
247247 const html = (await (await list(admin)).text()).replace(/\s+/g, " ");
248248 const maria = html.slice(html.indexOf('data-forge="maria"'), html.indexOf("</li>", html.indexOf('data-forge="maria"')));
249 expect(maria).toContain('action="/forges/maria/claim-link"');
249 expect(maria).toContain('href="/forges/maria/claim-link"');
250250 const lou = html.slice(html.indexOf('data-forge="lou"'), html.indexOf("</li>", html.indexOf('data-forge="lou"')));
251251 // Whether lou was claimed is unknown, so it offers nothing to send.
252252 expect(lou).not.toContain("claim-link");
test/client-states.test.ts +3
@@ -75,6 +75,9 @@ describe("client states", () => {
7575 expect(stale).toContain(STALE_WORDS);
7676 expect(stale).toContain("Resend");
7777 expect(stale).toContain("/forges/acme/claim-link");
78 // The row's button opens the preview (a link), not a form that issues at once (#13166).
79 expect(stale).not.toContain('method="post" action="/forges/acme/claim-link"');
80 expect(String(forgeRow(stage(), NOW))).toContain("Send a new link");
7881 });
7982
8083 test("the terminal line carries the same words, and resend", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs