{"file":"client/src/box.ts","version":318,"total":510,"from":1,"to":510,"lines":[{"n":1,"text":"// Signing in once per box (abso issue 108). `abso login` asks the server for a","atom":"a0","author":"init","version":0},{"n":2,"text":"// code, a person approves it on the website, and the box gets a credential","atom":"a0","author":"init","version":0},{"n":3,"text":"// with a grant: projects, a role cap, an agent limit and an expiry. Agents on","atom":"a0","author":"init","version":0},{"n":4,"text":"// the box then mint their own keys from it at `abso join`.","atom":"a0","author":"init","version":0},{"n":5,"text":"//","atom":"a0","author":"init","version":0},{"n":6,"text":"// The box credential lives in the user's config folder, one file per server,","atom":"a0","author":"init","version":0},{"n":7,"text":"// never in a project folder. It is never printed, never an argument, and only","atom":"a0","author":"init","version":0},{"n":8,"text":"// ever sent to the server that issued it: on /box/ routes, and on the org reads,","atom":"a286","author":"pinch","version":34},{"n":9,"text":"// which answer as the person who approved the box.","atom":"a286","author":"pinch","version":34},{"n":10,"text":"","atom":"a0","author":"init","version":0},{"n":11,"text":"import { createHash } from \"node:crypto\";","atom":"a0","author":"init","version":0},{"n":12,"text":"import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";","atom":"a613","author":"trials","version":61},{"n":13,"text":"import { homedir, hostname } from \"node:os\";","atom":"a0","author":"init","version":0},{"n":14,"text":"import { dirname, join } from \"node:path\";","atom":"a125","author":"review","version":17},{"n":15,"text":"import { type Parsed, str, UsageError } from \"./args.ts\";","atom":"a920","author":"codex-mac-1","version":102},{"n":16,"text":"import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from \"./state-dir.ts\";","atom":"a613","author":"trials","version":61},{"n":17,"text":"","atom":"a0","author":"init","version":0},{"n":18,"text":"/**","atom":"a1848","author":"open","version":171},{"n":19,"text":" * What the person who approved the code allowed: each project with the highest role its agents get there. A box lets in any","atom":"a1848","author":"open","version":171},{"n":20,"text":" * number of agents (abso 642; Christopher, 2026-10-14, ask 1947); the server still records a max_agents it doesn't enforce.","atom":"a1848","author":"open","version":171},{"n":21,"text":" */","atom":"a1848","author":"open","version":171},{"n":22,"text":"export interface Grant {","atom":"a0","author":"init","version":0},{"n":23,"text":"\treadonly projects: readonly { readonly project: string; readonly role: string }[];","atom":"a0","author":"init","version":0},{"n":24,"text":"\t/** Version 2 grants (abso 663): member-all is every project of the approver's, now and later, at most this role. */","atom":"a2071","author":"box-grants","version":185},{"n":25,"text":"\treadonly scopes?: readonly { readonly kind: string; readonly role: string }[];","atom":"a2071","author":"box-grants","version":185},{"n":26,"text":"}","atom":"a0","author":"init","version":0},{"n":27,"text":"","atom":"a0","author":"init","version":0},{"n":28,"text":"/** The role a box has in all its approver's projects, now and later, or null when its grant is a list (abso 663). */","atom":"a2071","author":"box-grants","version":185},{"n":29,"text":"export function allProjectsRole(grant: Grant): string | null {","atom":"a2071","author":"box-grants","version":185},{"n":30,"text":"\treturn grant.scopes?.find((scope) => scope.kind === \"member-all\")?.role ?? null;","atom":"a2071","author":"box-grants","version":185},{"n":31,"text":"}","atom":"a2071","author":"box-grants","version":185},{"n":32,"text":"","atom":"a2071","author":"box-grants","version":185},{"n":33,"text":"/** Requested access is a suggestion for the person approving, never an authorization. */","atom":"a920","author":"codex-mac-1","version":102},{"n":34,"text":"export interface LoginRequest {","atom":"a920","author":"codex-mac-1","version":102},{"n":35,"text":"\treadonly projects?: readonly { readonly project: string; readonly role: \"reader\" | \"writer\" | \"owner\" }[];","atom":"a920","author":"codex-mac-1","version":102},{"n":36,"text":"\treadonly days?: number;","atom":"a920","author":"codex-mac-1","version":102},{"n":37,"text":"}","atom":"a920","author":"codex-mac-1","version":102},{"n":38,"text":"","atom":"a920","author":"codex-mac-1","version":102},{"n":39,"text":"export function loginRequest(args: Parsed): LoginRequest | undefined {","atom":"a920","author":"codex-mac-1","version":102},{"n":40,"text":"\tconst projects = str(args, \"projects\");","atom":"a920","author":"codex-mac-1","version":102},{"n":41,"text":"\tconst role = str(args, \"role\");","atom":"a920","author":"codex-mac-1","version":102},{"n":42,"text":"\tconst days = str(args, \"days\");","atom":"a920","author":"codex-mac-1","version":102},{"n":43,"text":"\tif (projects === undefined && role === undefined && days === undefined) return undefined;","atom":"a1848","author":"open","version":171},{"n":44,"text":"\tif (role !== undefined && projects === undefined) throw new UsageError(\"--role needs --projects\");","atom":"a920","author":"codex-mac-1","version":102},{"n":45,"text":"\tconst requestedRole = role ?? \"writer\";","atom":"a920","author":"codex-mac-1","version":102},{"n":46,"text":"\tif (requestedRole !== \"reader\" && requestedRole !== \"writer\" && requestedRole !== \"owner\")","atom":"a920","author":"codex-mac-1","version":102},{"n":47,"text":"\t\tthrow new UsageError(\"--role is reader, writer or owner\");","atom":"a920","author":"codex-mac-1","version":102},{"n":48,"text":"\tconst names = projects?.split(\",\").map((name) => name.trim());","atom":"a920","author":"codex-mac-1","version":102},{"n":49,"text":"\tif (names && (names.length > 100 || names.some((name) => !/^[A-Za-z0-9._-]+$/.test(name))))","atom":"a920","author":"codex-mac-1","version":102},{"n":50,"text":"\t\tthrow new UsageError(","atom":"a920","author":"codex-mac-1","version":102},{"n":51,"text":"\t\t\t\"--projects is a comma-separated list of up to 100 project names (letters, digits, dot, dash and underscore)\",","atom":"a920","author":"codex-mac-1","version":102},{"n":52,"text":"\t\t);","atom":"a920","author":"codex-mac-1","version":102},{"n":53,"text":"\tconst integer = (value: string, name: string, max: number): number => {","atom":"a920","author":"codex-mac-1","version":102},{"n":54,"text":"\t\tif (!/^[0-9]+$/.test(value) || !Number.isInteger(Number(value)) || Number(value) < 1 || Number(value) > max)","atom":"a920","author":"codex-mac-1","version":102},{"n":55,"text":"\t\t\tthrow new UsageError(`--${name} is from 1 to ${max}`);","atom":"a920","author":"codex-mac-1","version":102},{"n":56,"text":"\t\treturn Number(value);","atom":"a920","author":"codex-mac-1","version":102},{"n":57,"text":"\t};","atom":"a920","author":"codex-mac-1","version":102},{"n":58,"text":"\treturn {","atom":"a920","author":"codex-mac-1","version":102},{"n":59,"text":"\t\t...(names ? { projects: [...new Set(names)].map((project) => ({ project, role: requestedRole })) } : {}),","atom":"a920","author":"codex-mac-1","version":102},{"n":60,"text":"\t\t...(days === undefined ? {} : { days: integer(days, \"days\", 90) }),","atom":"a920","author":"codex-mac-1","version":102},{"n":61,"text":"\t};","atom":"a920","author":"codex-mac-1","version":102},{"n":62,"text":"}","atom":"a920","author":"codex-mac-1","version":102},{"n":63,"text":"","atom":"a920","author":"codex-mac-1","version":102},{"n":64,"text":"export interface BoxRecord {","atom":"a0","author":"init","version":0},{"n":65,"text":"\treadonly server: string;","atom":"a0","author":"init","version":0},{"n":66,"text":"\treadonly id: string;","atom":"a0","author":"init","version":0},{"n":67,"text":"\treadonly credential: string;","atom":"a0","author":"init","version":0},{"n":68,"text":"\treadonly grant: Grant;","atom":"a0","author":"init","version":0},{"n":69,"text":"\treadonly expiresAt: number;","atom":"a0","author":"init","version":0},{"n":70,"text":"}","atom":"a0","author":"init","version":0},{"n":71,"text":"","atom":"a0","author":"init","version":0},{"n":72,"text":"export function originOf(server: string): string {","atom":"a0","author":"init","version":0},{"n":73,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":74,"text":"\t\treturn new URL(server).origin;","atom":"a0","author":"init","version":0},{"n":75,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":76,"text":"\t\treturn server;","atom":"a0","author":"init","version":0},{"n":77,"text":"\t}","atom":"a0","author":"init","version":0},{"n":78,"text":"}","atom":"a0","author":"init","version":0},{"n":79,"text":"","atom":"a0","author":"init","version":0},{"n":80,"text":"function boxFile(server: string): string {","atom":"a125","author":"review","version":17},{"n":81,"text":"\treturn `${createHash(\"sha256\").update(originOf(server)).digest(\"hex\").slice(0, 16)}.json`;","atom":"a125","author":"review","version":17},{"n":82,"text":"}","atom":"a0","author":"init","version":0},{"n":83,"text":"","atom":"a0","author":"init","version":0},{"n":84,"text":"export function readBox(server: string, home = homedir()): BoxRecord | undefined {","atom":"a0","author":"init","version":0},{"n":85,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":86,"text":"\t\tconst raw = JSON.parse(readFileSync(homeFile(home, \"boxes\", boxFile(server)), \"utf8\")) as Partial<BoxRecord>;","atom":"a125","author":"review","version":17},{"n":87,"text":"\t\tif (","atom":"a0","author":"init","version":0},{"n":88,"text":"\t\t\ttypeof raw.server !== \"string\" ||","atom":"a0","author":"init","version":0},{"n":89,"text":"\t\t\toriginOf(raw.server) !== originOf(server) ||","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\t\ttypeof raw.credential !== \"string\" ||","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\t\ttypeof raw.id !== \"string\" ||","atom":"a0","author":"init","version":0},{"n":92,"text":"\t\t\ttypeof raw.expiresAt !== \"number\" ||","atom":"a0","author":"init","version":0},{"n":93,"text":"\t\t\t!isGrant(raw.grant)","atom":"a0","author":"init","version":0},{"n":94,"text":"\t\t)","atom":"a0","author":"init","version":0},{"n":95,"text":"\t\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":96,"text":"\t\treturn raw as BoxRecord;","atom":"a0","author":"init","version":0},{"n":97,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":99,"text":"\t}","atom":"a0","author":"init","version":0},{"n":100,"text":"}","atom":"a613","author":"trials","version":61},{"n":101,"text":"","atom":"a613","author":"trials","version":61},{"n":102,"text":"/** The servers this box is signed in to and whose sign-in hasn't expired, from ~/.abso/boxes (and an older ~/.avcs/boxes). */","atom":"a613","author":"trials","version":61},{"n":103,"text":"export function signedInServers(home = homedir(), now = Date.now()): string[] {","atom":"a613","author":"trials","version":61},{"n":104,"text":"\tconst servers = new Set<string>();","atom":"a613","author":"trials","version":61},{"n":105,"text":"\tfor (const dir of [STATE_DIR, OLD_STATE_DIR]) {","atom":"a613","author":"trials","version":61},{"n":106,"text":"\t\tlet names: string[];","atom":"a613","author":"trials","version":61},{"n":107,"text":"\t\ttry {","atom":"a613","author":"trials","version":61},{"n":108,"text":"\t\t\tnames = readdirSync(join(home, dir, \"boxes\"));","atom":"a613","author":"trials","version":61},{"n":109,"text":"\t\t} catch {","atom":"a613","author":"trials","version":61},{"n":110,"text":"\t\t\tcontinue;","atom":"a613","author":"trials","version":61},{"n":111,"text":"\t\t}","atom":"a613","author":"trials","version":61},{"n":112,"text":"\t\tfor (const name of names) {","atom":"a613","author":"trials","version":61},{"n":113,"text":"\t\t\ttry {","atom":"a613","author":"trials","version":61},{"n":114,"text":"\t\t\t\tconst server = (JSON.parse(readFileSync(join(home, dir, \"boxes\", name), \"utf8\")) as { server?: unknown })","atom":"a613","author":"trials","version":61},{"n":115,"text":"\t\t\t\t\t.server;","atom":"a613","author":"trials","version":61},{"n":116,"text":"\t\t\t\tif (typeof server !== \"string\") continue;","atom":"a613","author":"trials","version":61},{"n":117,"text":"\t\t\t\tconst record = readBox(server, home);","atom":"a613","author":"trials","version":61},{"n":118,"text":"\t\t\t\tif (record && record.expiresAt > now) servers.add(originOf(record.server));","atom":"a613","author":"trials","version":61},{"n":119,"text":"\t\t\t} catch {","atom":"a613","author":"trials","version":61},{"n":120,"text":"\t\t\t\t// Not a sign-in this client wrote: left alone.","atom":"a613","author":"trials","version":61},{"n":121,"text":"\t\t\t}","atom":"a613","author":"trials","version":61},{"n":122,"text":"\t\t}","atom":"a613","author":"trials","version":61},{"n":123,"text":"\t}","atom":"a613","author":"trials","version":61},{"n":124,"text":"\treturn [...servers].sort();","atom":"a613","author":"trials","version":61},{"n":125,"text":"}","atom":"a0","author":"init","version":0},{"n":126,"text":"","atom":"a0","author":"init","version":0},{"n":127,"text":"export function writeBox(record: BoxRecord, home = homedir()): void {","atom":"a0","author":"init","version":0},{"n":128,"text":"\tconst path = homeWritePath(home, \"boxes\", boxFile(record.server));","atom":"a125","author":"review","version":17},{"n":129,"text":"\tmkdirSync(dirname(path), { recursive: true });","atom":"a125","author":"review","version":17},{"n":130,"text":"\twriteFileSync(path, `${JSON.stringify(record)}\\n`, { mode: 0o600 });","atom":"a0","author":"init","version":0},{"n":131,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":132,"text":"\t\tchmodSync(path, 0o600);","atom":"a0","author":"init","version":0},{"n":133,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":134,"text":"\t\t// Windows has no owner-only mode; the file is still outside every project folder.","atom":"a0","author":"init","version":0},{"n":135,"text":"\t}","atom":"a0","author":"init","version":0},{"n":136,"text":"}","atom":"a0","author":"init","version":0},{"n":137,"text":"","atom":"a0","author":"init","version":0},{"n":138,"text":"/** Logout ends the sign-in everywhere on this machine: the credential under ~/.abso and any older copy under ~/.avcs. */","atom":"a125","author":"review","version":17},{"n":139,"text":"export function forgetBox(server: string, home = homedir()): boolean {","atom":"a0","author":"init","version":0},{"n":140,"text":"\tconst paths = [homeWritePath(home, \"boxes\", boxFile(server)), join(home, OLD_STATE_DIR, \"boxes\", boxFile(server))];","atom":"a125","author":"review","version":17},{"n":141,"text":"\tconst had = paths.filter((path) => existsSync(path));","atom":"a125","author":"review","version":17},{"n":142,"text":"\tfor (const path of had) rmSync(path, { force: true });","atom":"a125","author":"review","version":17},{"n":143,"text":"\treturn had.length > 0;","atom":"a125","author":"review","version":17},{"n":144,"text":"}","atom":"a0","author":"init","version":0},{"n":145,"text":"","atom":"a0","author":"init","version":0},{"n":146,"text":"/** Error text with the credential (and anything shaped like a key) taken out. */","atom":"a0","author":"init","version":0},{"n":147,"text":"function scrub(text: string, secrets: readonly string[]): string {","atom":"a0","author":"init","version":0},{"n":148,"text":"\tlet out = text.replace(/abso_(sk|bx)_[A-Za-z0-9_-]+/g, \"[redacted]\");","atom":"a0","author":"init","version":0},{"n":149,"text":"\tfor (const s of secrets) if (s.length > 0) out = out.split(s).join(\"[redacted]\");","atom":"a0","author":"init","version":0},{"n":150,"text":"\treturn out;","atom":"a0","author":"init","version":0},{"n":151,"text":"}","atom":"a0","author":"init","version":0},{"n":152,"text":"","atom":"a0","author":"init","version":0},{"n":153,"text":"export interface Answer {","atom":"a286","author":"pinch","version":34},{"n":154,"text":"\treadonly status: number;","atom":"a0","author":"init","version":0},{"n":155,"text":"\treadonly body: Record<string, unknown>;","atom":"a0","author":"init","version":0},{"n":156,"text":"}","atom":"a0","author":"init","version":0},{"n":157,"text":"","atom":"a0","author":"init","version":0},{"n":158,"text":"async function call(","atom":"a0","author":"init","version":0},{"n":159,"text":"\tserver: string,","atom":"a0","author":"init","version":0},{"n":160,"text":"\tpath: string,","atom":"a0","author":"init","version":0},{"n":161,"text":"\tbody: unknown,","atom":"a0","author":"init","version":0},{"n":162,"text":"\tcredential: string | undefined,","atom":"a0","author":"init","version":0},{"n":163,"text":"\tfetcher: typeof fetch,","atom":"a0","author":"init","version":0},{"n":164,"text":"\theaders: Readonly<Record<string, string>> = {},","atom":"a2071","author":"box-grants","version":185},{"n":165,"text":"): Promise<Answer> {","atom":"a0","author":"init","version":0},{"n":166,"text":"\tconst secrets = credential ? [credential] : [];","atom":"a0","author":"init","version":0},{"n":167,"text":"\tlet response: Response;","atom":"a0","author":"init","version":0},{"n":168,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":169,"text":"\t\tresponse = await fetcher(`${originOf(server)}${path}`, {","atom":"a0","author":"init","version":0},{"n":170,"text":"\t\t\tmethod: \"POST\",","atom":"a0","author":"init","version":0},{"n":171,"text":"\t\t\theaders: {","atom":"a0","author":"init","version":0},{"n":172,"text":"\t\t\t\t\"content-type\": \"application/json\",","atom":"a0","author":"init","version":0},{"n":173,"text":"\t\t\t\t...headers,","atom":"a2071","author":"box-grants","version":185},{"n":174,"text":"\t\t\t\t...(credential ? { authorization: `Box ${credential}` } : {}),","atom":"a0","author":"init","version":0},{"n":175,"text":"\t\t\t},","atom":"a0","author":"init","version":0},{"n":176,"text":"\t\t\tbody: JSON.stringify(body),","atom":"a0","author":"init","version":0},{"n":177,"text":"\t\t\tsignal: AbortSignal.timeout(30_000),","atom":"a0","author":"init","version":0},{"n":178,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":179,"text":"\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":180,"text":"\t\tthrow new UsageError(","atom":"a0","author":"init","version":0},{"n":181,"text":"\t\t\t`couldn't reach ${originOf(server)}: ${scrub(err instanceof Error ? err.message : String(err), secrets)}`,","atom":"a0","author":"init","version":0},{"n":182,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":183,"text":"\t}","atom":"a0","author":"init","version":0},{"n":184,"text":"\tconst text = await response.text();","atom":"a0","author":"init","version":0},{"n":185,"text":"\tlet parsed: Record<string, unknown> = {};","atom":"a0","author":"init","version":0},{"n":186,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":187,"text":"\t\tparsed = JSON.parse(text) as Record<string, unknown>;","atom":"a0","author":"init","version":0},{"n":188,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":189,"text":"\t\tif (response.ok) throw new UsageError(`${originOf(server)}${path} didn't answer JSON`);","atom":"a0","author":"init","version":0},{"n":190,"text":"\t}","atom":"a0","author":"init","version":0},{"n":191,"text":"\tif (!response.ok && !(response.status === 400 && path === \"/login/token\")) {","atom":"a0","author":"init","version":0},{"n":192,"text":"\t\tconst said = typeof parsed.error === \"string\" ? parsed.error : text.slice(0, 300);","atom":"a0","author":"init","version":0},{"n":193,"text":"\t\tthrow new UsageError(scrub(`${originOf(server)} refused (${response.status}): ${said}`, secrets));","atom":"a0","author":"init","version":0},{"n":194,"text":"\t}","atom":"a0","author":"init","version":0},{"n":195,"text":"\treturn { status: response.status, body: parsed };","atom":"a0","author":"init","version":0},{"n":196,"text":"}","atom":"a0","author":"init","version":0},{"n":197,"text":"","atom":"a0","author":"init","version":0},{"n":198,"text":"/**","atom":"a287","author":"pinch","version":34},{"n":199,"text":" * A read that answers as the person who approved this box: the org reads (GET /orgs, /orgs/<name>). Answers the","atom":"a287","author":"pinch","version":34},{"n":200,"text":" * status and body as they came, refusals included, so the caller can say what each means; never the credential.","atom":"a287","author":"pinch","version":34},{"n":201,"text":" */","atom":"a287","author":"pinch","version":34},{"n":202,"text":"export async function boxGet(record: BoxRecord, path: string, fetcher: typeof fetch = fetch): Promise<Answer> {","atom":"a287","author":"pinch","version":34},{"n":203,"text":"\tconst secrets = [record.credential];","atom":"a287","author":"pinch","version":34},{"n":204,"text":"\tlet response: Response;","atom":"a287","author":"pinch","version":34},{"n":205,"text":"\ttry {","atom":"a287","author":"pinch","version":34},{"n":206,"text":"\t\tresponse = await fetcher(`${originOf(record.server)}${path}`, {","atom":"a287","author":"pinch","version":34},{"n":207,"text":"\t\t\theaders: { authorization: `Box ${record.credential}` },","atom":"a287","author":"pinch","version":34},{"n":208,"text":"\t\t\tsignal: AbortSignal.timeout(30_000),","atom":"a287","author":"pinch","version":34},{"n":209,"text":"\t\t});","atom":"a287","author":"pinch","version":34},{"n":210,"text":"\t} catch (err) {","atom":"a287","author":"pinch","version":34},{"n":211,"text":"\t\tthrow new UsageError(","atom":"a287","author":"pinch","version":34},{"n":212,"text":"\t\t\t`couldn't reach ${originOf(record.server)}: ${scrub(err instanceof Error ? err.message : String(err), secrets)}`,","atom":"a287","author":"pinch","version":34},{"n":213,"text":"\t\t);","atom":"a287","author":"pinch","version":34},{"n":214,"text":"\t}","atom":"a287","author":"pinch","version":34},{"n":215,"text":"\tconst text = await response.text();","atom":"a287","author":"pinch","version":34},{"n":216,"text":"\ttry {","atom":"a287","author":"pinch","version":34},{"n":217,"text":"\t\tconst body = JSON.parse(text) as unknown;","atom":"a287","author":"pinch","version":34},{"n":218,"text":"\t\tif (typeof body === \"object\" && body !== null && !Array.isArray(body))","atom":"a287","author":"pinch","version":34},{"n":219,"text":"\t\t\treturn { status: response.status, body: body as Record<string, unknown> };","atom":"a287","author":"pinch","version":34},{"n":220,"text":"\t} catch {}","atom":"a287","author":"pinch","version":34},{"n":221,"text":"\treturn { status: response.status, body: { error: scrub(text.slice(0, 300), secrets) } };","atom":"a287","author":"pinch","version":34},{"n":222,"text":"}","atom":"a287","author":"pinch","version":34},{"n":223,"text":"","atom":"a287","author":"pinch","version":34},{"n":224,"text":"/** This machine's name, as the server takes a box's name: 1-64 letters, digits, '.', '_' or '-'. */","atom":"a0","author":"init","version":0},{"n":225,"text":"export function boxName(): string {","atom":"a2637","author":"approvals-page","version":259},{"n":226,"text":"\tconst name = hostname()","atom":"a0","author":"init","version":0},{"n":227,"text":"\t\t.replace(/[^A-Za-z0-9._-]/g, \"-\")","atom":"a0","author":"init","version":0},{"n":228,"text":"\t\t.replace(/^[^A-Za-z0-9]+/, \"\")","atom":"a0","author":"init","version":0},{"n":229,"text":"\t\t.slice(0, 64);","atom":"a0","author":"init","version":0},{"n":230,"text":"\treturn name || \"box\";","atom":"a0","author":"init","version":0},{"n":231,"text":"}","atom":"a0","author":"init","version":0},{"n":232,"text":"","atom":"a0","author":"init","version":0},{"n":233,"text":"function isGrant(g: unknown): g is Grant {","atom":"a0","author":"init","version":0},{"n":234,"text":"\tconst x = g as Partial<Grant> | null;","atom":"a0","author":"init","version":0},{"n":235,"text":"\treturn (","atom":"a0","author":"init","version":0},{"n":236,"text":"\t\ttypeof x === \"object\" &&","atom":"a0","author":"init","version":0},{"n":237,"text":"\t\tx !== null &&","atom":"a0","author":"init","version":0},{"n":238,"text":"\t\tArray.isArray(x.projects) &&","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\tx.projects.every((p) => typeof p?.project === \"string\" && typeof p.role === \"string\")","atom":"a1848","author":"open","version":171},{"n":240,"text":"\t);","atom":"a0","author":"init","version":0},{"n":241,"text":"}","atom":"a0","author":"init","version":0},{"n":242,"text":"","atom":"a0","author":"init","version":0},{"n":243,"text":"/** The longest login waits for approval, whatever the server says. */","atom":"a585","author":"pinch","version":58},{"n":244,"text":"const MAX_LOGIN_WAIT_S = 30 * 60;","atom":"a585","author":"pinch","version":58},{"n":245,"text":"/** How often login says it's still waiting. */","atom":"a585","author":"pinch","version":58},{"n":246,"text":"const STILL_WAITING_MS = 60_000;","atom":"a585","author":"pinch","version":58},{"n":247,"text":"","atom":"a585","author":"pinch","version":58},{"n":248,"text":"export interface LoginIo {","atom":"a0","author":"init","version":0},{"n":249,"text":"\treadonly request?: LoginRequest;","atom":"a920","author":"codex-mac-1","version":102},{"n":250,"text":"\treadonly fetch?: typeof fetch;","atom":"a0","author":"init","version":0},{"n":251,"text":"\treadonly sleep?: (ms: number) => Promise<void>;","atom":"a0","author":"init","version":0},{"n":252,"text":"\treadonly now?: () => number;","atom":"a0","author":"init","version":0},{"n":253,"text":"\t/** Where the code and link go while login waits: stderr, so stdout stays quiet. */","atom":"a0","author":"init","version":0},{"n":254,"text":"\treadonly say: (line: string) => void;","atom":"a0","author":"init","version":0},{"n":255,"text":"\t/** Opens the approve page in a browser, answering whether it tried. None where it shouldn't (--no-browser, SSH, CI). */","atom":"a606","author":"speed","version":60},{"n":256,"text":"\treadonly open?: (url: string) => boolean;","atom":"a606","author":"speed","version":60},{"n":257,"text":"\t/**","atom":"a2637","author":"approvals-page","version":259},{"n":258,"text":"\t * abso 684: in a joined folder, asks a person in its project to approve this sign-in, through an abso ask, so nobody","atom":"a2637","author":"approvals-page","version":259},{"n":259,"text":"\t * relays the code. Answers who was asked, or null to fall back to the code alone.","atom":"a2637","author":"approvals-page","version":259},{"n":260,"text":"\t */","atom":"a2637","author":"approvals-page","version":259},{"n":261,"text":"\treadonly ask?: (codes: { readonly device: string; readonly user: string }) => Promise<LoginAsked | null>;","atom":"a2637","author":"approvals-page","version":259},{"n":262,"text":"}","atom":"a0","author":"init","version":0},{"n":263,"text":"","atom":"a0","author":"init","version":0},{"n":264,"text":"/** A sign-in asked of people (abso 684). */","atom":"a2637","author":"approvals-page","version":259},{"n":265,"text":"export interface LoginAsked {","atom":"a2637","author":"approvals-page","version":259},{"n":266,"text":"\treadonly project: string;","atom":"a2637","author":"approvals-page","version":259},{"n":267,"text":"\t/** \"the person who approved this agent's box\", or \"the owners of <project>\". */","atom":"a2637","author":"approvals-page","version":259},{"n":268,"text":"\treadonly who: string;","atom":"a2637","author":"approvals-page","version":259},{"n":269,"text":"\treadonly asks: readonly number[];","atom":"a2637","author":"approvals-page","version":259},{"n":270,"text":"\t/** Milliseconds: when the asked sign-in runs out. */","atom":"a2637","author":"approvals-page","version":259},{"n":271,"text":"\treadonly expiresAt: number;","atom":"a2637","author":"approvals-page","version":259},{"n":272,"text":"\t/** The most the box may be granted: the asking agent's own role. */","atom":"a2637","author":"approvals-page","version":259},{"n":273,"text":"\treadonly role: string;","atom":"a2637","author":"approvals-page","version":259},{"n":274,"text":"\t/** Withdraws the asks once nobody answered in time. */","atom":"a2637","author":"approvals-page","version":259},{"n":275,"text":"\treadonly withdraw: () => Promise<void>;","atom":"a2637","author":"approvals-page","version":259},{"n":276,"text":"}","atom":"a2637","author":"approvals-page","version":259},{"n":277,"text":"","atom":"a2637","author":"approvals-page","version":259},{"n":278,"text":"const CENTRAL = new Intl.DateTimeFormat(\"en-US\", { timeZone: \"America/Chicago\", hour: \"numeric\", minute: \"2-digit\" });","atom":"a2637","author":"approvals-page","version":259},{"n":279,"text":"","atom":"a2637","author":"approvals-page","version":259},{"n":280,"text":"/**","atom":"a0","author":"init","version":0},{"n":281,"text":" * Asks `server` for a code, shows it with its link, and waits for a person to","atom":"a0","author":"init","version":0},{"n":282,"text":" * approve it. Answers the box's record, already written to the config folder.","atom":"a0","author":"init","version":0},{"n":283,"text":" */","atom":"a0","author":"init","version":0},{"n":284,"text":"export async function login(server: string, io: LoginIo, home = homedir()): Promise<BoxRecord> {","atom":"a0","author":"init","version":0},{"n":285,"text":"\tconst fetcher = io.fetch ?? fetch;","atom":"a0","author":"init","version":0},{"n":286,"text":"\tconst sleep = io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));","atom":"a0","author":"init","version":0},{"n":287,"text":"\tconst now = io.now ?? Date.now;","atom":"a0","author":"init","version":0},{"n":288,"text":"\tconst start = await call(","atom":"a920","author":"codex-mac-1","version":102},{"n":289,"text":"\t\tserver,","atom":"a920","author":"codex-mac-1","version":102},{"n":290,"text":"\t\t\"/login/device\",","atom":"a920","author":"codex-mac-1","version":102},{"n":291,"text":"\t\t{ name: boxName(), client: \"abso\", ...(io.request ? { requested_grant: io.request } : {}) },","atom":"a920","author":"codex-mac-1","version":102},{"n":292,"text":"\t\tundefined,","atom":"a920","author":"codex-mac-1","version":102},{"n":293,"text":"\t\tfetcher,","atom":"a920","author":"codex-mac-1","version":102},{"n":294,"text":"\t);","atom":"a920","author":"codex-mac-1","version":102},{"n":295,"text":"\tconst { device_code: device, user_code: code, verification_uri_complete: link } = start.body;","atom":"a0","author":"init","version":0},{"n":296,"text":"\tlet interval = Number(start.body.interval) || 5;","atom":"a0","author":"init","version":0},{"n":297,"text":"\t// The server says when its code runs out; a server that says never still gets an end.","atom":"a585","author":"pinch","version":58},{"n":298,"text":"\tconst expiresIn = Math.min(Number(start.body.expires_in) || 900, MAX_LOGIN_WAIT_S);","atom":"a585","author":"pinch","version":58},{"n":299,"text":"\tif (typeof code !== \"string\" || typeof link !== \"string\" || typeof device !== \"string\")","atom":"a0","author":"init","version":0},{"n":300,"text":"\t\tthrow new UsageError(`${originOf(server)} didn't give a code to approve`);","atom":"a0","author":"init","version":0},{"n":301,"text":"\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.","atom":"a606","author":"speed","version":60},{"n":302,"text":"\t// A failed ask falls back to the code, and says why, so a person can still approve it (abso 684).","atom":"a2663","author":"approvals-page","version":264},{"n":303,"text":"\tconst asked = io.ask","atom":"a2663","author":"approvals-page","version":264},{"n":304,"text":"\t\t? await io.ask({ device, user: code }).catch((e: unknown) => {","atom":"a2663","author":"approvals-page","version":264},{"n":305,"text":"\t\t\t\tio.say(","atom":"a2663","author":"approvals-page","version":264},{"n":306,"text":"\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.`,","atom":"a2663","author":"approvals-page","version":264},{"n":307,"text":"\t\t\t\t);","atom":"a2663","author":"approvals-page","version":264},{"n":308,"text":"\t\t\t\treturn null;","atom":"a2663","author":"approvals-page","version":264},{"n":309,"text":"\t\t\t})","atom":"a2663","author":"approvals-page","version":264},{"n":310,"text":"\t\t: null;","atom":"a2663","author":"approvals-page","version":264},{"n":311,"text":"\tif (asked) {","atom":"a2637","author":"approvals-page","version":259},{"n":312,"text":"\t\tconst askWord = asked.asks.length === 1 ? `ask ${asked.asks[0]}` : `asks ${asked.asks.join(\", \")}`;","atom":"a2637","author":"approvals-page","version":259},{"n":313,"text":"\t\tio.say(`Asked ${asked.who} (${askWord} in ${asked.project}) to sign this box in, as at most ${asked.role}.`);","atom":"a2637","author":"approvals-page","version":259},{"n":314,"text":"\t\tio.say(","atom":"a2637","author":"approvals-page","version":259},{"n":315,"text":"\t\t\t`Waiting for their answer, until ${CENTRAL.format(new Date(asked.expiresAt))} CT. To approve it yourself instead: ${link}`,","atom":"a2637","author":"approvals-page","version":259},{"n":316,"text":"\t\t);","atom":"a2637","author":"approvals-page","version":259},{"n":317,"text":"\t} else {","atom":"a2637","author":"approvals-page","version":259},{"n":318,"text":"\t\tif (io.open?.(link)) io.say(\"Opening the approve page in your browser.\");","atom":"a2637","author":"approvals-page","version":259},{"n":319,"text":"\t\tio.say(`To sign this box in, open ${link} and approve the code ${code}.`);","atom":"a2637","author":"approvals-page","version":259},{"n":320,"text":"\t\tio.say(\"Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.\");","atom":"a2637","author":"approvals-page","version":259},{"n":321,"text":"\t}","atom":"a2637","author":"approvals-page","version":259},{"n":322,"text":"\tconst until = asked ? Math.min(asked.expiresAt, now() + MAX_LOGIN_WAIT_S * 1000) : now() + expiresIn * 1000;","atom":"a2637","author":"approvals-page","version":259},{"n":323,"text":"\tlet toldAt = now();","atom":"a585","author":"pinch","version":58},{"n":324,"text":"\twhile (now() < until) {","atom":"a0","author":"init","version":0},{"n":325,"text":"\t\tawait sleep(interval * 1000);","atom":"a0","author":"init","version":0},{"n":326,"text":"\t\t// A wait with no word looks like a hang, so say it's still waiting now and then.","atom":"a585","author":"pinch","version":58},{"n":327,"text":"\t\tif (now() - toldAt >= STILL_WAITING_MS) {","atom":"a585","author":"pinch","version":58},{"n":328,"text":"\t\t\tio.say(","atom":"a2637","author":"approvals-page","version":259},{"n":329,"text":"\t\t\t\tasked","atom":"a2637","author":"approvals-page","version":259},{"n":330,"text":"\t\t\t\t\t? `Still waiting (${asked.who} hasn't answered yet).`","atom":"a2637","author":"approvals-page","version":259},{"n":331,"text":"\t\t\t\t\t: `Still waiting for the code ${code} to be approved.`,","atom":"a2637","author":"approvals-page","version":259},{"n":332,"text":"\t\t\t);","atom":"a2637","author":"approvals-page","version":259},{"n":333,"text":"\t\t\ttoldAt = now();","atom":"a585","author":"pinch","version":58},{"n":334,"text":"\t\t}","atom":"a585","author":"pinch","version":58},{"n":335,"text":"\t\tconst a = await call(server, \"/login/token\", { device_code: device }, undefined, fetcher);","atom":"a0","author":"init","version":0},{"n":336,"text":"\t\tif (a.status === 400) {","atom":"a0","author":"init","version":0},{"n":337,"text":"\t\t\tif (a.body.error === \"authorization_pending\") continue;","atom":"a0","author":"init","version":0},{"n":338,"text":"\t\t\tif (a.body.error === \"slow_down\") {","atom":"a0","author":"init","version":0},{"n":339,"text":"\t\t\t\tinterval += 5;","atom":"a0","author":"init","version":0},{"n":340,"text":"\t\t\t\tcontinue;","atom":"a0","author":"init","version":0},{"n":341,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":342,"text":"\t\t\tif (a.body.error === \"access_denied\")","atom":"a2637","author":"approvals-page","version":259},{"n":343,"text":"\t\t\t\tthrow new UsageError(asked ? `${asked.who} turned this sign-in down.` : `the code ${code} was turned down.`);","atom":"a2637","author":"approvals-page","version":259},{"n":344,"text":"\t\t\tif (asked) await asked.withdraw().catch(() => undefined);","atom":"a2637","author":"approvals-page","version":259},{"n":345,"text":"\t\t\tthrow new UsageError(","atom":"a2637","author":"approvals-page","version":259},{"n":346,"text":"\t\t\t\tasked","atom":"a2637","author":"approvals-page","version":259},{"n":347,"text":"\t\t\t\t\t? \"nobody answered in time, so nothing was granted. Run abso login again.\"","atom":"a2637","author":"approvals-page","version":259},{"n":348,"text":"\t\t\t\t\t: `the code ${code} ran out. Run abso login again.`,","atom":"a2637","author":"approvals-page","version":259},{"n":349,"text":"\t\t\t);","atom":"a2637","author":"approvals-page","version":259},{"n":350,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":351,"text":"\t\tconst { box_token: credential, box_id: id, grant, expires_at } = a.body;","atom":"a0","author":"init","version":0},{"n":352,"text":"\t\tconst expiresAt = typeof expires_at === \"string\" ? Date.parse(expires_at) : Number.NaN;","atom":"a0","author":"init","version":0},{"n":353,"text":"\t\tif (typeof credential !== \"string\" || typeof id !== \"string\" || !isGrant(grant) || Number.isNaN(expiresAt))","atom":"a0","author":"init","version":0},{"n":354,"text":"\t\t\tthrow new UsageError(`${originOf(server)} approved the code but sent no credential`);","atom":"a0","author":"init","version":0},{"n":355,"text":"\t\tconst record: BoxRecord = { server: originOf(server), id, credential, grant, expiresAt };","atom":"a0","author":"init","version":0},{"n":356,"text":"\t\twriteBox(record, home);","atom":"a0","author":"init","version":0},{"n":357,"text":"\t\treturn record;","atom":"a0","author":"init","version":0},{"n":358,"text":"\t}","atom":"a2637","author":"approvals-page","version":259},{"n":359,"text":"\tif (asked) {","atom":"a2637","author":"approvals-page","version":259},{"n":360,"text":"\t\tawait asked.withdraw().catch(() => undefined);","atom":"a2637","author":"approvals-page","version":259},{"n":361,"text":"\t\tthrow new UsageError(\"nobody answered in time, so nothing was granted. Run abso login again.\");","atom":"a2637","author":"approvals-page","version":259},{"n":362,"text":"\t}","atom":"a0","author":"init","version":0},{"n":363,"text":"\tthrow new UsageError(`nobody approved the code ${code} in time. Run abso login again.`);","atom":"a0","author":"init","version":0},{"n":364,"text":"}","atom":"a0","author":"init","version":0},{"n":365,"text":"","atom":"a0","author":"init","version":0},{"n":366,"text":"/** An agent's own key, minted from the box's credential: `{key, id}`, as `abso key install` takes it. */","atom":"a0","author":"init","version":0},{"n":367,"text":"export async function mintKey(","atom":"a0","author":"init","version":0},{"n":368,"text":"\trecord: BoxRecord,","atom":"a0","author":"init","version":0},{"n":369,"text":"\tproject: string,","atom":"a0","author":"init","version":0},{"n":370,"text":"\tagent: string,","atom":"a0","author":"init","version":0},{"n":371,"text":"\tfetcher: typeof fetch = fetch,","atom":"a0","author":"init","version":0},{"n":372,"text":"): Promise<{ key: string; id: string }> {","atom":"a0","author":"init","version":0},{"n":373,"text":"\tconst a = await call(record.server, \"/box/agent-key\", { project, agent }, record.credential, fetcher);","atom":"a0","author":"init","version":0},{"n":374,"text":"\tconst { key, id } = a.body;","atom":"a0","author":"init","version":0},{"n":375,"text":"\tif (typeof key !== \"string\" || typeof id !== \"string\")","atom":"a0","author":"init","version":0},{"n":376,"text":"\t\tthrow new UsageError(`${record.server} didn't send a key for ${agent}`);","atom":"a0","author":"init","version":0},{"n":377,"text":"\treturn { key, id };","atom":"a0","author":"init","version":0},{"n":378,"text":"}","atom":"a2071","author":"box-grants","version":185},{"n":379,"text":"","atom":"a2071","author":"box-grants","version":185},{"n":380,"text":"/** What a new project from this box starts with (abso 663): the website's own create, as the person who approved the box. */","atom":"a2071","author":"box-grants","version":185},{"n":381,"text":"export interface NewProject {","atom":"a2071","author":"box-grants","version":185},{"n":382,"text":"\treadonly name: string;","atom":"a2071","author":"box-grants","version":185},{"n":383,"text":"\treadonly owner?: string;","atom":"a2071","author":"box-grants","version":185},{"n":384,"text":"\treadonly visibility?: \"public\" | \"private\";","atom":"a2071","author":"box-grants","version":185},{"n":385,"text":"\treadonly files?: readonly (","atom":"a2071","author":"box-grants","version":185},{"n":386,"text":"\t\t| { readonly path: string; readonly text: string }","atom":"a2071","author":"box-grants","version":185},{"n":387,"text":"\t\t| { readonly path: string; readonly base64: string }","atom":"a2071","author":"box-grants","version":185},{"n":388,"text":"\t)[];","atom":"a2071","author":"box-grants","version":185},{"n":389,"text":"}","atom":"a2071","author":"box-grants","version":185},{"n":390,"text":"","atom":"a2071","author":"box-grants","version":185},{"n":391,"text":"/**","atom":"a2071","author":"box-grants","version":185},{"n":392,"text":" * Makes a project as the person who approved this box (abso init, abso 663). One key for every try, so a retry after","atom":"a2071","author":"box-grants","version":185},{"n":393,"text":" * a lost answer or a pending one is the same project, never a second.","atom":"a2071","author":"box-grants","version":185},{"n":394,"text":" */","atom":"a2071","author":"box-grants","version":185},{"n":395,"text":"export async function boxCreateProject(","atom":"a2071","author":"box-grants","version":185},{"n":396,"text":"\trecord: BoxRecord,","atom":"a2071","author":"box-grants","version":185},{"n":397,"text":"\tproject: NewProject,","atom":"a2071","author":"box-grants","version":185},{"n":398,"text":"\tkey: string,","atom":"a2071","author":"box-grants","version":185},{"n":399,"text":"\tfetcher: typeof fetch = fetch,","atom":"a2071","author":"box-grants","version":185},{"n":400,"text":"\tsleep: (ms: number) => Promise<void> = (ms) => new Promise((done) => setTimeout(done, ms)),","atom":"a2071","author":"box-grants","version":185},{"n":401,"text":"): Promise<Record<string, unknown>> {","atom":"a2071","author":"box-grants","version":185},{"n":402,"text":"\tfor (let attempt = 1; ; attempt++) {","atom":"a2071","author":"box-grants","version":185},{"n":403,"text":"\t\tconst a = await call(record.server, \"/box/projects\", project, record.credential, fetcher, {","atom":"a2071","author":"box-grants","version":185},{"n":404,"text":"\t\t\t\"Idempotency-Key\": key,","atom":"a2071","author":"box-grants","version":185},{"n":405,"text":"\t\t});","atom":"a2071","author":"box-grants","version":185},{"n":406,"text":"\t\tconst pending = (a.body.operation as { state?: unknown } | undefined)?.state === \"pending\";","atom":"a2071","author":"box-grants","version":185},{"n":407,"text":"\t\tif (!pending) return a.body;","atom":"a2071","author":"box-grants","version":185},{"n":408,"text":"\t\tif (attempt >= 10)","atom":"a2071","author":"box-grants","version":185},{"n":409,"text":"\t\t\tthrow new UsageError(","atom":"a2071","author":"box-grants","version":185},{"n":410,"text":"\t\t\t\t`${originOf(record.server)} is still making ${project.name}. Run the same abso init again in a minute: it picks up where this left off.`,","atom":"a2071","author":"box-grants","version":185},{"n":411,"text":"\t\t\t);","atom":"a2071","author":"box-grants","version":185},{"n":412,"text":"\t\tawait sleep(1000 * attempt);","atom":"a2071","author":"box-grants","version":185},{"n":413,"text":"\t}","atom":"a2071","author":"box-grants","version":185},{"n":414,"text":"}","atom":"a2071","author":"box-grants","version":185},{"n":415,"text":"","atom":"a2071","author":"box-grants","version":185},{"n":416,"text":"/** Makes an organization as the person who approved this box (abso org new, abso 663). */","atom":"a2071","author":"box-grants","version":185},{"n":417,"text":"export async function boxCreateOrg(","atom":"a2071","author":"box-grants","version":185},{"n":418,"text":"\trecord: BoxRecord,","atom":"a2071","author":"box-grants","version":185},{"n":419,"text":"\tname: string,","atom":"a2071","author":"box-grants","version":185},{"n":420,"text":"\tdisplayName: string | undefined,","atom":"a2071","author":"box-grants","version":185},{"n":421,"text":"\tfetcher: typeof fetch = fetch,","atom":"a2071","author":"box-grants","version":185},{"n":422,"text":"): Promise<Record<string, unknown>> {","atom":"a2071","author":"box-grants","version":185},{"n":423,"text":"\treturn (","atom":"a2071","author":"box-grants","version":185},{"n":424,"text":"\t\tawait call(","atom":"a2071","author":"box-grants","version":185},{"n":425,"text":"\t\t\trecord.server,","atom":"a2071","author":"box-grants","version":185},{"n":426,"text":"\t\t\t\"/box/orgs\",","atom":"a2071","author":"box-grants","version":185},{"n":427,"text":"\t\t\t{ name, ...(displayName === undefined ? {} : { displayName }) },","atom":"a2071","author":"box-grants","version":185},{"n":428,"text":"\t\t\trecord.credential,","atom":"a2071","author":"box-grants","version":185},{"n":429,"text":"\t\t\tfetcher,","atom":"a2071","author":"box-grants","version":185},{"n":430,"text":"\t\t)","atom":"a2071","author":"box-grants","version":185},{"n":431,"text":"\t).body;","atom":"a2071","author":"box-grants","version":185},{"n":432,"text":"}","atom":"a0","author":"init","version":0},{"n":433,"text":"","atom":"a0","author":"init","version":0},{"n":434,"text":"/** The agent name abso join takes when none is given: the box's name, lower-cased. */","atom":"a626","author":"trials","version":64},{"n":435,"text":"export function defaultAgentName(): string {","atom":"a620","author":"trials","version":63},{"n":436,"text":"\treturn boxName().toLowerCase();","atom":"a620","author":"trials","version":63},{"n":437,"text":"}","atom":"a620","author":"trials","version":63},{"n":438,"text":"","atom":"a620","author":"trials","version":63},{"n":439,"text":"/**","atom":"a620","author":"trials","version":63},{"n":440,"text":" * abso join with no --agent: mints a key under `base`, else `base`-2, -3 and so on. Names this","atom":"a626","author":"trials","version":64},{"n":441,"text":" * box already holds in the project are skipped without asking, since minting one again would replace that agent's","atom":"a620","author":"trials","version":63},{"n":442,"text":" * key and cut off its folder. A name the server says is taken (409) moves on to the next; any other refusal, the","atom":"a620","author":"trials","version":63},{"n":443,"text":" * box's agent limit among them, is said as it is.","atom":"a620","author":"trials","version":63},{"n":444,"text":" */","atom":"a620","author":"trials","version":63},{"n":445,"text":"export async function mintFreeName(","atom":"a620","author":"trials","version":63},{"n":446,"text":"\trecord: BoxRecord,","atom":"a620","author":"trials","version":63},{"n":447,"text":"\tproject: string,","atom":"a620","author":"trials","version":63},{"n":448,"text":"\tbase: string,","atom":"a620","author":"trials","version":63},{"n":449,"text":"\tfetcher: typeof fetch = fetch,","atom":"a620","author":"trials","version":63},{"n":450,"text":"\ttries = 20,","atom":"a620","author":"trials","version":63},{"n":451,"text":"): Promise<{ key: string; id: string; agent: string }> {","atom":"a620","author":"trials","version":63},{"n":452,"text":"\tconst box = await boxGet(record, \"/box\", fetcher);","atom":"a620","author":"trials","version":63},{"n":453,"text":"\tif (box.status !== 200)","atom":"a620","author":"trials","version":63},{"n":454,"text":"\t\tthrow new UsageError(","atom":"a620","author":"trials","version":63},{"n":455,"text":"\t\t\t`${originOf(record.server)} refused (${box.status}): ${String(box.body.error ?? \"no reason given\")}`,","atom":"a620","author":"trials","version":63},{"n":456,"text":"\t\t);","atom":"a620","author":"trials","version":63},{"n":457,"text":"\tconst agents = Array.isArray(box.body.agents) ? (box.body.agents as { project?: unknown; agent?: unknown }[]) : [];","atom":"a620","author":"trials","version":63},{"n":458,"text":"\tconst held = new Set(agents.filter((a) => a.project === project).map((a) => String(a.agent)));","atom":"a620","author":"trials","version":63},{"n":459,"text":"\tfor (let n = 1; n <= tries; n++) {","atom":"a620","author":"trials","version":63},{"n":460,"text":"\t\tconst agent = n === 1 ? base : `${base}-${n}`;","atom":"a620","author":"trials","version":63},{"n":461,"text":"\t\tif (held.has(agent)) continue;","atom":"a620","author":"trials","version":63},{"n":462,"text":"\t\ttry {","atom":"a620","author":"trials","version":63},{"n":463,"text":"\t\t\treturn { ...(await mintKey(record, project, agent, fetcher)), agent };","atom":"a620","author":"trials","version":63},{"n":464,"text":"\t\t} catch (err) {","atom":"a620","author":"trials","version":63},{"n":465,"text":"\t\t\tif (err instanceof UsageError && /refused \\(409\\): that agent name/.test(err.message)) continue;","atom":"a620","author":"trials","version":63},{"n":466,"text":"\t\t\tthrow err;","atom":"a620","author":"trials","version":63},{"n":467,"text":"\t\t}","atom":"a620","author":"trials","version":63},{"n":468,"text":"\t}","atom":"a620","author":"trials","version":63},{"n":469,"text":"\tthrow new UsageError(","atom":"a620","author":"trials","version":63},{"n":470,"text":"\t\t`${base} through ${base}-${tries} are all taken in ${project}: give this agent a name with --agent <name>`,","atom":"a620","author":"trials","version":63},{"n":471,"text":"\t);","atom":"a620","author":"trials","version":63},{"n":472,"text":"}","atom":"a620","author":"trials","version":63},{"n":473,"text":"","atom":"a620","author":"trials","version":63},{"n":474,"text":"/** Ends the box on the server, then forgets it here. Forgets it even when the server can't be reached. */","atom":"a0","author":"init","version":0},{"n":475,"text":"export async function logout(record: BoxRecord, fetcher: typeof fetch = fetch, home = homedir()): Promise<boolean> {","atom":"a0","author":"init","version":0},{"n":476,"text":"\tlet ended = true;","atom":"a0","author":"init","version":0},{"n":477,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":478,"text":"\t\tawait call(record.server, \"/box/logout\", {}, record.credential, fetcher);","atom":"a0","author":"init","version":0},{"n":479,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":480,"text":"\t\tended = false;","atom":"a0","author":"init","version":0},{"n":481,"text":"\t}","atom":"a0","author":"init","version":0},{"n":482,"text":"\tforgetBox(record.server, home);","atom":"a0","author":"init","version":0},{"n":483,"text":"\treturn ended;","atom":"a0","author":"init","version":0},{"n":484,"text":"}","atom":"a0","author":"init","version":0},{"n":485,"text":"","atom":"a0","author":"init","version":0},{"n":486,"text":"const day = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace(\"T\", \" \");","atom":"a0","author":"init","version":0},{"n":487,"text":"","atom":"a0","author":"init","version":0},{"n":488,"text":"/** What `abso box` prints: the grant, never the credential. */","atom":"a0","author":"init","version":0},{"n":489,"text":"export function boxText(record: BoxRecord | undefined, server: string, now = Date.now()): string {","atom":"a0","author":"init","version":0},{"n":490,"text":"\tif (!record) return `This box isn't signed in to ${originOf(server)}. abso login signs it in.`;","atom":"a0","author":"init","version":0},{"n":491,"text":"\tconst g = record.grant;","atom":"a0","author":"init","version":0},{"n":492,"text":"\tconst expired = record.expiresAt <= now;","atom":"a0","author":"init","version":0},{"n":493,"text":"\tconst all = allProjectsRole(g);","atom":"a2071","author":"box-grants","version":185},{"n":494,"text":"\treturn [","atom":"a0","author":"init","version":0},{"n":495,"text":"\t\t`Signed in to ${record.server} as box ${record.id}${expired ? \", but the sign-in has expired. abso login renews it.\" : \".\"}`,","atom":"a0","author":"init","version":0},{"n":496,"text":"\t\tall === null","atom":"a2071","author":"box-grants","version":185},{"n":497,"text":"\t\t\t? `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(\", \")}.`","atom":"a2071","author":"box-grants","version":185},{"n":498,"text":"\t\t\t: `Projects: all of yours, now and later (${all} at most). abso init makes a new one; abso org new makes an organization.`,","atom":"a2071","author":"box-grants","version":185},{"n":499,"text":"\t\t`${expired ? \"Expired\" : \"Expires\"} ${day(record.expiresAt)} UTC.`,","atom":"a0","author":"init","version":0},{"n":500,"text":"\t].join(\"\\n\");","atom":"a0","author":"init","version":0},{"n":501,"text":"}","atom":"a0","author":"init","version":0},{"n":502,"text":"","atom":"a0","author":"init","version":0},{"n":503,"text":"/** What `abso box --json` answers: the record without its credential. */","atom":"a0","author":"init","version":0},{"n":504,"text":"export function boxPublic(","atom":"a0","author":"init","version":0},{"n":505,"text":"\trecord: BoxRecord | undefined,","atom":"a0","author":"init","version":0},{"n":506,"text":"): { server: string; id: string; grant: Grant; expiresAt: string } | null {","atom":"a0","author":"init","version":0},{"n":507,"text":"\treturn record","atom":"a0","author":"init","version":0},{"n":508,"text":"\t\t? { server: record.server, id: record.id, grant: record.grant, expiresAt: new Date(record.expiresAt).toISOString() }","atom":"a0","author":"init","version":0},{"n":509,"text":"\t\t: null;","atom":"a0","author":"init","version":0},{"n":510,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a125","author":"review","message":"","time":1791522270512,"timeIso":"2026-10-09T05:04:30.512Z","publish":{"draft":null,"version":17,"agent":"review","message":"New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.","time":1791522270512,"timeIso":"2026-10-09T05:04:30.512Z"}},{"atom":"a286","author":"pinch","message":"","time":1791542921637,"timeIso":"2026-10-09T10:48:41.637Z","publish":{"draft":null,"version":34,"agent":"pinch","message":"Client: abso orgs and abso org <name>, reading as the person who approved this box's sign-in (abso login): your organizations and roles, invitations waiting for you, and an org's projects, people (by name, never id), settings and open invites. Changes (--invite, --role, --remove, --leave, --members, --projects-by), abso org new and abso init --org are made on the website for now; each says where and sends nothing. One change at a time. MCP serves orgs and org. Client tests 283/283, tsc and biome clean.","time":1791543392927,"timeIso":"2026-10-09T10:56:32.927Z"}},{"atom":"a287","author":"pinch","message":"","time":1791542924627,"timeIso":"2026-10-09T10:48:44.627Z","publish":{"draft":null,"version":34,"agent":"pinch","message":"Client: abso orgs and abso org <name>, reading as the person who approved this box's sign-in (abso login): your organizations and roles, invitations waiting for you, and an org's projects, people (by name, never id), settings and open invites. Changes (--invite, --role, --remove, --leave, --members, --projects-by), abso org new and abso init --org are made on the website for now; each says where and sends nothing. One change at a time. MCP serves orgs and org. Client tests 283/283, tsc and biome clean.","time":1791543392927,"timeIso":"2026-10-09T10:56:32.927Z"}},{"atom":"a585","author":"pinch","message":"","time":1791598040070,"timeIso":"2026-10-10T02:07:20.070Z","publish":{"draft":null,"version":58,"agent":"pinch","message":"abso login says it is waiting for approval, and that Ctrl-C stops it, then says it is still waiting about once a minute. It stops by itself when the code runs out, and never waits past 30 minutes whatever the server's expires_in says. A login that said nothing for 15 minutes looked like a hang.","time":1791598042242,"timeIso":"2026-10-10T02:07:22.242Z"}},{"atom":"a606","author":"speed","message":"","time":1791600855389,"timeIso":"2026-10-10T02:54:15.389Z","publish":{"draft":null,"version":60,"agent":"speed","message":"abso login opens the approve page in the browser\n\nLike gh auth login and wrangler login: abso login opens the approve page in the default browser with the code already in it, so nobody copies a link by hand. It still prints the link and the code, which stand when the open fails or is skipped.\n\n- Windows opens with rundll32 url.dll,FileProtocolHandler, macOS with open, Linux with xdg-open. There's no shell, so a link with & in it arrives whole (cmd's start would cut it).\n- No browser with --no-browser or ABSO_NO_BROWSER, over SSH (SSH_CONNECTION or SSH_TTY), under CI, or on Linux and other Unixes with neither DISPLAY nor WAYLAND_DISPLAY.\n- Only http and https links are opened, so a link from a server is never handed to the desktop as a file or a program.\n- The opener starts detached and isn't waited on; a failure is silent.\n\nTests: open-browser.test.ts (each skip, each platform's command, web links only, a failing opener is silent), and two login tests with an injected opener.","time":1791600855763,"timeIso":"2026-10-10T02:54:15.763Z"}},{"atom":"a613","author":"trials","message":"","time":1791600856656,"timeIso":"2026-10-10T02:54:16.656Z","publish":{"draft":null,"version":61,"agent":"trials","message":"abso join and abso init no longer need --server (abso issue 349): --server, then ABSO_SERVER, then the server this box signed in to with abso login, then https://api.abso.dev. A box signed in to more than one server is asked to say which. Usage, about text and the README's join line updated; box.test.ts covers the order.","time":1791600859268,"timeIso":"2026-10-10T02:54:19.268Z"}},{"atom":"a620","author":"trials","message":"","time":1791601554431,"timeIso":"2026-10-10T03:05:54.431Z","publish":{"draft":null,"version":63,"agent":"trials","message":"abso join <project> works with no --agent and no --dir (abso issue 351), so the project page can show npx abso-cli join <project>.\n\n- Agent: the box's name (the hostname abso login sends), lower-cased; if taken, <name>-2, -3, up to 20 tries. Names this box already holds in the project (GET /box) are skipped without minting, since minting one again replaces that agent's key and would cut off its folder. A 409 for a taken name moves on; the agent-limit 409 says the limit and where to revoke. No box sign-in: abso login first, or --agent.\n- Folder: --dir, else here when empty, else ./<project>, which must be new or empty; it prints cd <folder> when it isn't here.\n- --agent, --dir and --server still win. Project names are checked before use as a folder.\nTests: box.test.ts (mintFreeName: held name skipped, 409 moves on, agent limit), client.test.ts (empty folder, ./<project>, refusing a non-empty one); the git line-endings test now joins with --dir . since its folder has files.","time":1791601556423,"timeIso":"2026-10-10T03:05:56.423Z"}},{"atom":"a626","author":"trials","message":"","time":1791601972847,"timeIso":"2026-10-10T03:12:52.847Z","publish":{"draft":null,"version":64,"agent":"trials","message":"join: a folder prepared with abso key install --server is joined where it is again (Pinch's catch on 63).\n\n- --agent keeps 'here' as the default, as before 63, so scripts that join into a prepared folder still do. The ./<project> rule is only for a join with no --agent.\n- A folder holding only abso's own state folder (.abso, or the older .avcs) counts as empty.\n- New tests: joinFolder's rule (empty, only .abso, files here, --agent, --dir, a taken ./<project>), and a runJoin test that installs a key with --server and joins with --agent and no --dir: it joins here and sends that key (the shared token is wrong, so only the key gets through). The git line-endings test is back to joining without --dir.\n- Issue numbers taken out of the new code comments and test names.","time":1791601975047,"timeIso":"2026-10-10T03:12:55.047Z"}},{"atom":"a920","author":"codex-mac-1","message":"","time":1791680677633,"timeIso":"2026-10-11T01:04:37.633Z","publish":{"draft":null,"version":102,"agent":"codex-mac-1","message":"Let login request projects, roles, agent limits and duration","time":1791680699999,"timeIso":"2026-10-11T01:04:59.999Z"}},{"atom":"a1848","author":"open","message":"","time":1791965038684,"timeIso":"2026-10-14T08:03:58.684Z","publish":{"draft":null,"version":171,"agent":"open","message":"abso login drops --max-agents (abso ask 1947; Christopher, 2026-10-14: no arbitrary free limits). A box lets in any number of agents (the server stopped enforcing max_agents in abso 642): abso box no longer prints 'Up to N agents', the 'agent limit' 409 message is gone, and a stored grant without max_agents reads fine. Instant cutover, no alias. Bundle rebuilt.","time":1791965043647,"timeIso":"2026-10-14T08:04:03.647Z"}},{"atom":"a2071","author":"box-grants","message":"","time":1791994802453,"timeIso":"2026-10-14T16:20:02.453Z","publish":{"draft":null,"version":185,"agent":"box-grants","message":"abso init, init --org and org new from a signed-in box (abso 663). On a server this box is signed in to and with no token for it, abso init makes the project as the person who approved the box, through the server's POST /box/projects (the website's own create): its folder (up to 24 MB) is the first version, --public or --private picks visibility (private by default), --org makes it an organization's project, and one Idempotency-Key per folder (kept in .abso/init-key until it finishes) makes a retry the same project. The folder then joins at once with its own key from the box (--agent, else the box's name). abso org new <name> [--name] makes an organization through POST /box/orgs. abso box and login say 'all of yours, now and later' for a member-all grant. Without a box, init and init --org say to abso login. Tests: orgs, box, help; full suite passes.","time":1791994804231,"timeIso":"2026-10-14T16:20:04.231Z"}},{"atom":"a2637","author":"approvals-page","message":"","time":1792092902455,"timeIso":"2026-10-15T19:35:02.455Z","publish":{"draft":null,"version":259,"agent":"approvals-page","message":"Box sign-ins asked of a person (abso 684, client; Security's yes with changes on ask 2097). In an agent's folder on the same server, abso login also asks a person in that project to approve it, through POST /login/ask with the folder's agent key and this client's own device code, then an ordinary abso ask (to person:<id>) with the request link, linked with /login/ask/link. It says who it asked and until when, keeps the code link as a fallback, says who turned it down on a deny, and withdraws its ask when nobody answers in time. --no-ask shows the code only. Tests: client/test/box.test.ts, three new (abso 684).","time":1792093041064,"timeIso":"2026-10-15T19:37:21.064Z"}},{"atom":"a2663","author":"approvals-page","message":"","time":1792095519694,"timeIso":"2026-10-15T20:18:39.694Z","publish":{"draft":null,"version":264,"agent":"approvals-page","message":"abso login says why it couldn't ask a person (abso 684): when the ask step fails (the server refuses, a limit, Issues unreachable), it prints 'Couldn't ask a person to approve this (<reason>), so here is the code.' and falls back to the code, instead of falling back silently. Found trying 684 on staging. Tests: client/test/box.test.ts, 16 pass.","time":1792097612529,"timeIso":"2026-10-15T20:53:32.529Z"}}]}