{"version":60,"agent":"speed","message":"abso login opens the approve page in the browser\n\nLike 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.\n\n- 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).\n- 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.\n- 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.\n- The opener starts detached and isn't waited on; a failure is silent.\n\nTests: 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.","time":1791600855763,"timeIso":"2026-10-10T02:54:15.763Z","changes":5,"change":785,"files":["client/src/box.ts","client/src/main.ts","client/src/open-browser.ts","client/test/box.test.ts","client/test/open-browser.test.ts"],"draft":null,"diff":[{"path":"client/src/box.ts","added":4,"removed":0,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -185,6 +185,8 @@\n \treadonly now?: () => number;\n \t/** Where the code and link go while login waits: stderr, so stdout stays quiet. */\n \treadonly say: (line: string) => void;\n+\t/** Opens the approve page in a browser, answering whether it tried. None where it shouldn't (--no-browser, SSH, CI). */\n+\treadonly open?: (url: string) => boolean;\n }\n \n /**\n@@ -202,6 +204,8 @@\n \tconst expiresIn = Math.min(Number(start.body.expires_in) || 900, MAX_LOGIN_WAIT_S);\n \tif (typeof code !== \"string\" || typeof link !== \"string\" || typeof device !== \"string\")\n \t\tthrow new UsageError(`${originOf(server)} didn't give a code to approve`);\n+\t// The page opens with the code in it, so nobody copies a link by hand. The link and code are printed all the same.\n+\tif (io.open?.(link)) io.say(\"Opening the approve page in your browser.\");\n \tio.say(`To sign this box in, open ${link} and approve the code ${code}.`);\n \tio.say(\"Waiting for approval. Ctrl-C stops waiting, and abso stops by itself when the code runs out.\");\n \tconst until = now() + expiresIn * 1000;"},{"path":"client/src/main.ts","added":9,"removed":4,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -43,6 +43,7 @@\n import { runBlame, runWhere, runWho, runWhy } from \"./history.ts\";\n import { runAck, runAnswer, runAsk, runIssue, runIssues, runSearch, runWaiting } from \"./issues.ts\";\n import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from \"./key-admin.ts\";\n+import { browserSkip, openInBrowser } from \"./open-browser.ts\";\n import { initInOrg, runOrg, runOrgs } from \"./orgs.ts\";\n import { runUnqueue } from \"./queue.ts\";\n import { runNote, runNotes, runReview } from \"./review.ts\";\n@@ -169,13 +170,17 @@\n \t\t},\n \t},\n \tlogin: {\n-\t\tflags: { server: \"string\" },\n-\t\tusage: \"abso login [--server <url>]\",\n+\t\tflags: { server: \"string\", \"no-browser\": \"boolean\" },\n+\t\tusage: \"abso login [--server <url>] [--no-browser]\",\n \t\tabout:\n-\t\t\t\"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.\",\n+\t\t\t\"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.\",\n \t\trun: async (args, env) => {\n \t\t\tconst server = boxServer(args, env);\n-\t\t\tconst record = await login(server, { say: (line) => process.stderr.write(`${line}\\n`) });\n+\t\t\tconst open =\n+\t\t\t\tbool(args, \"no-browser\") || browserSkip(env.env, process.platform) !== null\n+\t\t\t\t\t? undefined\n+\t\t\t\t\t: (url: string) => openInBrowser(url);\n+\t\t\tconst record = await login(server, { say: (line) => process.stderr.write(`${line}\\n`), open });\n \t\t\treturn {\n \t\t\t\ttext: `This box is signed in. ${boxText(record, server).split(\"\\n\").slice(1).join(\" \")}`,\n \t\t\t\tjson: { box: boxPublic(record) },"},{"path":"client/src/open-browser.ts","added":53,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/open-browser.ts\n@@ -0,0 +1,53 @@\n+// Opening a page in the person's own browser, as `gh auth login` and `wrangler login` do.\n+// `abso login` opens the approve page with the code already in it, and still prints the\n+// link and the code: an open that fails, or is skipped, is silent, and the printed link stands.\n+\n+import { spawn } from \"node:child_process\";\n+\n+/** Why not to open a browser here, or null to open one. */\n+export function browserSkip(env: Readonly<Record<string, string | undefined>>, platform: string): string | null {\n+\tif (env.ABSO_NO_BROWSER) return \"ABSO_NO_BROWSER is set\";\n+\t// Over SSH the browser would open on the far machine's desktop, if it has one.\n+\tif (env.SSH_CONNECTION || env.SSH_TTY) return \"this is an SSH session\";\n+\tif (env.CI && env.CI !== \"false\" && env.CI !== \"0\") return \"this is CI\";\n+\tif (platform !== \"win32\" && platform !== \"darwin\" && !env.DISPLAY && !env.WAYLAND_DISPLAY)\n+\t\treturn \"there's no display\";\n+\treturn null;\n+}\n+\n+/**\n+ * The program that opens `url` in the default browser, and its arguments. No shell, so nothing in the url is\n+ * read as shell syntax. On Windows that rules out cmd's start, which cuts a url at its first &.\n+ */\n+export function openCommand(url: string, platform: string): [string, string[]] {\n+\tif (platform === \"win32\") return [\"rundll32\", [\"url.dll,FileProtocolHandler\", url]];\n+\tif (platform === \"darwin\") return [\"open\", [url]];\n+\treturn [\"xdg-open\", [url]];\n+}\n+\n+/** Only web pages are opened: a link from a server is never handed to the desktop as a file or another program. */\n+export function isWebLink(url: string): boolean {\n+\ttry {\n+\t\tconst u = new URL(url);\n+\t\treturn u.protocol === \"https:\" || u.protocol === \"http:\";\n+\t} catch {\n+\t\treturn false;\n+\t}\n+}\n+\n+/**\n+ * Opens `url` in the default browser and doesn't wait. Answers whether it started an opener; a failure\n+ * (no such program, refused) is silent.\n+ */\n+export function openInBrowser(url: string, platform: string = process.platform, run: typeof spawn = spawn): boolean {\n+\tif (!isWebLink(url)) return false;\n+\tconst [command, args] = openCommand(url, platform);\n+\ttry {\n+\t\tconst child = run(command, args, { detached: true, stdio: \"ignore\", windowsHide: true });\n+\t\tchild.on(\"error\", () => {});\n+\t\tchild.unref();\n+\t\treturn true;\n+\t} catch {\n+\t\treturn false;\n+\t}\n+}"},{"path":"client/test/box.test.ts","added":58,"removed":0,"diff":"--- a/client/test/box.test.ts\n+++ b/client/test/box.test.ts\n@@ -102,6 +102,64 @@\n \tassert.equal(JSON.stringify(boxPublic(got)).includes(CREDENTIAL), false);\n });\n \n+test(\"login opens the approve page with the code in it, and prints the link and code all the same\", async () => {\n+\tconst said: string[] = [];\n+\tconst opened: string[] = [];\n+\tconst c = clock();\n+\tawait login(\n+\t\tSERVER,\n+\t\t{\n+\t\t\tfetch: server(\n+\t\t\t\t[\n+\t\t\t\t\t[200, started],\n+\t\t\t\t\t[200, { box_id: \"b_0123abcd\", box_token: CREDENTIAL, expires_at: EXPIRES, grant }],\n+\t\t\t\t],\n+\t\t\t\t[],\n+\t\t\t),\n+\t\t\tsleep: c.sleep,\n+\t\t\tnow: c.now,\n+\t\t\tsay: (line) => said.push(line),\n+\t\t\topen: (url) => (opened.push(url), true),\n+\t\t},\n+\t\thome(),\n+\t);\n+\tassert.deepEqual(opened, [\"https://abso.dev/login/box?code=WXYZ-BCDF\"]);\n+\tassert.deepEqual(said.slice(0, 2), [\n+\t\t\"Opening the approve page in your browser.\",\n+\t\t\"To sign this box in, open https://abso.dev/login/box?code=WXYZ-BCDF and approve the code WXYZ-BCDF.\",\n+\t]);\n+});\n+\n+test(\"an open that doesn't start says nothing about a browser, and the printed link stands\", async () => {\n+\tconst said: string[] = [];\n+\tconst c = clock();\n+\tawait login(\n+\t\tSERVER,\n+\t\t{\n+\t\t\tfetch: server(\n+\t\t\t\t[\n+\t\t\t\t\t[200, started],\n+\t\t\t\t\t[200, { box_id: \"b_0123abcd\", box_token: CREDENTIAL, expires_at: EXPIRES, grant }],\n+\t\t\t\t],\n+\t\t\t\t[],\n+\t\t\t),\n+\t\t\tsleep: c.sleep,\n+\t\t\tnow: c.now,\n+\t\t\tsay: (line) => said.push(line),\n+\t\t\topen: () => false,\n+\t\t},\n+\t\thome(),\n+\t);\n+\tassert.equal(\n+\t\tsaid[0],\n+\t\t\"To sign this box in, open https://abso.dev/login/box?code=WXYZ-BCDF and approve the code WXYZ-BCDF.\",\n+\t);\n+\tassert.equal(\n+\t\tsaid.some((l) => l.includes(\"browser\")),\n+\t\tfalse,\n+\t);\n+});\n+\n test(\"a code that's turned down or runs out says so and keeps nothing\", async () => {\n \tconst h = home();\n \tconst c = clock();"},{"path":"client/test/open-browser.test.ts","added":67,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/open-browser.test.ts\n@@ -0,0 +1,67 @@\n+// Opening the approve page in the person's browser: when it's skipped, which program opens it on each\n+// platform, and that a failed open is silent.\n+\n+import assert from \"node:assert/strict\";\n+import type { spawn } from \"node:child_process\";\n+import { EventEmitter } from \"node:events\";\n+import { test } from \"node:test\";\n+import { browserSkip, isWebLink, openCommand, openInBrowser } from \"../src/open-browser.ts\";\n+\n+const LINK = \"https://abso.dev/login/box?code=WXYZ-BCDF&from=cli\";\n+\n+test(\"a desktop opens a browser\", () => {\n+\tassert.equal(browserSkip({}, \"win32\"), null);\n+\tassert.equal(browserSkip({}, \"darwin\"), null);\n+\tassert.equal(browserSkip({ DISPLAY: \":0\" }, \"linux\"), null);\n+\tassert.equal(browserSkip({ WAYLAND_DISPLAY: \"wayland-0\" }, \"linux\"), null);\n+\tassert.equal(browserSkip({ CI: \"false\" }, \"darwin\"), null, \"CI=false isn't CI\");\n+});\n+\n+test(\"no browser with ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display\", () => {\n+\tassert.equal(browserSkip({ ABSO_NO_BROWSER: \"1\" }, \"win32\"), \"ABSO_NO_BROWSER is set\");\n+\tassert.equal(browserSkip({ SSH_CONNECTION: \"10.0.0.2 51234 10.0.0.1 22\" }, \"darwin\"), \"this is an SSH session\");\n+\tassert.equal(browserSkip({ SSH_TTY: \"/dev/pts/0\", DISPLAY: \":0\" }, \"linux\"), \"this is an SSH session\");\n+\tassert.equal(browserSkip({ CI: \"true\" }, \"win32\"), \"this is CI\");\n+\tassert.equal(browserSkip({}, \"linux\"), \"there's no display\");\n+\tassert.equal(browserSkip({}, \"freebsd\"), \"there's no display\");\n+});\n+\n+test(\"each platform's opener takes the link whole, with no shell to split it at &\", () => {\n+\tassert.deepEqual(openCommand(LINK, \"win32\"), [\"rundll32\", [\"url.dll,FileProtocolHandler\", LINK]]);\n+\tassert.deepEqual(openCommand(LINK, \"darwin\"), [\"open\", [LINK]]);\n+\tassert.deepEqual(openCommand(LINK, \"linux\"), [\"xdg-open\", [LINK]]);\n+});\n+\n+test(\"only web pages are opened\", () => {\n+\tassert.equal(isWebLink(LINK), true);\n+\tassert.equal(isWebLink(\"http://localhost:8787/login/box?code=A\"), true);\n+\tfor (const bad of [\"file:///C:/Windows/System32/calc.exe\", \"javascript:alert(1)\", \"C:\\\\x.exe\", \"not a link\", \"\"])\n+\t\tassert.equal(isWebLink(bad), false, bad);\n+});\n+\n+type Call = { command: string; args: readonly string[]; options: unknown };\n+function fakeSpawn(calls: Call[], fail?: \"throw\" | \"error\"): typeof spawn {\n+\treturn ((command: string, args: readonly string[], options: unknown) => {\n+\t\tcalls.push({ command, args, options });\n+\t\tif (fail === \"throw\") throw new Error(\"spawn EACCES\");\n+\t\tconst child = Object.assign(new EventEmitter(), { unref: () => {} });\n+\t\tif (fail === \"error\") queueMicrotask(() => child.emit(\"error\", new Error(\"spawn xdg-open ENOENT\")));\n+\t\treturn child;\n+\t}) as unknown as typeof spawn;\n+}\n+\n+test(\"openInBrowser starts the opener without waiting on it, and a failure is silent\", async () => {\n+\tconst calls: Call[] = [];\n+\tassert.equal(openInBrowser(LINK, \"win32\", fakeSpawn(calls)), true);\n+\tassert.deepEqual(calls[0]?.command, \"rundll32\");\n+\tassert.deepEqual(calls[0]?.args, [\"url.dll,FileProtocolHandler\", LINK]);\n+\tassert.deepEqual(calls[0]?.options, { detached: true, stdio: \"ignore\", windowsHide: true });\n+\n+\tassert.equal(openInBrowser(LINK, \"linux\", fakeSpawn([], \"throw\")), false);\n+\tassert.equal(openInBrowser(LINK, \"linux\", fakeSpawn([], \"error\")), true);\n+\tawait new Promise((done) => setTimeout(done, 0)); // the error event fires, and nothing throws\n+\n+\tconst none: Call[] = [];\n+\tassert.equal(openInBrowser(\"file:///etc/passwd\", \"linux\", fakeSpawn(none)), false);\n+\tassert.equal(none.length, 0, \"a link that isn't a web page never reaches the opener\");\n+});"}],"ci":null}