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 216 to 318

Compare

+60 −8 in 5 places
Lines 222–228 at 318 (were 222–228 at 216)
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 318 (were 254–261 at 216)
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–335 at 318 (were 278–293 at 216)
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+ // 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;
311+ 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;
285323 let toldAt = now();
286324 while (now() < until) {
287325 await sleep(interval * 1000);
288326 // A wait with no word looks like a hang, so say it's still waiting now and then.
289327 if (now() - toldAt >= STILL_WAITING_MS) {
290− io.say(`Still waiting for the code ${code} to be approved.`);
328+ io.say(
329+ asked
330+ ? `Still waiting (${asked.who} hasn't answered yet).`
331+ : `Still waiting for the code ${code} to be approved.`,
332+ );
291333 toldAt = now();
292334 }
293335 const a = await call(server, "/login/token", { device_code: device }, undefined, fetcher);
Lines 339–352 at 318 (were 297–304 at 216)
297339 interval += 5;
298340 continue;
299341 }
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.`);
342+ 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+ );
302350 }
303351 const { box_token: credential, box_id: id, grant, expires_at } = a.body;
304352 const expiresAt = typeof expires_at === "string" ? Date.parse(expires_at) : Number.NaN;
Lines 356–365 at 318 (were 308–313 at 216)
308356 writeBox(record, home);
309357 return record;
310358 }
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.");
362+ }
311363 throw new UsageError(`nobody approved the code ${code} in time. Run abso login again.`);
312364}
313365
MCP
compare on this site's /mcp
CLI
abso diff 216 318 client/src/box.ts --json
JSON
/christopher/abso-core/compare/216..318?file=client%2Fsrc%2Fbox.ts&format=json