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 60 --json
JSON
/christopher/abso-core/versions/60?format=json

abso login opens the approve page in the browser

of shared·speed··Not checked

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.

Version 59 · Files at version 60

5 files, 191 lines added, 4 removed.

--- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -185,6 +185,8 @@
185185 readonly now?: () => number;
186186 /** Where the code and link go while login waits: stderr, so stdout stays quiet. */
187187 readonly say: (line: string) => void;
188+ /** Opens the approve page in a browser, answering whether it tried. None where it shouldn't (--no-browser, SSH, CI). */
189+ readonly open?: (url: string) => boolean;
188190}
189191
190192/**
@@ -202,6 +204,8 @@
202204 const expiresIn = Math.min(Number(start.body.expires_in) || 900, MAX_LOGIN_WAIT_S);
203205 if (typeof code !== "string" || typeof link !== "string" || typeof device !== "string")
204206 throw new UsageError(`${originOf(server)} didn't give a code to approve`);
207+ // The page opens with the code in it, so nobody copies a link by hand. The link and code are printed all the same.
208+ if (io.open?.(link)) io.say("Opening the approve page in your browser.");
205209 io.say(`To sign this box in, open ${link} and approve the code ${code}.`);
206210 io.say("Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.");
207211 const until = now() + expiresIn * 1000;
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -43,6 +43,7 @@
4343import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
4444import { runAck, runAnswer, runAsk, runIssue, runIssues, runSearch, runWaiting } from "./issues.ts";
4545import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from "./key-admin.ts";
46+import { browserSkip, openInBrowser } from "./open-browser.ts";
4647import { initInOrg, runOrg, runOrgs } from "./orgs.ts";
4748import { runUnqueue } from "./queue.ts";
4849import { runNote, runNotes, runReview } from "./review.ts";
@@ -169,13 +170,17 @@
169170 },
170171 },
171172 login: {
172− flags: { server: "string" },
173− usage: "abso login [--server <url>]",
173+ flags: { server: "string", "no-browser": "boolean" },
174+ usage: "abso login [--server <url>] [--no-browser]",
174175 about:
175− "Sign this box in once (abso issue 108): it shows a code and a link, 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.",
176+ "Sign this box in once (abso issue 108): 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.",
176177 run: async (args, env) => {
177178 const server = boxServer(args, env);
178− const record = await login(server, { say: (line) => process.stderr.write(`${line}\n`) });
179+ const open =
180+ bool(args, "no-browser") || browserSkip(env.env, process.platform) !== null
181+ ? undefined
182+ : (url: string) => openInBrowser(url);
183+ const record = await login(server, { say: (line) => process.stderr.write(`${line}\n`), open });
179184 return {
180185 text: `This box is signed in. ${boxText(record, server).split("\n").slice(1).join(" ")}`,
181186 json: { box: boxPublic(record) },
--- /dev/null
+++ b/client/src/open-browser.ts
@@ -0,0 +1,53 @@
1+// Opening a page in the person's own browser, as `gh auth login` and `wrangler login` do.
2+// `abso login` opens the approve page with the code already in it, and still prints the
3+// link and the code: an open that fails, or is skipped, is silent, and the printed link stands.
4+
5+import { spawn } from "node:child_process";
6+
7+/** Why not to open a browser here, or null to open one. */
8+export function browserSkip(env: Readonly<Record<string, string | undefined>>, platform: string): string | null {
9+ if (env.ABSO_NO_BROWSER) return "ABSO_NO_BROWSER is set";
10+ // Over SSH the browser would open on the far machine's desktop, if it has one.
11+ if (env.SSH_CONNECTION || env.SSH_TTY) return "this is an SSH session";
12+ if (env.CI && env.CI !== "false" && env.CI !== "0") return "this is CI";
13+ if (platform !== "win32" && platform !== "darwin" && !env.DISPLAY && !env.WAYLAND_DISPLAY)
14+ return "there's no display";
15+ return null;
16+}
18+/**
19+ * The program that opens `url` in the default browser, and its arguments. No shell, so nothing in the url is
20+ * read as shell syntax. On Windows that rules out cmd's start, which cuts a url at its first &.
21+ */
22+export function openCommand(url: string, platform: string): [string, string[]] {
23+ if (platform === "win32") return ["rundll32", ["url.dll,FileProtocolHandler", url]];
24+ if (platform === "darwin") return ["open", [url]];
25+ return ["xdg-open", [url]];
26+}
28+/** Only web pages are opened: a link from a server is never handed to the desktop as a file or another program. */
29+export function isWebLink(url: string): boolean {
30+ try {
31+ const u = new URL(url);
32+ return u.protocol === "https:" || u.protocol === "http:";
33+ } catch {
34+ return false;
35+ }
36+}
38+/**
39+ * Opens `url` in the default browser and doesn't wait. Answers whether it started an opener; a failure
40+ * (no such program, refused) is silent.
41+ */
42+export function openInBrowser(url: string, platform: string = process.platform, run: typeof spawn = spawn): boolean {
43+ if (!isWebLink(url)) return false;
44+ const [command, args] = openCommand(url, platform);
45+ try {
46+ const child = run(command, args, { detached: true, stdio: "ignore", windowsHide: true });
47+ child.on("error", () => {});
48+ child.unref();
49+ return true;
50+ } catch {
51+ return false;
52+ }
53+}
--- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -102,6 +102,64 @@
102102 assert.equal(JSON.stringify(boxPublic(got)).includes(CREDENTIAL), false);
103103});
104104
105+test("login opens the approve page with the code in it, and prints the link and code all the same", async () => {
106+ const said: string[] = [];
107+ const opened: string[] = [];
108+ const c = clock();
109+ await login(
110+ SERVER,
111+ {
112+ fetch: server(
113+ [
114+ [200, started],
115+ [200, { box_id: "b_0123abcd", box_token: CREDENTIAL, expires_at: EXPIRES, grant }],
116+ ],
117+ [],
118+ ),
119+ sleep: c.sleep,
120+ now: c.now,
121+ say: (line) => said.push(line),
122+ open: (url) => (opened.push(url), true),
123+ },
124+ home(),
125+ );
126+ assert.deepEqual(opened, ["https://abso.dev/login/box?code=WXYZ-BCDF"]);
127+ assert.deepEqual(said.slice(0, 2), [
128+ "Opening the approve page in your browser.",
129+ "To sign this box in, open https://abso.dev/login/box?code=WXYZ-BCDF and approve the code WXYZ-BCDF.",
130+ ]);
131+});
133+test("an open that doesn't start says nothing about a browser, and the printed link stands", async () => {
134+ const said: string[] = [];
135+ const c = clock();
136+ await login(
137+ SERVER,
138+ {
139+ fetch: server(
140+ [
141+ [200, started],
142+ [200, { box_id: "b_0123abcd", box_token: CREDENTIAL, expires_at: EXPIRES, grant }],
143+ ],
144+ [],
145+ ),
146+ sleep: c.sleep,
147+ now: c.now,
148+ say: (line) => said.push(line),
149+ open: () => false,
150+ },
151+ home(),
152+ );
153+ assert.equal(
154+ said[0],
155+ "To sign this box in, open https://abso.dev/login/box?code=WXYZ-BCDF and approve the code WXYZ-BCDF.",
156+ );
157+ assert.equal(
158+ said.some((l) => l.includes("browser")),
159+ false,
160+ );
161+});
105163test("a code that's turned down or runs out says so and keeps nothing", async () => {
106164 const h = home();
107165 const c = clock();
--- /dev/null
+++ b/client/test/open-browser.test.ts
@@ -0,0 +1,67 @@
1+// Opening the approve page in the person's browser: when it's skipped, which program opens it on each
2+// platform, and that a failed open is silent.
3+
4+import assert from "node:assert/strict";
5+import type { spawn } from "node:child_process";
6+import { EventEmitter } from "node:events";
7+import { test } from "node:test";
8+import { browserSkip, isWebLink, openCommand, openInBrowser } from "../src/open-browser.ts";
9+
10+const LINK = "https://abso.dev/login/box?code=WXYZ-BCDF&from=cli";
12+test("a desktop opens a browser", () => {
13+ assert.equal(browserSkip({}, "win32"), null);
14+ assert.equal(browserSkip({}, "darwin"), null);
15+ assert.equal(browserSkip({ DISPLAY: ":0" }, "linux"), null);
16+ assert.equal(browserSkip({ WAYLAND_DISPLAY: "wayland-0" }, "linux"), null);
17+ assert.equal(browserSkip({ CI: "false" }, "darwin"), null, "CI=false isn't CI");
18+});
20+test("no browser with ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display", () => {
21+ assert.equal(browserSkip({ ABSO_NO_BROWSER: "1" }, "win32"), "ABSO_NO_BROWSER is set");
22+ assert.equal(browserSkip({ SSH_CONNECTION: "10.0.0.2 51234 10.0.0.1 22" }, "darwin"), "this is an SSH session");
23+ assert.equal(browserSkip({ SSH_TTY: "/dev/pts/0", DISPLAY: ":0" }, "linux"), "this is an SSH session");
24+ assert.equal(browserSkip({ CI: "true" }, "win32"), "this is CI");
25+ assert.equal(browserSkip({}, "linux"), "there's no display");
26+ assert.equal(browserSkip({}, "freebsd"), "there's no display");
27+});
29+test("each platform's opener takes the link whole, with no shell to split it at &", () => {
30+ assert.deepEqual(openCommand(LINK, "win32"), ["rundll32", ["url.dll,FileProtocolHandler", LINK]]);
31+ assert.deepEqual(openCommand(LINK, "darwin"), ["open", [LINK]]);
32+ assert.deepEqual(openCommand(LINK, "linux"), ["xdg-open", [LINK]]);
33+});
35+test("only web pages are opened", () => {
36+ assert.equal(isWebLink(LINK), true);
37+ assert.equal(isWebLink("http://localhost:8787/login/box?code=A"), true);
38+ for (const bad of ["file:///C:/Windows/System32/calc.exe", "javascript:alert(1)", "C:\\x.exe", "not a link", ""])
39+ assert.equal(isWebLink(bad), false, bad);
40+});
42+type Call = { command: string; args: readonly string[]; options: unknown };
43+function fakeSpawn(calls: Call[], fail?: "throw" | "error"): typeof spawn {
44+ return ((command: string, args: readonly string[], options: unknown) => {
45+ calls.push({ command, args, options });
46+ if (fail === "throw") throw new Error("spawn EACCES");
47+ const child = Object.assign(new EventEmitter(), { unref: () => {} });
48+ if (fail === "error") queueMicrotask(() => child.emit("error", new Error("spawn xdg-open ENOENT")));
49+ return child;
50+ }) as unknown as typeof spawn;
51+}
53+test("openInBrowser starts the opener without waiting on it, and a failure is silent", async () => {
54+ const calls: Call[] = [];
55+ assert.equal(openInBrowser(LINK, "win32", fakeSpawn(calls)), true);
56+ assert.deepEqual(calls[0]?.command, "rundll32");
57+ assert.deepEqual(calls[0]?.args, ["url.dll,FileProtocolHandler", LINK]);
58+ assert.deepEqual(calls[0]?.options, { detached: true, stdio: "ignore", windowsHide: true });
60+ assert.equal(openInBrowser(LINK, "linux", fakeSpawn([], "throw")), false);
61+ assert.equal(openInBrowser(LINK, "linux", fakeSpawn([], "error")), true);
62+ await new Promise((done) => setTimeout(done, 0)); // the error event fires, and nothing throws
64+ const none: Call[] = [];
65+ assert.equal(openInBrowser("file:///etc/passwd", "linux", fakeSpawn(none)), false);
66+ assert.equal(none.length, 0, "a link that isn't a web page never reaches the opener");
67+});