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

Versions 258 to 259

Compare

+52 −8 in 5 places
Lines 222–228 at 259 (were 222–228 at 258)
222222}
223223
224224/** This machine's name, as the server takes a box's name: 1-64 letters, digits, '.', '_' or '-'. */
225−function boxName(): string {
225+export function boxName(): string {
226226 const name = hostname()
227227 .replace(/[^A-Za-z0-9._-]/g, "-")
228228 .replace(/^[^A-Za-z0-9]+/, "")
Lines 254–282 at 259 (were 254–261 at 258)
254254 readonly say: (line: string) => void;
255255 /** Opens the approve page in a browser, answering whether it tried. None where it shouldn't (--no-browser, SSH, CI). */
256256 readonly open?: (url: string) => boolean;
257+ /**
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>;
257262}
258263
264+/** A sign-in asked of people (abso 684). */
265+export 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>;
276+}
278+const CENTRAL = new Intl.DateTimeFormat("en-US", { timeZone: "America/Chicago", hour: "numeric", minute: "2-digit" });
259280/**
260281 * Asks `server` for a code, shows it with its link, and waits for a person to
261282 * approve it. Answers the box's record, already written to the config folder.
Lines 299–327 at 259 (were 278–293 at 258)
278299 if (typeof code !== "string" || typeof link !== "string" || typeof device !== "string")
279300 throw new UsageError(`${originOf(server)} didn't give a code to approve`);
280301 // The page opens with the code in it, so nobody copies a link by hand. The link and code are printed all the same.
281− if (io.open?.(link)) io.say("Opening the approve page in your browser.");
282− io.say(`To sign this box in, open ${link} and approve the code ${code}.`);
283− io.say("Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.");
284− const until = now() + expiresIn * 1000;
302+ const asked = io.ask ? await io.ask({ device, user: code }).catch(() => null) : null;
303+ if (asked) {
304+ const askWord = asked.asks.length === 1 ? `ask ${asked.asks[0]}` : `asks ${asked.asks.join(", ")}`;
305+ io.say(`Asked ${asked.who} (${askWord} in ${asked.project}) to sign this box in, as at most ${asked.role}.`);
306+ io.say(
307+ `Waiting for their answer, until ${CENTRAL.format(new Date(asked.expiresAt))} CT. To approve it yourself instead: ${link}`,
308+ );
309+ } else {
310+ if (io.open?.(link)) io.say("Opening the approve page in your browser.");
311+ io.say(`To sign this box in, open ${link} and approve the code ${code}.`);
312+ io.say("Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.");
313+ }
314+ const until = asked ? Math.min(asked.expiresAt, now() + MAX_LOGIN_WAIT_S * 1000) : now() + expiresIn * 1000;
285315 let toldAt = now();
286316 while (now() < until) {
287317 await sleep(interval * 1000);
288318 // A wait with no word looks like a hang, so say it's still waiting now and then.
289319 if (now() - toldAt >= STILL_WAITING_MS) {
290− io.say(`Still waiting for the code ${code} to be approved.`);
320+ io.say(
321+ asked
322+ ? `Still waiting (${asked.who} hasn't answered yet).`
323+ : `Still waiting for the code ${code} to be approved.`,
324+ );
291325 toldAt = now();
292326 }
293327 const a = await call(server, "/login/token", { device_code: device }, undefined, fetcher);
Lines 331–344 at 259 (were 297–304 at 258)
297331 interval += 5;
298332 continue;
299333 }
300− if (a.body.error === "access_denied") throw new UsageError(`the code ${code} was turned down.`);
301− throw new UsageError(`the code ${code} ran out. Run abso login again.`);
334+ if (a.body.error === "access_denied")
335+ throw new UsageError(asked ? `${asked.who} turned this sign-in down.` : `the code ${code} was turned down.`);
336+ if (asked) await asked.withdraw().catch(() => undefined);
337+ throw new UsageError(
338+ asked
339+ ? "nobody answered in time, so nothing was granted. Run abso login again."
340+ : `the code ${code} ran out. Run abso login again.`,
341+ );
302342 }
303343 const { box_token: credential, box_id: id, grant, expires_at } = a.body;
304344 const expiresAt = typeof expires_at === "string" ? Date.parse(expires_at) : Number.NaN;
Lines 348–357 at 259 (were 308–313 at 258)
308348 writeBox(record, home);
309349 return record;
310350 }
351+ if (asked) {
352+ await asked.withdraw().catch(() => undefined);
353+ throw new UsageError("nobody answered in time, so nothing was granted. Run abso login again.");
354+ }
311355 throw new UsageError(`nobody approved the code ${code} in time. Run abso login again.`);
312356}
313357
MCP
compare on this site's /mcp
CLI
abso diff 258 259 client/src/box.ts --json
JSON
/christopher/abso-core/compare/258..259?file=client%2Fsrc%2Fbox.ts&format=json