{"version":38,"agent":"speed","message":"client/launch.mjs: run the client from a git checkout and keep it current. It runs a plain-JS bundle of the client in the same process when the bundle matches the checkout's commit, and client/abso.ts otherwise. A background step, one at a time under a lock, fast-forwards main, installs when package-lock.json changed, and builds the bundle (temporary file, checked, then renamed into place). stdin, stdout, stderr, arguments and exit codes pass through; a bundle that fails to load falls back to the .ts in the same run, and a command that started is never run twice. Notices go only to ~/.abso/launcher.log. Tests run it against a throwaway checkout and home.","time":1791548358594,"timeIso":"2026-10-09T12:19:18.594Z","changes":16,"change":502,"files":["client/README.md","client/launch.mjs","client/test/launch.test.ts"],"draft":null,"diff":[{"path":"client/README.md","added":16,"removed":0,"diff":"--- a/client/README.md\n+++ b/client/README.md\n@@ -11,6 +11,22 @@\n node client/abso.ts help\n ```\n \n+### Running it from a git checkout\n+\n+`client/launch.mjs` runs the client from a git checkout of abso and keeps the\n+checkout current. Point your `abso` command at it:\n+\n+```bash\n+node /path/to/abso/client/launch.mjs help\n+```\n+\n+It runs a bundle of the client when one matches the checkout's commit, which\n+starts several times faster than the TypeScript, and `client/abso.ts`\n+otherwise. Every few minutes it fast-forwards the checkout (on `main` only)\n+and builds the bundle in the background, with esbuild if the checkout has it.\n+It never changes the command's output or exit code, and writes its own notices\n+to `~/.abso/launcher.log`.\n+\n ## Setting up a folder\n \n Folders and machines set up before abso had its name keep working: the older "},{"path":"client/launch.mjs","added":214,"removed":0,"diff":"--- /dev/null\n+++ b/client/launch.mjs\n@@ -0,0 +1,214 @@\n+// Runs abso from a git checkout of it and keeps that checkout current.\n+//\n+// Point a command at this file (node <checkout>/client/launch.mjs <args>) and it:\n+// - runs the client: a plain-JS bundle of it in this process when one matches the checkout's commit,\n+//   otherwise client/abso.ts in a second node. Node strips types from every client file on every run,\n+//   so the bundle starts several times faster;\n+// - at most every 5 minutes, and within 30 seconds of a stale bundle, starts a background step that\n+//   fast-forwards the checkout (on main only), runs npm install when package-lock.json changed, and\n+//   builds the bundle. That step never blocks or fails the command, and only one runs at a time.\n+//\n+// stdin, stdout, stderr, the arguments and the exit code pass through untouched: the exit codes carry\n+// meaning (2 refused, 3 still queued). The launcher's own notices go only to ~/.abso/launcher.log.\n+//\n+// The bundle is client/dist/abso.mjs, with the commit it was built from in client/dist/abso.mjs.commit.\n+// It sits one folder under client/, so the client's own folder (client-version.ts) is still client/.\n+// It is built with esbuild when the checkout has it (in worker/ or at the root): bundled, for node24,\n+// as an ES module, with no build commit stamped in, since a stamped client calls itself a downloaded\n+// copy. It is built to a temporary file and renamed into place, and marked current only after every\n+// require left in it resolves and it runs --version. If it still fails to load, the same run falls\n+// back to client/abso.ts and writes one line to the log, so edit hooks keep recording.\n+//\n+// Plain JS on purpose: this file is loaded on every command, before any bundle.\n+import { execFileSync, spawn } from \"node:child_process\";\n+import { appendFileSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n+import { createRequire } from \"node:module\";\n+import { homedir } from \"node:os\";\n+import { dirname, join } from \"node:path\";\n+import { fileURLToPath, pathToFileURL } from \"node:url\";\n+\n+const repo = dirname(dirname(fileURLToPath(import.meta.url)));\n+const state = join(homedir(), \".abso\");\n+const stamp = join(state, \"client-update.stamp\");\n+const every = 5 * 60 * 1000;\n+const bundle = join(repo, \"client\", \"dist\", \"abso.mjs\");\n+const bundleCommit = `${bundle}.commit`;\n+/** Set on the background step's own node, which updates the checkout and exits. */\n+const UPDATE = \"ABSO_LAUNCH_UPDATE\";\n+/** Set by the bundle's first line: an error after it came from the command, so it's never run again. */\n+const STARTED = \"__absoBundleStarted\";\n+\n+/** The checkout's commit, read from .git without running git; undefined if it can't be read. */\n+function headCommit(root = repo) {\n+\ttry {\n+\t\tconst head = readFileSync(join(root, \".git\", \"HEAD\"), \"utf8\").trim();\n+\t\tif (!head.startsWith(\"ref:\")) return head;\n+\t\tconst ref = head.slice(4).trim();\n+\t\ttry {\n+\t\t\treturn readFileSync(join(root, \".git\", ...ref.split(\"/\")), \"utf8\").trim();\n+\t\t} catch {\n+\t\t\tconst line = readFileSync(join(root, \".git\", \"packed-refs\"), \"utf8\")\n+\t\t\t\t.split(\"\\n\")\n+\t\t\t\t.find((l) => l.endsWith(` ${ref}`));\n+\t\t\treturn line?.split(\" \")[0];\n+\t\t}\n+\t} catch {\n+\t\treturn undefined;\n+\t}\n+}\n+\n+/** Runs fn under a lock folder; a lock older than 10 minutes is a dead run's and is cleared. */\n+function locked(lock, fn) {\n+\ttry {\n+\t\tif (Date.now() - statSync(lock).mtimeMs > 10 * 60 * 1000) rmSync(lock, { recursive: true, force: true });\n+\t} catch {}\n+\ttry {\n+\t\tmkdirSync(lock);\n+\t} catch {\n+\t\treturn;\n+\t}\n+\ttry {\n+\t\tfn();\n+\t} finally {\n+\t\trmSync(lock, { recursive: true, force: true });\n+\t}\n+}\n+\n+/** One line in the launcher's log, never on the command's own output. */\n+function note(text) {\n+\ttry {\n+\t\tmkdirSync(state, { recursive: true });\n+\t\tappendFileSync(join(state, \"launcher.log\"), `${new Date().toISOString()} abso launch: ${text}\\n`);\n+\t} catch {}\n+}\n+\n+/**\n+ * The background step, one at a time under a lock (a second one finds it taken and exits): fast-forward,\n+ * install when the lock file moved, then the bundle.\n+ */\n+function update() {\n+\tconst git = (...a) => execFileSync(\"git\", [\"-C\", repo, ...a], { encoding: \"utf8\", windowsHide: true });\n+\tmkdirSync(state, { recursive: true });\n+\tlocked(join(state, \"client-update.lock\"), () => {\n+\t\ttry {\n+\t\t\tif (git(\"branch\", \"--show-current\").trim() === \"main\") {\n+\t\t\t\tconst before = git(\"rev-parse\", \"HEAD\").trim();\n+\t\t\t\tgit(\"fetch\", \"-q\", \"origin\", \"main\");\n+\t\t\t\tgit(\"merge\", \"-q\", \"--ff-only\", \"origin/main\");\n+\t\t\t\tif (git(\"diff\", \"--name-only\", before, \"HEAD\", \"--\", \"package-lock.json\").trim())\n+\t\t\t\t\texecFileSync(\"npm\", [\"install\", \"--no-audit\", \"--no-fund\"], {\n+\t\t\t\t\t\tcwd: repo,\n+\t\t\t\t\t\tstdio: \"ignore\",\n+\t\t\t\t\t\twindowsHide: true,\n+\t\t\t\t\t\tshell: true,\n+\t\t\t\t\t});\n+\t\t\t}\n+\t\t} catch {}\n+\t\ttry {\n+\t\t\tbuild(git(\"rev-parse\", \"HEAD\").trim());\n+\t\t} catch (e) {\n+\t\t\tnote(`the bundle wasn't built (${String(e?.message).split(\"\\n\")[0]}); client/abso.ts runs until it is`);\n+\t\t}\n+\t});\n+}\n+\n+/** Builds the bundle for this commit, unless it's already current or the checkout has no esbuild. */\n+function build(head) {\n+\ttry {\n+\t\tif (readFileSync(bundleCommit, \"utf8\").trim() === head) return;\n+\t} catch {}\n+\tconst require = createRequire(import.meta.url);\n+\tlet esbuild;\n+\ttry {\n+\t\tesbuild = require(require.resolve(\"esbuild\", { paths: [join(repo, \"worker\"), repo] }));\n+\t} catch {\n+\t\treturn;\n+\t}\n+\tconst exclude = join(repo, \".git\", \"info\", \"exclude\");\n+\ttry {\n+\t\tif (!readFileSync(exclude, \"utf8\").split(/\\r?\\n/).includes(\"client/dist/\"))\n+\t\t\tappendFileSync(exclude, \"\\nclient/dist/\\n\");\n+\t} catch {}\n+\tmkdirSync(dirname(bundle), { recursive: true });\n+\tconst tmp = bundle.replace(/\\.mjs$/, `.${process.pid}.tmp.mjs`);\n+\ttry {\n+\t\tesbuild.buildSync({\n+\t\t\tentryPoints: [join(repo, \"client\", \"abso.ts\")],\n+\t\t\tbundle: true,\n+\t\t\tplatform: \"node\",\n+\t\t\tformat: \"esm\",\n+\t\t\ttarget: \"node24\",\n+\t\t\toutfile: tmp,\n+\t\t\tlogLevel: \"silent\",\n+\t\t\t// A bundled CommonJS package (yaml) calls require(\"process\") lazily, which an ES module\n+\t\t\t// bundle can't do without a real require. The flag says the bundle started running.\n+\t\t\tbanner: {\n+\t\t\t\tjs: `globalThis.${STARTED} = true; import { createRequire as __absoCreateRequire } from \"node:module\"; const require = __absoCreateRequire(import.meta.url);`,\n+\t\t\t},\n+\t\t});\n+\t\tconst from = createRequire(bundle);\n+\t\tfor (const m of readFileSync(tmp, \"utf8\").matchAll(/__require\\(\"([^\"]+)\"\\)/g)) from.resolve(m[1]);\n+\t\texecFileSync(process.execPath, [tmp, \"--version\"], { cwd: repo, stdio: \"ignore\", windowsHide: true });\n+\t\trenameSync(tmp, bundle);\n+\t\twriteFileSync(bundleCommit, `${head}\\n`);\n+\t} finally {\n+\t\trmSync(tmp, { force: true });\n+\t}\n+}\n+\n+/** Runs client/abso.ts in a second node, and exits with its code. */\n+function runTs() {\n+\tconst child = spawn(process.execPath, [join(repo, \"client\", \"abso.ts\"), ...process.argv.slice(2)], {\n+\t\tstdio: \"inherit\",\n+\t});\n+\tchild.on(\"exit\", (code, signal) => process.exit(code ?? (signal ? 1 : 0)));\n+}\n+\n+/** Starts the background step when it's due: every 5 minutes, or within 30 seconds of a stale bundle. */\n+function maybeUpdate(fresh) {\n+\ttry {\n+\t\tlet last = 0;\n+\t\ttry {\n+\t\t\tlast = statSync(stamp).mtimeMs;\n+\t\t} catch {}\n+\t\tif (Date.now() - last <= (fresh ? every : 30_000)) return;\n+\t\tmkdirSync(state, { recursive: true });\n+\t\twriteFileSync(stamp, `${new Date().toISOString()}\\n`);\n+\t\tspawn(process.execPath, [fileURLToPath(import.meta.url)], {\n+\t\t\tdetached: true,\n+\t\t\tstdio: \"ignore\",\n+\t\t\twindowsHide: true,\n+\t\t\tenv: { ...process.env, [UPDATE]: \"1\" },\n+\t\t}).unref();\n+\t} catch {}\n+}\n+\n+/** The command: the bundle when it matches the checkout, else client/abso.ts. */\n+async function run() {\n+\tconst head = headCommit();\n+\tlet fresh = false;\n+\ttry {\n+\t\tfresh = head !== undefined && readFileSync(bundleCommit, \"utf8\").trim() === head;\n+\t} catch {}\n+\tmaybeUpdate(fresh);\n+\tif (!fresh) return runTs();\n+\t// In this process: the client reads its arguments from process.argv, as if run as `node client/dist/abso.mjs`.\n+\tconst args = process.argv;\n+\tprocess.argv = [args[0], bundle, ...args.slice(2)];\n+\ttry {\n+\t\tawait import(pathToFileURL(bundle).href);\n+\t} catch (e) {\n+\t\t// Only a bundle that never started falls back: one that can't be found or parsed, or imports\n+\t\t// something missing. Anything else came from the command itself, which the .ts would repeat.\n+\t\tconst code = e?.code;\n+\t\tconst loading =\n+\t\t\te instanceof SyntaxError || code === \"ERR_MODULE_NOT_FOUND\" || code === \"ERR_UNSUPPORTED_ESM_URL_SCHEME\";\n+\t\tif (!loading || globalThis[STARTED] === true) throw e;\n+\t\tnote(`the bundle didn't load (${code ?? e?.name}: ${String(e?.message).split(\"\\n\")[0]}), ran client/abso.ts`);\n+\t\tprocess.argv = args;\n+\t\trunTs();\n+\t}\n+}\n+\n+if (process.env[UPDATE] === \"1\") update();\n+else await run();"},{"path":"client/test/launch.test.ts","added":137,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/launch.test.ts\n@@ -0,0 +1,137 @@\n+// client/launch.mjs: which client a run takes, and that a bad bundle never stops a command.\n+// Each test runs the real launch.mjs from a throwaway git checkout, with a stand-in client, and a home of its own.\n+\n+import assert from \"node:assert/strict\";\n+import { execFileSync, spawnSync } from \"node:child_process\";\n+import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { describe, it } from \"node:test\";\n+\n+const LAUNCH = new URL(\"../launch.mjs\", import.meta.url);\n+\n+/** A checkout on main with one commit, launch.mjs and a stand-in client/abso.ts that names itself. */\n+function checkout(): { repo: string; home: string; head: string } {\n+\tconst root = mkdtempSync(join(tmpdir(), \"abso-launch-\"));\n+\tconst repo = join(root, \"repo\");\n+\tconst home = join(root, \"home\");\n+\tmkdirSync(join(repo, \"client\"), { recursive: true });\n+\tcopyFileSync(LAUNCH, join(repo, \"client\", \"launch.mjs\"));\n+\twriteFileSync(\n+\t\tjoin(repo, \"client\", \"abso.ts\"),\n+\t\t'console.log(\"ts \" + JSON.stringify(process.argv.slice(2)));\\nprocess.exitCode = Number(process.env.FAKE_EXIT ?? 0);\\n',\n+\t);\n+\tconst git = (...a: string[]) => execFileSync(\"git\", [\"-C\", repo, ...a], { encoding: \"utf8\" });\n+\tgit(\"init\", \"-q\", \"-b\", \"main\");\n+\tgit(\"add\", \".\");\n+\tgit(\"-c\", \"user.name=t\", \"-c\", \"user.email=t@example.com\", \"commit\", \"-q\", \"-m\", \"one\");\n+\t// A stamp from now: no background step starts during a test.\n+\tmkdirSync(join(home, \".abso\"), { recursive: true });\n+\twriteFileSync(join(home, \".abso\", \"client-update.stamp\"), \"now\\n\");\n+\treturn { repo, home, head: git(\"rev-parse\", \"HEAD\").trim() };\n+}\n+\n+function bundle(repo: string, text: string, commit: string): void {\n+\tmkdirSync(join(repo, \"client\", \"dist\"), { recursive: true });\n+\twriteFileSync(join(repo, \"client\", \"dist\", \"abso.mjs\"), text);\n+\twriteFileSync(join(repo, \"client\", \"dist\", \"abso.mjs.commit\"), `${commit}\\n`);\n+}\n+\n+function launch(c: { repo: string; home: string }, args: string[], env: Record<string, string> = {}) {\n+\treturn spawnSync(process.execPath, [join(c.repo, \"client\", \"launch.mjs\"), ...args], {\n+\t\tencoding: \"utf8\",\n+\t\tenv: { ...process.env, HOME: c.home, USERPROFILE: c.home, ...env },\n+\t});\n+}\n+\n+const NAMES_ITSELF = 'console.log(\"bundle \" + JSON.stringify(process.argv.slice(1)));\\n';\n+\n+describe(\"client/launch.mjs\", () => {\n+\tit(\"runs client/abso.ts when there's no bundle, with the arguments and exit code passed through\", () => {\n+\t\tconst c = checkout();\n+\t\tconst r = launch(c, [\"issue\", \"42\"], { FAKE_EXIT: \"3\" });\n+\t\tassert.equal(r.stdout.trim(), 'ts [\"issue\",\"42\"]');\n+\t\tassert.equal(r.status, 3);\n+\t});\n+\n+\tit(\"runs the bundle in its own process when it was built from the checkout's commit\", () => {\n+\t\tconst c = checkout();\n+\t\tbundle(c.repo, NAMES_ITSELF, c.head);\n+\t\tconst r = launch(c, [\"--version\"]);\n+\t\tassert.equal(\n+\t\t\tr.stdout.trim(),\n+\t\t\t`bundle ${JSON.stringify([join(c.repo, \"client\", \"dist\", \"abso.mjs\"), \"--version\"])}`,\n+\t\t);\n+\t\tassert.equal(r.status, 0);\n+\t});\n+\n+\tit(\"runs client/abso.ts when the bundle is from another commit\", () => {\n+\t\tconst c = checkout();\n+\t\tbundle(c.repo, NAMES_ITSELF, \"0\".repeat(40));\n+\t\tassert.equal(launch(c, [\"status\"]).stdout.trim(), 'ts [\"status\"]');\n+\t});\n+\n+\tit(\"falls back to client/abso.ts in the same run when the bundle doesn't load, and writes one line\", () => {\n+\t\tconst c = checkout();\n+\t\tbundle(c.repo, \"this is not javascript (\\n\", c.head);\n+\t\tconst r = launch(c, [\"log\"]);\n+\t\tassert.equal(r.stdout.trim(), 'ts [\"log\"]');\n+\t\tassert.equal(r.status, 0);\n+\t\t// The launcher's own notice goes to its log only, never on the command's output.\n+\t\tassert.equal(r.stderr, \"\");\n+\t\tconst log = readFileSync(join(c.home, \".abso\", \"launcher.log\"), \"utf8\")\n+\t\t\t.trim()\n+\t\t\t.split(\"\\n\");\n+\t\tassert.equal(log.length, 1);\n+\t\tassert.match(log[0]!, /the bundle didn't load \\(SyntaxError/);\n+\t});\n+\n+\tit(\"doesn't run a command twice when it fails inside a bundle that loaded\", () => {\n+\t\tconst c = checkout();\n+\t\tbundle(c.repo, 'throw new Error(\"the command failed\");\\n', c.head);\n+\t\tconst r = launch(c, [\"publish\"]);\n+\t\tassert.notEqual(r.status, 0);\n+\t\tassert.doesNotMatch(r.stdout, /^ts /m);\n+\t\tassert.equal(existsSync(join(c.home, \".abso\", \"launcher.log\")), false);\n+\t});\n+\n+\tit(\"doesn't run a command twice when it throws a SyntaxError after the bundle started\", () => {\n+\t\tconst c = checkout();\n+\t\tbundle(c.repo, 'globalThis.__absoBundleStarted = true;\\nJSON.parse(\"{\");\\n', c.head);\n+\t\tconst r = launch(c, [\"publish\"]);\n+\t\tassert.notEqual(r.status, 0);\n+\t\tassert.doesNotMatch(r.stdout, /^ts /m);\n+\t\tassert.equal(existsSync(join(c.home, \".abso\", \"launcher.log\")), false);\n+\t});\n+\n+\tit(\"passes stdin through to the client, from the bundle and from the .ts\", () => {\n+\t\tconst c = checkout();\n+\t\tconst echo = 'let s = \"\";\\nprocess.stdin.on(\"data\", (d) => (s += d)).on(\"end\", () => console.log(\"got \" + s));\\n';\n+\t\twriteFileSync(join(c.repo, \"client\", \"abso.ts\"), echo);\n+\t\tconst fed = (input: string) =>\n+\t\t\tspawnSync(process.execPath, [join(c.repo, \"client\", \"launch.mjs\")], {\n+\t\t\t\tinput,\n+\t\t\t\tencoding: \"utf8\",\n+\t\t\t\tenv: { ...process.env, HOME: c.home, USERPROFILE: c.home },\n+\t\t\t}).stdout.trim();\n+\t\tassert.equal(fed(\"from the ts\"), \"got from the ts\");\n+\t\tbundle(c.repo, echo, c.head);\n+\t\tassert.equal(fed(\"from the bundle\"), \"got from the bundle\");\n+\t});\n+\n+\tit(\"runs one background step at a time: a second finds the lock taken and leaves it\", () => {\n+\t\tconst c = checkout();\n+\t\tconst lock = join(c.home, \".abso\", \"client-update.lock\");\n+\t\tmkdirSync(lock);\n+\t\tassert.equal(launch(c, [], { ABSO_LAUNCH_UPDATE: \"1\" }).status, 0);\n+\t\tassert.equal(existsSync(lock), true);\n+\t});\n+\n+\tit(\"keeps the background step quiet when it can't fetch or build\", () => {\n+\t\tconst c = checkout();\n+\t\tconst r = launch(c, [], { ABSO_LAUNCH_UPDATE: \"1\" });\n+\t\tassert.equal(r.status, 0);\n+\t\tassert.equal(r.stdout, \"\");\n+\t\tassert.equal(existsSync(join(c.repo, \"client\", \"dist\", \"abso.mjs.commit\")), false);\n+\t});\n+});"}],"ci":null}