{"draft":null,"from":101,"to":102,"files":[{"path":"client/src/box.ts","added":43,"removed":2,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -12,7 +12,7 @@\n import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n import { homedir, hostname } from \"node:os\";\n import { dirname, join } from \"node:path\";\n-import { UsageError } from \"./args.ts\";\n+import { type Parsed, str, UsageError } from \"./args.ts\";\n import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from \"./state-dir.ts\";\n \n /** What the person who approved the code allowed: each project with the highest role its agents get there, and how many agents. */\n@@ -21,6 +21,40 @@\n \treadonly max_agents: number;\n }\n \n+/** Requested access is a suggestion for the person approving, never an authorization. */\n+export interface LoginRequest {\n+\treadonly projects?: readonly { readonly project: string; readonly role: \"reader\" | \"writer\" | \"owner\" }[];\n+\treadonly max_agents?: number;\n+\treadonly days?: number;\n+}\n+\n+export function loginRequest(args: Parsed): LoginRequest | undefined {\n+\tconst projects = str(args, \"projects\");\n+\tconst role = str(args, \"role\");\n+\tconst maxAgents = str(args, \"max-agents\");\n+\tconst days = str(args, \"days\");\n+\tif (projects === undefined && role === undefined && maxAgents === undefined && days === undefined) return undefined;\n+\tif (role !== undefined && projects === undefined) throw new UsageError(\"--role needs --projects\");\n+\tconst requestedRole = role ?? \"writer\";\n+\tif (requestedRole !== \"reader\" && requestedRole !== \"writer\" && requestedRole !== \"owner\")\n+\t\tthrow new UsageError(\"--role is reader, writer or owner\");\n+\tconst names = projects?.split(\",\").map((name) => name.trim());\n+\tif (names && (names.length > 100 || names.some((name) => !/^[A-Za-z0-9._-]+$/.test(name))))\n+\t\tthrow new UsageError(\n+\t\t\t\"--projects is a comma-separated list of up to 100 project names (letters, digits, dot, dash and underscore)\",\n+\t\t);\n+\tconst integer = (value: string, name: string, max: number): number => {\n+\t\tif (!/^[0-9]+$/.test(value) || !Number.isInteger(Number(value)) || Number(value) < 1 || Number(value) > max)\n+\t\t\tthrow new UsageError(`--${name} is from 1 to ${max}`);\n+\t\treturn Number(value);\n+\t};\n+\treturn {\n+\t\t...(names ? { projects: [...new Set(names)].map((project) => ({ project, role: requestedRole })) } : {}),\n+\t\t...(maxAgents === undefined ? {} : { max_agents: integer(maxAgents, \"max-agents\", 50) }),\n+\t\t...(days === undefined ? {} : { days: integer(days, \"days\", 90) }),\n+\t};\n+}\n+\n export interface BoxRecord {\n \treadonly server: string;\n \treadonly id: string;\n@@ -205,6 +239,7 @@\n const STILL_WAITING_MS = 60_000;\n \n export interface LoginIo {\n+\treadonly request?: LoginRequest;\n \treadonly fetch?: typeof fetch;\n \treadonly sleep?: (ms: number) => Promise<void>;\n \treadonly now?: () => number;\n@@ -222,7 +257,13 @@\n \tconst fetcher = io.fetch ?? fetch;\n \tconst sleep = io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));\n \tconst now = io.now ?? Date.now;\n-\tconst start = await call(server, \"/login/device\", { name: boxName(), client: \"abso\" }, undefined, fetcher);\n+\tconst start = await call(\n+\t\tserver,\n+\t\t\"/login/device\",\n+\t\t{ name: boxName(), client: \"abso\", ...(io.request ? { requested_grant: io.request } : {}) },\n+\t\tundefined,\n+\t\tfetcher,\n+\t);\n \tconst { device_code: device, user_code: code, verification_uri_complete: link } = start.body;\n \tlet interval = Number(start.body.interval) || 5;\n \t// The server says when its code runs out; a server that says never still gets an end."}],"unmatched":[]}