Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 102 --json
JSON
/christopher/abso-core/versions/102?format=json

Let login request projects, roles, agent limits and duration

of shared·codex-mac-1··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 @@
3232
3333## Setting up a folder
3434
35+### Requesting access at login
37+An agent can request the access it needs when starting a box login:
39+```bash
40+abso login --projects alpha,beta --role writer --max-agents 1 --days 30 --no-browser
41+```
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.
3552Folders and machines set up before abso had its name keep working: the older
3653`.avcs/` folder, `~/.avcs/` files, `AVCS_` environment names and `.avcsignore` are
3754read 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 @@
1212import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1313import { homedir, hostname } from "node:os";
1414import { dirname, join } from "node:path";
15−import { UsageError } from "./args.ts";
15+import { type Parsed, str, UsageError } from "./args.ts";
1616import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from "./state-dir.ts";
1717
1818/** 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 @@
2121 readonly max_agents: number;
2222}
2323
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;
29+}
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)",
45+ );
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);
50+ };
51+ return {
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) }),
55+ };
56+}
2458export interface BoxRecord {
2559 readonly server: string;
2660 readonly id: string;
@@ -205,6 +239,7 @@
205239const STILL_WAITING_MS = 60_000;
206240
207241export interface LoginIo {
242+ readonly request?: LoginRequest;
208243 readonly fetch?: typeof fetch;
209244 readonly sleep?: (ms: number) => Promise<void>;
210245 readonly now?: () => number;
@@ -222,7 +257,13 @@
222257 const fetcher = io.fetch ?? fetch;
223258 const sleep = io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
224259 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(
261+ server,
262+ "/login/device",
263+ { name: boxName(), client: "abso", ...(io.request ? { requested_grant: io.request } : {}) },
264+ undefined,
265+ fetcher,
266+ );
226267 const { device_code: device, user_code: code, verification_uri_complete: link } = start.body;
227268 let interval = Number(start.body.interval) || 5;
228269 // 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 @@
77import { ApiError } from "./api.ts";
88import { bool, type FlagSpec, type Parsed, parseArgs, str, UsageError } from "./args.ts";
99import { 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";
1111import { runDiff, runFiles, runLog, runRestore, runShow } from "./changes.ts";
1212import { runCheckIgnore } from "./check-ignore.ts";
1313import { runCi } from "./ci.ts";
@@ -174,8 +174,16 @@
174174 },
175175 },
176176 login: {
177− flags: { server: "string", "no-browser": "boolean" },
178− usage: "abso login [--server <url>] [--no-browser]",
177+ flags: {
178+ server: "string",
179+ "no-browser": "boolean",
180+ projects: "string",
181+ role: "string",
182+ "max-agents": "string",
183+ days: "string",
184+ },
185+ usage:
186+ "abso login [--server <url>] [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]",
179187 about:
180188 "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.",
181189 run: async (args, env) => {
@@ -185,6 +193,7 @@
185193 ? undefined
186194 : (url: string) => openInBrowser(url);
187195 const record = await login(server, {
196+ request: loginRequest(args),
188197 say: (line) => process.stderr.write(terminalText(`${line}\n`, colorsPass(process.stderr, env.env))),
189198 open,
190199 });
--- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -7,11 +7,13 @@
77import { tmpdir } from "node:os";
88import { join } from "node:path";
99import { test } from "node:test";
10+import { parseArgs } from "../src/args.ts";
1011import {
1112 boxPublic,
1213 boxText,
1314 forgetBox,
1415 login,
16+ loginRequest,
1517 logout,
1618 mintFreeName,
1719 mintKey,
@@ -20,6 +22,7 @@
2022 writeBox,
2123} from "../src/box.ts";
2224import { serverFrom } from "../src/join-commands.ts";
25+import { main } from "../src/main.ts";
2326
2427const SERVER = "https://staging.abso.example";
2528const CREDENTIAL = "abso_bx_the-secret-credential";
@@ -67,6 +70,102 @@
6770 };
6871}
6972
73+test("login grant options validate project lists, roles, limits and duration", () => {
74+ const request = (...words: string[]) =>
75+ loginRequest(
76+ parseArgs("login", words, {
77+ projects: "string",
78+ role: "string",
79+ "max-agents": "string",
80+ days: "string",
81+ }),
82+ );
83+ assert.equal(request(), undefined);
84+ assert.deepEqual(request("--projects", "alpha, beta,alpha", "--max-agents", "1", "--days", "30"), {
85+ projects: [
86+ { project: "alpha", role: "writer" },
87+ { project: "beta", role: "writer" },
88+ ],
89+ max_agents: 1,
90+ days: 30,
91+ });
92+ assert.deepEqual(request("--projects", "alpha", "--role", "reader"), {
93+ projects: [{ project: "alpha", role: "reader" }],
94+ });
95+ assert.deepEqual(request("--projects", "alpha", "--role", "owner"), {
96+ projects: [{ project: "alpha", role: "owner" }],
97+ });
98+ assert.deepEqual(request("--max-agents", "50", "--days", "90"), { max_agents: 50, days: 90 });
99+ for (const words of [
100+ ["--role", "writer"],
101+ ["--projects", ""],
102+ ["--projects", "alpha,"],
103+ ["--projects", "../alpha"],
104+ ["--projects", "alpha", "--role", "admin"],
105+ ["--projects", Array.from({ length: 101 }, (_, i) => `p${i}`).join(",")],
106+ ])
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));
111+ }
112+});
114+test("login sends requested grants only at device start and retains the user's actual approval", async () => {
115+ const h = home();
116+ const seen: Seen = [];
117+ const c = clock();
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(
121+ SERVER,
122+ {
123+ request: requested,
124+ fetch: server(
125+ [
126+ [200, started],
127+ [400, { error: "authorization_pending" }],
128+ [200, { box_id: "b_test", box_token: CREDENTIAL, expires_at: EXPIRES, grant: approved }],
129+ ],
130+ seen,
131+ ),
132+ sleep: c.sleep,
133+ now: c.now,
134+ say: () => {},
135+ },
136+ h,
137+ );
138+ assert.ok(seen[0]);
139+ assert.deepEqual((seen[0].body as Record<string, unknown>).requested_grant, requested);
140+ assert.deepEqual(
141+ seen.slice(1).map((call) => call.body),
142+ [{ device_code: started.device_code }, { device_code: started.device_code }],
143+ );
144+ assert.deepEqual(got.grant, approved);
145+ assert.deepEqual(readBox(SERVER, h)?.grant, approved);
146+});
148+test("invalid login grant flags fail before a network request through the CLI", async () => {
149+ const original = globalThis.fetch;
150+ let calls = 0;
151+ globalThis.fetch = (async () => {
152+ calls++;
153+ throw new Error("unexpected request");
154+ }) as typeof fetch;
155+ try {
156+ const result = await main(["login", "--projects", "alpha", "--days", "0", "--no-browser"], {
157+ cwd: home(),
158+ env: {},
159+ write: () => {},
160+ });
161+ assert.equal(result.exit, 1);
162+ assert.match(result.stderr, /--days is from 1 to 90/);
163+ assert.equal(calls, 0);
164+ } finally {
165+ globalThis.fetch = original;
166+ }
167+});
70169test("login shows the code, waits while it's pending, and keeps the credential in the user folder", async () => {
71170 const h = home();
72171 const seen: Seen = [];