{"draft":null,"from":257,"to":318,"files":[{"path":"client/src/box.ts","added":60,"removed":8,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -222,7 +222,7 @@\n }\n \n /** This machine's name, as the server takes a box's name: 1-64 letters, digits, '.', '_' or '-'. */\n-function boxName(): string {\n+export function boxName(): string {\n \tconst name = hostname()\n \t\t.replace(/[^A-Za-z0-9._-]/g, \"-\")\n \t\t.replace(/^[^A-Za-z0-9]+/, \"\")\n@@ -254,8 +254,29 @@\n \treadonly say: (line: string) => void;\n \t/** Opens the approve page in a browser, answering whether it tried. None where it shouldn't (--no-browser, SSH, CI). */\n \treadonly open?: (url: string) => boolean;\n+\t/**\n+\t * abso 684: in a joined folder, asks a person in its project to approve this sign-in, through an abso ask, so nobody\n+\t * relays the code. Answers who was asked, or null to fall back to the code alone.\n+\t */\n+\treadonly ask?: (codes: { readonly device: string; readonly user: string }) => Promise<LoginAsked | null>;\n }\n \n+/** A sign-in asked of people (abso 684). */\n+export interface LoginAsked {\n+\treadonly project: string;\n+\t/** \"the person who approved this agent's box\", or \"the owners of <project>\". */\n+\treadonly who: string;\n+\treadonly asks: readonly number[];\n+\t/** Milliseconds: when the asked sign-in runs out. */\n+\treadonly expiresAt: number;\n+\t/** The most the box may be granted: the asking agent's own role. */\n+\treadonly role: string;\n+\t/** Withdraws the asks once nobody answered in time. */\n+\treadonly withdraw: () => Promise<void>;\n+}\n+\n+const CENTRAL = new Intl.DateTimeFormat(\"en-US\", { timeZone: \"America/Chicago\", hour: \"numeric\", minute: \"2-digit\" });\n+\n /**\n  * Asks `server` for a code, shows it with its link, and waits for a person to\n  * approve it. Answers the box's record, already written to the config folder.\n@@ -278,16 +299,37 @@\n \tif (typeof code !== \"string\" || typeof link !== \"string\" || typeof device !== \"string\")\n \t\tthrow new UsageError(`${originOf(server)} didn't give a code to approve`);\n \t// The page opens with the code in it, so nobody copies a link by hand. The link and code are printed all the same.\n-\tif (io.open?.(link)) io.say(\"Opening the approve page in your browser.\");\n-\tio.say(`To sign this box in, open ${link} and approve the code ${code}.`);\n-\tio.say(\"Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.\");\n-\tconst until = now() + expiresIn * 1000;\n+\t// A failed ask falls back to the code, and says why, so a person can still approve it (abso 684).\n+\tconst asked = io.ask\n+\t\t? await io.ask({ device, user: code }).catch((e: unknown) => {\n+\t\t\t\tio.say(\n+\t\t\t\t\t`Couldn't ask a person to approve this (${e instanceof Error ? e.message : String(e)}), so here is the code.`,\n+\t\t\t\t);\n+\t\t\t\treturn null;\n+\t\t\t})\n+\t\t: null;\n+\tif (asked) {\n+\t\tconst askWord = asked.asks.length === 1 ? `ask ${asked.asks[0]}` : `asks ${asked.asks.join(\", \")}`;\n+\t\tio.say(`Asked ${asked.who} (${askWord} in ${asked.project}) to sign this box in, as at most ${asked.role}.`);\n+\t\tio.say(\n+\t\t\t`Waiting for their answer, until ${CENTRAL.format(new Date(asked.expiresAt))} CT. To approve it yourself instead: ${link}`,\n+\t\t);\n+\t} else {\n+\t\tif (io.open?.(link)) io.say(\"Opening the approve page in your browser.\");\n+\t\tio.say(`To sign this box in, open ${link} and approve the code ${code}.`);\n+\t\tio.say(\"Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.\");\n+\t}\n+\tconst until = asked ? Math.min(asked.expiresAt, now() + MAX_LOGIN_WAIT_S * 1000) : now() + expiresIn * 1000;\n \tlet toldAt = now();\n \twhile (now() < until) {\n \t\tawait sleep(interval * 1000);\n \t\t// A wait with no word looks like a hang, so say it's still waiting now and then.\n \t\tif (now() - toldAt >= STILL_WAITING_MS) {\n-\t\t\tio.say(`Still waiting for the code ${code} to be approved.`);\n+\t\t\tio.say(\n+\t\t\t\tasked\n+\t\t\t\t\t? `Still waiting (${asked.who} hasn't answered yet).`\n+\t\t\t\t\t: `Still waiting for the code ${code} to be approved.`,\n+\t\t\t);\n \t\t\ttoldAt = now();\n \t\t}\n \t\tconst a = await call(server, \"/login/token\", { device_code: device }, undefined, fetcher);\n@@ -297,8 +339,14 @@\n \t\t\t\tinterval += 5;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (a.body.error === \"access_denied\") throw new UsageError(`the code ${code} was turned down.`);\n-\t\t\tthrow new UsageError(`the code ${code} ran out. Run abso login again.`);\n+\t\t\tif (a.body.error === \"access_denied\")\n+\t\t\t\tthrow new UsageError(asked ? `${asked.who} turned this sign-in down.` : `the code ${code} was turned down.`);\n+\t\t\tif (asked) await asked.withdraw().catch(() => undefined);\n+\t\t\tthrow new UsageError(\n+\t\t\t\tasked\n+\t\t\t\t\t? \"nobody answered in time, so nothing was granted. Run abso login again.\"\n+\t\t\t\t\t: `the code ${code} ran out. Run abso login again.`,\n+\t\t\t);\n \t\t}\n \t\tconst { box_token: credential, box_id: id, grant, expires_at } = a.body;\n \t\tconst expiresAt = typeof expires_at === \"string\" ? Date.parse(expires_at) : Number.NaN;\n@@ -308,6 +356,10 @@\n \t\twriteBox(record, home);\n \t\treturn record;\n \t}\n+\tif (asked) {\n+\t\tawait asked.withdraw().catch(() => undefined);\n+\t\tthrow new UsageError(\"nobody answered in time, so nothing was granted. Run abso login again.\");\n+\t}\n \tthrow new UsageError(`nobody approved the code ${code} in time. Run abso login again.`);\n }\n "}],"unmatched":[]}