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
blame on this site's /mcp
CLI
abso blame client/src/box.ts --json
JSON
/christopher/abso-core/blame/client/src/box.ts?format=json
510 linesFirst import 42% · box-grants 13% · trials 13% · approvals-page 12% · pinch 8% · codex-mac-1 8% · Last change approvals-page in version 264,

510 lines from 14 changes in 13 versions.

init0Start the project1// Signing in once per box (abso issue 108). `abso login` asks the server for a
2// code, a person approves it on the website, and the box gets a credential
3// with a grant: projects, a role cap, an agent limit and an expiry. Agents on
4// the box then mint their own keys from it at `abso join`.
5//
6// The box credential lives in the user's config folder, one file per server,
7// never in a project folder. It is never printed, never an argument, and only
pinch34Client: 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.Compare8// ever sent to the server that issued it: on /box/ routes, and on the org reads,
9// which answer as the person who approved the box.
init0Start the project10
11import { createHash } from "node:crypto";
trials61abso 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.Compare12import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
init0Start the project13import { homedir, hostname } from "node:os";
review17New 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.Compare14import { dirname, join } from "node:path";
codex-mac-1102Let login request projects, roles, agent limits and durationCompare15import { type Parsed, str, UsageError } from "./args.ts";
trials61abso 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.Compare16import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from "./state-dir.ts";
init0Start the project17
open171abso 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.Compare18/**
19 * What the person who approved the code allowed: each project with the highest role its agents get there. A box lets in any
20 * number of agents (abso 642; Christopher, 2026-10-14, ask 1947); the server still records a max_agents it doesn't enforce.
21 */
init0Start the project22export interface Grant {
23 readonly projects: readonly { readonly project: string; readonly role: string }[];
box-grants185abso 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.Compare24 /** Version 2 grants (abso 663): member-all is every project of the approver's, now and later, at most this role. */
25 readonly scopes?: readonly { readonly kind: string; readonly role: string }[];
init0Start the project26}
box-grants185abso 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.Compare28/** The role a box has in all its approver's projects, now and later, or null when its grant is a list (abso 663). */
29export function allProjectsRole(grant: Grant): string | null {
30 return grant.scopes?.find((scope) => scope.kind === "member-all")?.role ?? null;
codex-mac-1102Let login request projects, roles, agent limits and durationCompare33/** Requested access is a suggestion for the person approving, never an authorization. */
34export interface LoginRequest {
35 readonly projects?: readonly { readonly project: string; readonly role: "reader" | "writer" | "owner" }[];
36 readonly days?: number;
39export function loginRequest(args: Parsed): LoginRequest | undefined {
40 const projects = str(args, "projects");
41 const role = str(args, "role");
42 const days = str(args, "days");
open171abso 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.Compare43 if (projects === undefined && role === undefined && days === undefined) return undefined;
codex-mac-1102Let login request projects, roles, agent limits and durationCompare44 if (role !== undefined && projects === undefined) throw new UsageError("--role needs --projects");
45 const requestedRole = role ?? "writer";
46 if (requestedRole !== "reader" && requestedRole !== "writer" && requestedRole !== "owner")
47 throw new UsageError("--role is reader, writer or owner");
48 const names = projects?.split(",").map((name) => name.trim());
49 if (names && (names.length > 100 || names.some((name) => !/^[A-Za-z0-9._-]+$/.test(name))))
50 throw new UsageError(
51 "--projects is a comma-separated list of up to 100 project names (letters, digits, dot, dash and underscore)",
52 );
53 const integer = (value: string, name: string, max: number): number => {
54 if (!/^[0-9]+$/.test(value) || !Number.isInteger(Number(value)) || Number(value) < 1 || Number(value) > max)
55 throw new UsageError(`--${name} is from 1 to ${max}`);
56 return Number(value);
57 };
58 return {
59 ...(names ? { projects: [...new Set(names)].map((project) => ({ project, role: requestedRole })) } : {}),
60 ...(days === undefined ? {} : { days: integer(days, "days", 90) }),
61 };
init0Start the project64export interface BoxRecord {
65 readonly server: string;
66 readonly id: string;
67 readonly credential: string;
68 readonly grant: Grant;
69 readonly expiresAt: number;
72export function originOf(server: string): string {
73 try {
74 return new URL(server).origin;
75 } catch {
76 return server;
77 }
review17New 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.Compare80function boxFile(server: string): string {
81 return `${createHash("sha256").update(originOf(server)).digest("hex").slice(0, 16)}.json`;
init0Start the project82}
84export function readBox(server: string, home = homedir()): BoxRecord | undefined {
85 try {
review17New 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.Compare86 const raw = JSON.parse(readFileSync(homeFile(home, "boxes", boxFile(server)), "utf8")) as Partial<BoxRecord>;
init0Start the project87 if (
88 typeof raw.server !== "string" ||
89 originOf(raw.server) !== originOf(server) ||
90 typeof raw.credential !== "string" ||
91 typeof raw.id !== "string" ||
92 typeof raw.expiresAt !== "number" ||
93 !isGrant(raw.grant)
94 )
95 return undefined;
96 return raw as BoxRecord;
97 } catch {
98 return undefined;
99 }
trials61abso 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.Compare100}
102/** The servers this box is signed in to and whose sign-in hasn't expired, from ~/.abso/boxes (and an older ~/.avcs/boxes). */
103export function signedInServers(home = homedir(), now = Date.now()): string[] {
104 const servers = new Set<string>();
105 for (const dir of [STATE_DIR, OLD_STATE_DIR]) {
106 let names: string[];
107 try {
108 names = readdirSync(join(home, dir, "boxes"));
109 } catch {
110 continue;
111 }
112 for (const name of names) {
113 try {
114 const server = (JSON.parse(readFileSync(join(home, dir, "boxes", name), "utf8")) as { server?: unknown })
115 .server;
116 if (typeof server !== "string") continue;
117 const record = readBox(server, home);
118 if (record && record.expiresAt > now) servers.add(originOf(record.server));
119 } catch {
120 // Not a sign-in this client wrote: left alone.
121 }
122 }
123 }
124 return [...servers].sort();
init0Start the project125}
127export function writeBox(record: BoxRecord, home = homedir()): void {
review17New 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.Compare128 const path = homeWritePath(home, "boxes", boxFile(record.server));
129 mkdirSync(dirname(path), { recursive: true });
init0Start the project130 writeFileSync(path, `${JSON.stringify(record)}\n`, { mode: 0o600 });
131 try {
132 chmodSync(path, 0o600);
133 } catch {
134 // Windows has no owner-only mode; the file is still outside every project folder.
135 }
review17New 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.Compare138/** Logout ends the sign-in everywhere on this machine: the credential under ~/.abso and any older copy under ~/.avcs. */
init0Start the project139export function forgetBox(server: string, home = homedir()): boolean {
review17New 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.Compare140 const paths = [homeWritePath(home, "boxes", boxFile(server)), join(home, OLD_STATE_DIR, "boxes", boxFile(server))];
141 const had = paths.filter((path) => existsSync(path));
142 for (const path of had) rmSync(path, { force: true });
143 return had.length > 0;
init0Start the project144}
146/** Error text with the credential (and anything shaped like a key) taken out. */
147function scrub(text: string, secrets: readonly string[]): string {
148 let out = text.replace(/abso_(sk|bx)_[A-Za-z0-9_-]+/g, "[redacted]");
149 for (const s of secrets) if (s.length > 0) out = out.split(s).join("[redacted]");
150 return out;
pinch34Client: 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.Compare153export interface Answer {
init0Start the project154 readonly status: number;
155 readonly body: Record<string, unknown>;
158async function call(
159 server: string,
160 path: string,
161 body: unknown,
162 credential: string | undefined,
163 fetcher: typeof fetch,
box-grants185abso 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.Compare164 headers: Readonly<Record<string, string>> = {},
init0Start the project165): Promise<Answer> {
166 const secrets = credential ? [credential] : [];
167 let response: Response;
168 try {
169 response = await fetcher(`${originOf(server)}${path}`, {
170 method: "POST",
171 headers: {
172 "content-type": "application/json",
box-grants185abso 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.Compare173 ...headers,
init0Start the project174 ...(credential ? { authorization: `Box ${credential}` } : {}),
175 },
176 body: JSON.stringify(body),
177 signal: AbortSignal.timeout(30_000),
178 });
179 } catch (err) {
180 throw new UsageError(
181 `couldn't reach ${originOf(server)}: ${scrub(err instanceof Error ? err.message : String(err), secrets)}`,
182 );
183 }
184 const text = await response.text();
185 let parsed: Record<string, unknown> = {};
186 try {
187 parsed = JSON.parse(text) as Record<string, unknown>;
188 } catch {
189 if (response.ok) throw new UsageError(`${originOf(server)}${path} didn't answer JSON`);
190 }
191 if (!response.ok && !(response.status === 400 && path === "/login/token")) {
192 const said = typeof parsed.error === "string" ? parsed.error : text.slice(0, 300);
193 throw new UsageError(scrub(`${originOf(server)} refused (${response.status}): ${said}`, secrets));
194 }
195 return { status: response.status, body: parsed };
pinch34Client: 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.Compare198/**
199 * A read that answers as the person who approved this box: the org reads (GET /orgs, /orgs/<name>). Answers the
200 * status and body as they came, refusals included, so the caller can say what each means; never the credential.
201 */
202export async function boxGet(record: BoxRecord, path: string, fetcher: typeof fetch = fetch): Promise<Answer> {
203 const secrets = [record.credential];
204 let response: Response;
205 try {
206 response = await fetcher(`${originOf(record.server)}${path}`, {
207 headers: { authorization: `Box ${record.credential}` },
208 signal: AbortSignal.timeout(30_000),
209 });
210 } catch (err) {
211 throw new UsageError(
212 `couldn't reach ${originOf(record.server)}: ${scrub(err instanceof Error ? err.message : String(err), secrets)}`,
213 );
214 }
215 const text = await response.text();
216 try {
217 const body = JSON.parse(text) as unknown;
218 if (typeof body === "object" && body !== null && !Array.isArray(body))
219 return { status: response.status, body: body as Record<string, unknown> };
220 } catch {}
221 return { status: response.status, body: { error: scrub(text.slice(0, 300), secrets) } };
init0Start the project224/** This machine's name, as the server takes a box's name: 1-64 letters, digits, '.', '_' or '-'. */
approvals-page259Box 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).Compare225export function boxName(): string {
init0Start the project226 const name = hostname()
227 .replace(/[^A-Za-z0-9._-]/g, "-")
228 .replace(/^[^A-Za-z0-9]+/, "")
229 .slice(0, 64);
230 return name || "box";
233function isGrant(g: unknown): g is Grant {
234 const x = g as Partial<Grant> | null;
235 return (
236 typeof x === "object" &&
237 x !== null &&
238 Array.isArray(x.projects) &&
open171abso 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.Compare239 x.projects.every((p) => typeof p?.project === "string" && typeof p.role === "string")
init0Start the project240 );
pinch58abso 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.Compare243/** The longest login waits for approval, whatever the server says. */
244const MAX_LOGIN_WAIT_S = 30 * 60;
245/** How often login says it's still waiting. */
246const STILL_WAITING_MS = 60_000;
init0Start the project248export interface LoginIo {
codex-mac-1102Let login request projects, roles, agent limits and durationCompare249 readonly request?: LoginRequest;
init0Start the project250 readonly fetch?: typeof fetch;
251 readonly sleep?: (ms: number) => Promise<void>;
252 readonly now?: () => number;
253 /** Where the code and link go while login waits: stderr, so stdout stays quiet. */
254 readonly say: (line: string) => void;
speed60abso login opens the approve page in the browser Like 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. - 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). - 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. - 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. - The opener starts detached and isn't waited on; a failure is silent. Tests: 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.Compare255 /** Opens the approve page in a browser, answering whether it tried. None where it shouldn't (--no-browser, SSH, CI). */
256 readonly open?: (url: string) => boolean;
approvals-page259Box 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).Compare257 /**
258 * abso 684: in a joined folder, asks a person in its project to approve this sign-in, through an abso ask, so nobody
259 * relays the code. Answers who was asked, or null to fall back to the code alone.
260 */
261 readonly ask?: (codes: { readonly device: string; readonly user: string }) => Promise<LoginAsked | null>;
init0Start the project262}
approvals-page259Box 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).Compare264/** A sign-in asked of people (abso 684). */
265export interface LoginAsked {
266 readonly project: string;
267 /** "the person who approved this agent's box", or "the owners of <project>". */
268 readonly who: string;
269 readonly asks: readonly number[];
270 /** Milliseconds: when the asked sign-in runs out. */
271 readonly expiresAt: number;
272 /** The most the box may be granted: the asking agent's own role. */
273 readonly role: string;
274 /** Withdraws the asks once nobody answered in time. */
275 readonly withdraw: () => Promise<void>;
278const CENTRAL = new Intl.DateTimeFormat("en-US", { timeZone: "America/Chicago", hour: "numeric", minute: "2-digit" });
init0Start the project280/**
281 * Asks `server` for a code, shows it with its link, and waits for a person to
282 * approve it. Answers the box's record, already written to the config folder.
283 */
284export async function login(server: string, io: LoginIo, home = homedir()): Promise<BoxRecord> {
285 const fetcher = io.fetch ?? fetch;
286 const sleep = io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
287 const now = io.now ?? Date.now;
codex-mac-1102Let login request projects, roles, agent limits and durationCompare288 const start = await call(
289 server,
290 "/login/device",
291 { name: boxName(), client: "abso", ...(io.request ? { requested_grant: io.request } : {}) },
292 undefined,
293 fetcher,
294 );
init0Start the project295 const { device_code: device, user_code: code, verification_uri_complete: link } = start.body;
296 let interval = Number(start.body.interval) || 5;
pinch58abso 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.Compare297 // The server says when its code runs out; a server that says never still gets an end.
298 const expiresIn = Math.min(Number(start.body.expires_in) || 900, MAX_LOGIN_WAIT_S);
init0Start the project299 if (typeof code !== "string" || typeof link !== "string" || typeof device !== "string")
300 throw new UsageError(`${originOf(server)} didn't give a code to approve`);
speed60abso login opens the approve page in the browser Like 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. - 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). - 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. - 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. - The opener starts detached and isn't waited on; a failure is silent. Tests: 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.Compare301 // The page opens with the code in it, so nobody copies a link by hand. The link and code are printed all the same.
approvals-page264abso 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.Compare302 // A failed ask falls back to the code, and says why, so a person can still approve it (abso 684).
303 const asked = io.ask
304 ? await io.ask({ device, user: code }).catch((e: unknown) => {
305 io.say(
306 `Couldn't ask a person to approve this (${e instanceof Error ? e.message : String(e)}), so here is the code.`,
307 );
308 return null;
309 })
310 : null;
approvals-page259Box 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).Compare311 if (asked) {
312 const askWord = asked.asks.length === 1 ? `ask ${asked.asks[0]}` : `asks ${asked.asks.join(", ")}`;
313 io.say(`Asked ${asked.who} (${askWord} in ${asked.project}) to sign this box in, as at most ${asked.role}.`);
314 io.say(
315 `Waiting for their answer, until ${CENTRAL.format(new Date(asked.expiresAt))} CT. To approve it yourself instead: ${link}`,
316 );
317 } else {
318 if (io.open?.(link)) io.say("Opening the approve page in your browser.");
319 io.say(`To sign this box in, open ${link} and approve the code ${code}.`);
320 io.say("Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.");
321 }
322 const until = asked ? Math.min(asked.expiresAt, now() + MAX_LOGIN_WAIT_S * 1000) : now() + expiresIn * 1000;
pinch58abso 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.Compare323 let toldAt = now();
init0Start the project324 while (now() < until) {
325 await sleep(interval * 1000);
pinch58abso 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.Compare326 // A wait with no word looks like a hang, so say it's still waiting now and then.
327 if (now() - toldAt >= STILL_WAITING_MS) {
approvals-page259Box 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).Compare328 io.say(
329 asked
330 ? `Still waiting (${asked.who} hasn't answered yet).`
331 : `Still waiting for the code ${code} to be approved.`,
332 );
pinch58abso 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.Compare333 toldAt = now();
334 }
init0Start the project335 const a = await call(server, "/login/token", { device_code: device }, undefined, fetcher);
336 if (a.status === 400) {
337 if (a.body.error === "authorization_pending") continue;
338 if (a.body.error === "slow_down") {
339 interval += 5;
340 continue;
341 }
approvals-page259Box 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).Compare342 if (a.body.error === "access_denied")
343 throw new UsageError(asked ? `${asked.who} turned this sign-in down.` : `the code ${code} was turned down.`);
344 if (asked) await asked.withdraw().catch(() => undefined);
345 throw new UsageError(
346 asked
347 ? "nobody answered in time, so nothing was granted. Run abso login again."
348 : `the code ${code} ran out. Run abso login again.`,
349 );
init0Start the project350 }
351 const { box_token: credential, box_id: id, grant, expires_at } = a.body;
352 const expiresAt = typeof expires_at === "string" ? Date.parse(expires_at) : Number.NaN;
353 if (typeof credential !== "string" || typeof id !== "string" || !isGrant(grant) || Number.isNaN(expiresAt))
354 throw new UsageError(`${originOf(server)} approved the code but sent no credential`);
355 const record: BoxRecord = { server: originOf(server), id, credential, grant, expiresAt };
356 writeBox(record, home);
357 return record;
approvals-page259Box 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).Compare358 }
359 if (asked) {
360 await asked.withdraw().catch(() => undefined);
361 throw new UsageError("nobody answered in time, so nothing was granted. Run abso login again.");
init0Start the project362 }
363 throw new UsageError(`nobody approved the code ${code} in time. Run abso login again.`);
366/** An agent's own key, minted from the box's credential: `{key, id}`, as `abso key install` takes it. */
367export async function mintKey(
368 record: BoxRecord,
369 project: string,
370 agent: string,
371 fetcher: typeof fetch = fetch,
372): Promise<{ key: string; id: string }> {
373 const a = await call(record.server, "/box/agent-key", { project, agent }, record.credential, fetcher);
374 const { key, id } = a.body;
375 if (typeof key !== "string" || typeof id !== "string")
376 throw new UsageError(`${record.server} didn't send a key for ${agent}`);
377 return { key, id };
box-grants185abso 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.Compare378}
380/** What a new project from this box starts with (abso 663): the website's own create, as the person who approved the box. */
381export interface NewProject {
382 readonly name: string;
383 readonly owner?: string;
384 readonly visibility?: "public" | "private";
385 readonly files?: readonly (
386 | { readonly path: string; readonly text: string }
387 | { readonly path: string; readonly base64: string }
388 )[];
391/**
392 * Makes a project as the person who approved this box (abso init, abso 663). One key for every try, so a retry after
393 * a lost answer or a pending one is the same project, never a second.
394 */
395export async function boxCreateProject(
396 record: BoxRecord,
397 project: NewProject,
398 key: string,
399 fetcher: typeof fetch = fetch,
400 sleep: (ms: number) => Promise<void> = (ms) => new Promise((done) => setTimeout(done, ms)),
401): Promise<Record<string, unknown>> {
402 for (let attempt = 1; ; attempt++) {
403 const a = await call(record.server, "/box/projects", project, record.credential, fetcher, {
404 "Idempotency-Key": key,
405 });
406 const pending = (a.body.operation as { state?: unknown } | undefined)?.state === "pending";
407 if (!pending) return a.body;
408 if (attempt >= 10)
409 throw new UsageError(
410 `${originOf(record.server)} is still making ${project.name}. Run the same abso init again in a minute: it picks up where this left off.`,
411 );
412 await sleep(1000 * attempt);
413 }
416/** Makes an organization as the person who approved this box (abso org new, abso 663). */
417export async function boxCreateOrg(
418 record: BoxRecord,
419 name: string,
420 displayName: string | undefined,
421 fetcher: typeof fetch = fetch,
422): Promise<Record<string, unknown>> {
423 return (
424 await call(
425 record.server,
426 "/box/orgs",
427 { name, ...(displayName === undefined ? {} : { displayName }) },
428 record.credential,
429 fetcher,
430 )
431 ).body;
init0Start the project432}
trials64join: a folder prepared with abso key install --server is joined where it is again (Pinch's catch on 63). - --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. - A folder holding only abso's own state folder (.abso, or the older .avcs) counts as empty. - 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. - Issue numbers taken out of the new code comments and test names.Compare434/** The agent name abso join takes when none is given: the box's name, lower-cased. */
trials63abso join <project> works with no --agent and no --dir (abso issue 351), so the project page can show npx abso-cli join <project>. - 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. - Folder: --dir, else here when empty, else ./<project>, which must be new or empty; it prints cd <folder> when it isn't here. - --agent, --dir and --server still win. Project names are checked before use as a folder. Tests: 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.Compare435export function defaultAgentName(): string {
436 return boxName().toLowerCase();
439/**
trials64join: a folder prepared with abso key install --server is joined where it is again (Pinch's catch on 63). - --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. - A folder holding only abso's own state folder (.abso, or the older .avcs) counts as empty. - 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. - Issue numbers taken out of the new code comments and test names.Compare440 * abso join with no --agent: mints a key under `base`, else `base`-2, -3 and so on. Names this
trials63abso join <project> works with no --agent and no --dir (abso issue 351), so the project page can show npx abso-cli join <project>. - 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. - Folder: --dir, else here when empty, else ./<project>, which must be new or empty; it prints cd <folder> when it isn't here. - --agent, --dir and --server still win. Project names are checked before use as a folder. Tests: 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.Compare441 * box already holds in the project are skipped without asking, since minting one again would replace that agent's
442 * key and cut off its folder. A name the server says is taken (409) moves on to the next; any other refusal, the
443 * box's agent limit among them, is said as it is.
444 */
445export async function mintFreeName(
446 record: BoxRecord,
447 project: string,
448 base: string,
449 fetcher: typeof fetch = fetch,
450 tries = 20,
451): Promise<{ key: string; id: string; agent: string }> {
452 const box = await boxGet(record, "/box", fetcher);
453 if (box.status !== 200)
454 throw new UsageError(
455 `${originOf(record.server)} refused (${box.status}): ${String(box.body.error ?? "no reason given")}`,
456 );
457 const agents = Array.isArray(box.body.agents) ? (box.body.agents as { project?: unknown; agent?: unknown }[]) : [];
458 const held = new Set(agents.filter((a) => a.project === project).map((a) => String(a.agent)));
459 for (let n = 1; n <= tries; n++) {
460 const agent = n === 1 ? base : `${base}-${n}`;
461 if (held.has(agent)) continue;
462 try {
463 return { ...(await mintKey(record, project, agent, fetcher)), agent };
464 } catch (err) {
465 if (err instanceof UsageError && /refused \(409\): that agent name/.test(err.message)) continue;
466 throw err;
467 }
468 }
469 throw new UsageError(
470 `${base} through ${base}-${tries} are all taken in ${project}: give this agent a name with --agent <name>`,
471 );
init0Start the project474/** Ends the box on the server, then forgets it here. Forgets it even when the server can't be reached. */
475export async function logout(record: BoxRecord, fetcher: typeof fetch = fetch, home = homedir()): Promise<boolean> {
476 let ended = true;
477 try {
478 await call(record.server, "/box/logout", {}, record.credential, fetcher);
479 } catch {
480 ended = false;
481 }
482 forgetBox(record.server, home);
483 return ended;
486const day = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace("T", " ");
488/** What `abso box` prints: the grant, never the credential. */
489export function boxText(record: BoxRecord | undefined, server: string, now = Date.now()): string {
490 if (!record) return `This box isn't signed in to ${originOf(server)}. abso login signs it in.`;
491 const g = record.grant;
492 const expired = record.expiresAt <= now;
box-grants185abso 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.Compare493 const all = allProjectsRole(g);
init0Start the project494 return [
495 `Signed in to ${record.server} as box ${record.id}${expired ? ", but the sign-in has expired. abso login renews it." : "."}`,
box-grants185abso 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.Compare496 all === null
497 ? `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(", ")}.`
498 : `Projects: all of yours, now and later (${all} at most). abso init makes a new one; abso org new makes an organization.`,
init0Start the project499 `${expired ? "Expired" : "Expires"} ${day(record.expiresAt)} UTC.`,
500 ].join("\n");
503/** What `abso box --json` answers: the record without its credential. */
504export function boxPublic(
505 record: BoxRecord | undefined,
506): { server: string; id: string; grant: Grant; expiresAt: string } | null {
507 return record
508 ? { server: record.server, id: record.id, grant: record.grant, expiresAt: new Date(record.expiresAt).toISOString() }
509 : null;