Let login request projects, roles, agent limits and duration Version 102 of shared· codex-mac-1· Oct 11 (2026-10-11 01:04 UTC) · Not checked
Version 101 · Files at version 102
4 files, 171 lines added, 5 removed.
--- a/client/README.md
+++ b/client/README.md
@@ -32,6 +32,23 @@
33 33 ## Setting up a folder 35 + ### Requesting access at login 37 + An agent can request the access it needs when starting a box login: 40 + abso login --projects alpha,beta --role writer --max-agents 1 --days 30 --no-browser 43 + The client sends a `requested_grant` with the device request: `projects` 44 + (each with `project` and `role`), `max_agents`, and `days`. Only supplied 45 + fields are sent; project roles default to `writer`. The role option requires 46 + projects. Agent limits range from 1 to 50 and durations from 1 to 90 days. 47 + The person approving still chooses the actual grant and can narrow or reject 48 + the request. Servers must support requested grants to prefill their approval 49 + page; older servers may ignore the suggestions. Without these options, login 50 + works as before. The request itself never authorizes access. 35 52 Folders and machines set up before abso had its name keep working: the older 36 53 `.avcs/` folder, `~/.avcs/` files, `AVCS_` environment names and `.avcsignore` are 37 54 read when the new ones are not there. New things are written under the new names. --- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -12,7 +12,7 @@
12 12 import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; 13 13 import { homedir, hostname } from "node:os"; 14 14 import { dirname, join } from "node:path"; 15 − import { UsageError } from "./args.ts";
15 + import { type Parsed, str, UsageError } from "./args.ts"; 16 16 import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from "./state-dir.ts"; 18 18 /** What the person who approved the code allowed: each project with the highest role its agents get there, and how many agents. */ @@ -21,6 +21,40 @@
21 21 readonly max_agents: number; 24 + /** Requested access is a suggestion for the person approving, never an authorization. */ 25 + export interface LoginRequest { 26 + readonly projects?: readonly { readonly project: string; readonly role: "reader" | "writer" | "owner" }[]; 27 + readonly max_agents?: number; 28 + readonly days?: number; 31 + export function loginRequest(args: Parsed): LoginRequest | undefined { 32 + const projects = str(args, "projects"); 33 + const role = str(args, "role"); 34 + const maxAgents = str(args, "max-agents"); 35 + const days = str(args, "days"); 36 + if (projects === undefined && role === undefined && maxAgents === undefined && days === undefined) return undefined; 37 + if (role !== undefined && projects === undefined) throw new UsageError("--role needs --projects"); 38 + const requestedRole = role ?? "writer"; 39 + if (requestedRole !== "reader" && requestedRole !== "writer" && requestedRole !== "owner") 40 + throw new UsageError("--role is reader, writer or owner"); 41 + const names = projects?.split(",").map((name) => name.trim()); 42 + if (names && (names.length > 100 || names.some((name) => !/^[A-Za-z0-9._-]+$/.test(name)))) 43 + throw new UsageError( 44 + "--projects is a comma-separated list of up to 100 project names (letters, digits, dot, dash and underscore)", 46 + const integer = (value: string, name: string, max: number): number => { 47 + if (!/^[0-9]+$/.test(value) || !Number.isInteger(Number(value)) || Number(value) < 1 || Number(value) > max) 48 + throw new UsageError(`--${name} is from 1 to ${max}`); 49 + return Number(value); 52 + ...(names ? { projects: [...new Set(names)].map((project) => ({ project, role: requestedRole })) } : {}), 53 + ...(maxAgents === undefined ? {} : { max_agents: integer(maxAgents, "max-agents", 50) }), 54 + ...(days === undefined ? {} : { days: integer(days, "days", 90) }), 24 58 export interface BoxRecord { 25 59 readonly server: string; 26 60 readonly id: string; @@ -205,6 +239,7 @@
205 239 const STILL_WAITING_MS = 60_000; 207 241 export interface LoginIo { 242 + readonly request?: LoginRequest; 208 243 readonly fetch?: typeof fetch; 209 244 readonly sleep?: (ms: number) => Promise<void>; 210 245 readonly now?: () => number; @@ -222,7 +257,13 @@
222 257 const fetcher = io.fetch ?? fetch; 223 258 const sleep = io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))); 224 259 const now = io.now ?? Date.now; 225 − const start = await call(server, "/login/device", { name: boxName(), client: "abso" }, undefined, fetcher);
260 + const start = await call( 263 + { name: boxName(), client: "abso", ...(io.request ? { requested_grant: io.request } : {}) }, 226 267 const { device_code: device, user_code: code, verification_uri_complete: link } = start.body; 227 268 let interval = Number(start.body.interval) || 5; 228 269 // The server says when its code runs out; a server that says never still gets an end. --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -7,7 +7,7 @@
7 7 import { ApiError } from "./api.ts"; 8 8 import { bool, type FlagSpec, type Parsed, parseArgs, str, UsageError } from "./args.ts"; 9 9 import { bodyFilesHelp, readBodyFiles, withBodyFiles } from "./body-files.ts"; 10 − import { boxPublic, boxText, login, logout, readBox } from "./box.ts";
10 + import { boxPublic, boxText, login, loginRequest, logout, readBox } from "./box.ts"; 11 11 import { runDiff, runFiles, runLog, runRestore, runShow } from "./changes.ts"; 12 12 import { runCheckIgnore } from "./check-ignore.ts"; 13 13 import { runCi } from "./ci.ts"; @@ -174,8 +174,16 @@
177 − flags: { server: "string", "no-browser": "boolean" },
178 − usage: "abso login [--server <url>] [--no-browser]",
179 + "no-browser": "boolean", 182 + "max-agents": "string", 186 + "abso login [--server <url>] [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]", 180 188 "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.", 181 189 run: async (args, env) => { @@ -185,6 +193,7 @@
186 194 : (url: string) => openInBrowser(url); 187 195 const record = await login(server, { 196 + request: loginRequest(args), 188 197 say: (line) => process.stderr.write(terminalText(`${line}\n`, colorsPass(process.stderr, env.env))), --- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -7,11 +7,13 @@
7 7 import { tmpdir } from "node:os"; 8 8 import { join } from "node:path"; 9 9 import { test } from "node:test"; 10 + import { parseArgs } from "../src/args.ts"; @@ -20,6 +22,7 @@
21 23 } from "../src/box.ts"; 22 24 import { serverFrom } from "../src/join-commands.ts"; 25 + import { main } from "../src/main.ts"; 24 27 const SERVER = "https://staging.abso.example"; 25 28 const CREDENTIAL = "abso_bx_the-secret-credential"; @@ -67,6 +70,102 @@
73 + test("login grant options validate project lists, roles, limits and duration", () => { 74 + const request = (...words: string[]) => 76 + parseArgs("login", words, { 79 + "max-agents": "string", 83 + assert.equal(request(), undefined); 84 + assert.deepEqual(request("--projects", "alpha, beta,alpha", "--max-agents", "1", "--days", "30"), { 86 + { project: "alpha", role: "writer" }, 87 + { project: "beta", role: "writer" }, 92 + assert.deepEqual(request("--projects", "alpha", "--role", "reader"), { 93 + projects: [{ project: "alpha", role: "reader" }], 95 + assert.deepEqual(request("--projects", "alpha", "--role", "owner"), { 96 + projects: [{ project: "alpha", role: "owner" }], 98 + assert.deepEqual(request("--max-agents", "50", "--days", "90"), { max_agents: 50, days: 90 }); 99 + for (const words of [ 100 + ["--role", "writer"], 102 + ["--projects", "alpha,"], 103 + ["--projects", "../alpha"], 104 + ["--projects", "alpha", "--role", "admin"], 105 + ["--projects", Array.from({ length: 101 }, (_, i) => `p${i}`).join(",")], 107 + assert.throws(() => request(...words)); 108 + for (const flag of ["--max-agents", "--days"]) { 109 + for (const value of ["0", "-1", "1.5", "1e1", "Infinity", "100", "abc", ""]) 110 + assert.throws(() => request(flag, value)); 114 + test("login sends requested grants only at device start and retains the user's actual approval", async () => { 116 + const seen: Seen = []; 118 + const requested = { projects: [{ project: "abso", role: "owner" as const }], max_agents: 10, days: 90 }; 119 + const approved = { projects: [{ project: "abso", role: "reader" }], max_agents: 1 }; 120 + const got = await login( 127 + [400, { error: "authorization_pending" }], 128 + [200, { box_id: "b_test", box_token: CREDENTIAL, expires_at: EXPIRES, grant: approved }], 139 + assert.deepEqual((seen[0].body as Record<string, unknown>).requested_grant, requested); 141 + seen.slice(1).map((call) => call.body), 142 + [{ device_code: started.device_code }, { device_code: started.device_code }], 144 + assert.deepEqual(got.grant, approved); 145 + assert.deepEqual(readBox(SERVER, h)?.grant, approved); 148 + test("invalid login grant flags fail before a network request through the CLI", async () => { 149 + const original = globalThis.fetch; 151 + globalThis.fetch = (async () => { 153 + throw new Error("unexpected request"); 156 + const result = await main(["login", "--projects", "alpha", "--days", "0", "--no-browser"], { 161 + assert.equal(result.exit, 1); 162 + assert.match(result.stderr, /--days is from 1 to 90/); 163 + assert.equal(calls, 0); 165 + globalThis.fetch = original; 70 169 test("login shows the code, waits while it's pending, and keeps the credential in the user folder", async () => { 72 171 const seen: Seen = [];