{"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","changes":4,"change":1193,"files":["client/README.md","client/src/box.ts","client/src/main.ts","client/test/box.test.ts"],"draft":null,"diff":[{"path":"client/README.md","added":17,"removed":0,"diff":"--- a/client/README.md\n+++ b/client/README.md\n@@ -32,6 +32,23 @@\n \n ## Setting up a folder\n \n+### Requesting access at login\n+\n+An agent can request the access it needs when starting a box login:\n+\n+```bash\n+abso login --projects alpha,beta --role writer --max-agents 1 --days 30 --no-browser\n+```\n+\n+The client sends a `requested_grant` with the device request: `projects`\n+(each with `project` and `role`), `max_agents`, and `days`. Only supplied\n+fields are sent; project roles default to `writer`. The role option requires\n+projects. Agent limits range from 1 to 50 and durations from 1 to 90 days.\n+The person approving still chooses the actual grant and can narrow or reject\n+the request. Servers must support requested grants to prefill their approval\n+page; older servers may ignore the suggestions. Without these options, login\n+works as before. The request itself never authorizes access.\n+\n Folders and machines set up before abso had its name keep working: the older \n `.avcs/` folder, `~/.avcs/` files, `AVCS_` environment names and `.avcsignore` are \n read when the new ones are not there. New things are written under the new names."},{"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."},{"path":"client/src/main.ts","added":12,"removed":3,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -7,7 +7,7 @@\n import { ApiError } from \"./api.ts\";\n import { bool, type FlagSpec, type Parsed, parseArgs, str, UsageError } from \"./args.ts\";\n import { bodyFilesHelp, readBodyFiles, withBodyFiles } from \"./body-files.ts\";\n-import { boxPublic, boxText, login, logout, readBox } from \"./box.ts\";\n+import { boxPublic, boxText, login, loginRequest, logout, readBox } from \"./box.ts\";\n import { runDiff, runFiles, runLog, runRestore, runShow } from \"./changes.ts\";\n import { runCheckIgnore } from \"./check-ignore.ts\";\n import { runCi } from \"./ci.ts\";\n@@ -174,8 +174,16 @@\n \t\t},\n \t},\n \tlogin: {\n-\t\tflags: { server: \"string\", \"no-browser\": \"boolean\" },\n-\t\tusage: \"abso login [--server <url>] [--no-browser]\",\n+\t\tflags: {\n+\t\t\tserver: \"string\",\n+\t\t\t\"no-browser\": \"boolean\",\n+\t\t\tprojects: \"string\",\n+\t\t\trole: \"string\",\n+\t\t\t\"max-agents\": \"string\",\n+\t\t\tdays: \"string\",\n+\t\t},\n+\t\tusage:\n+\t\t\t\"abso login [--server <url>] [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]\",\n \t\tabout:\n \t\t\t\"Sign this box in once: it opens the approve page in your browser with the code filled in, prints the link and the code too, and waits while a person approves the code on the website, choosing the projects, the highest role and how many agents. Then abso join in any of those projects gives each agent its own key, with no approval. The box's sign-in is kept in your user folder, never in a project folder, and is never printed. Without --server, the folder's server, or https://api.abso.dev outside a folder. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display.\",\n \t\trun: async (args, env) => {\n@@ -185,6 +193,7 @@\n \t\t\t\t\t? undefined\n \t\t\t\t\t: (url: string) => openInBrowser(url);\n \t\t\tconst record = await login(server, {\n+\t\t\t\trequest: loginRequest(args),\n \t\t\t\tsay: (line) => process.stderr.write(terminalText(`${line}\\n`, colorsPass(process.stderr, env.env))),\n \t\t\t\topen,\n \t\t\t});"},{"path":"client/test/box.test.ts","added":99,"removed":0,"diff":"--- a/client/test/box.test.ts\n+++ b/client/test/box.test.ts\n@@ -7,11 +7,13 @@\n import { tmpdir } from \"node:os\";\n import { join } from \"node:path\";\n import { test } from \"node:test\";\n+import { parseArgs } from \"../src/args.ts\";\n import {\n \tboxPublic,\n \tboxText,\n \tforgetBox,\n \tlogin,\n+\tloginRequest,\n \tlogout,\n \tmintFreeName,\n \tmintKey,\n@@ -20,6 +22,7 @@\n \twriteBox,\n } from \"../src/box.ts\";\n import { serverFrom } from \"../src/join-commands.ts\";\n+import { main } from \"../src/main.ts\";\n \n const SERVER = \"https://staging.abso.example\";\n const CREDENTIAL = \"abso_bx_the-secret-credential\";\n@@ -67,6 +70,102 @@\n \t};\n }\n \n+test(\"login grant options validate project lists, roles, limits and duration\", () => {\n+\tconst request = (...words: string[]) =>\n+\t\tloginRequest(\n+\t\t\tparseArgs(\"login\", words, {\n+\t\t\t\tprojects: \"string\",\n+\t\t\t\trole: \"string\",\n+\t\t\t\t\"max-agents\": \"string\",\n+\t\t\t\tdays: \"string\",\n+\t\t\t}),\n+\t\t);\n+\tassert.equal(request(), undefined);\n+\tassert.deepEqual(request(\"--projects\", \"alpha, beta,alpha\", \"--max-agents\", \"1\", \"--days\", \"30\"), {\n+\t\tprojects: [\n+\t\t\t{ project: \"alpha\", role: \"writer\" },\n+\t\t\t{ project: \"beta\", role: \"writer\" },\n+\t\t],\n+\t\tmax_agents: 1,\n+\t\tdays: 30,\n+\t});\n+\tassert.deepEqual(request(\"--projects\", \"alpha\", \"--role\", \"reader\"), {\n+\t\tprojects: [{ project: \"alpha\", role: \"reader\" }],\n+\t});\n+\tassert.deepEqual(request(\"--projects\", \"alpha\", \"--role\", \"owner\"), {\n+\t\tprojects: [{ project: \"alpha\", role: \"owner\" }],\n+\t});\n+\tassert.deepEqual(request(\"--max-agents\", \"50\", \"--days\", \"90\"), { max_agents: 50, days: 90 });\n+\tfor (const words of [\n+\t\t[\"--role\", \"writer\"],\n+\t\t[\"--projects\", \"\"],\n+\t\t[\"--projects\", \"alpha,\"],\n+\t\t[\"--projects\", \"../alpha\"],\n+\t\t[\"--projects\", \"alpha\", \"--role\", \"admin\"],\n+\t\t[\"--projects\", Array.from({ length: 101 }, (_, i) => `p${i}`).join(\",\")],\n+\t])\n+\t\tassert.throws(() => request(...words));\n+\tfor (const flag of [\"--max-agents\", \"--days\"]) {\n+\t\tfor (const value of [\"0\", \"-1\", \"1.5\", \"1e1\", \"Infinity\", \"100\", \"abc\", \"\"])\n+\t\t\tassert.throws(() => request(flag, value));\n+\t}\n+});\n+\n+test(\"login sends requested grants only at device start and retains the user's actual approval\", async () => {\n+\tconst h = home();\n+\tconst seen: Seen = [];\n+\tconst c = clock();\n+\tconst requested = { projects: [{ project: \"abso\", role: \"owner\" as const }], max_agents: 10, days: 90 };\n+\tconst approved = { projects: [{ project: \"abso\", role: \"reader\" }], max_agents: 1 };\n+\tconst got = await login(\n+\t\tSERVER,\n+\t\t{\n+\t\t\trequest: requested,\n+\t\t\tfetch: server(\n+\t\t\t\t[\n+\t\t\t\t\t[200, started],\n+\t\t\t\t\t[400, { error: \"authorization_pending\" }],\n+\t\t\t\t\t[200, { box_id: \"b_test\", box_token: CREDENTIAL, expires_at: EXPIRES, grant: approved }],\n+\t\t\t\t],\n+\t\t\t\tseen,\n+\t\t\t),\n+\t\t\tsleep: c.sleep,\n+\t\t\tnow: c.now,\n+\t\t\tsay: () => {},\n+\t\t},\n+\t\th,\n+\t);\n+\tassert.ok(seen[0]);\n+\tassert.deepEqual((seen[0].body as Record<string, unknown>).requested_grant, requested);\n+\tassert.deepEqual(\n+\t\tseen.slice(1).map((call) => call.body),\n+\t\t[{ device_code: started.device_code }, { device_code: started.device_code }],\n+\t);\n+\tassert.deepEqual(got.grant, approved);\n+\tassert.deepEqual(readBox(SERVER, h)?.grant, approved);\n+});\n+\n+test(\"invalid login grant flags fail before a network request through the CLI\", async () => {\n+\tconst original = globalThis.fetch;\n+\tlet calls = 0;\n+\tglobalThis.fetch = (async () => {\n+\t\tcalls++;\n+\t\tthrow new Error(\"unexpected request\");\n+\t}) as typeof fetch;\n+\ttry {\n+\t\tconst result = await main([\"login\", \"--projects\", \"alpha\", \"--days\", \"0\", \"--no-browser\"], {\n+\t\t\tcwd: home(),\n+\t\t\tenv: {},\n+\t\t\twrite: () => {},\n+\t\t});\n+\t\tassert.equal(result.exit, 1);\n+\t\tassert.match(result.stderr, /--days is from 1 to 90/);\n+\t\tassert.equal(calls, 0);\n+\t} finally {\n+\t\tglobalThis.fetch = original;\n+\t}\n+});\n+\n test(\"login shows the code, waits while it's pending, and keeps the credential in the user folder\", async () => {\n \tconst h = home();\n \tconst seen: Seen = [];"}],"ci":null}