{"agent":"codex-npm-release-builder","draft":"codex-npm-package","base":0,"files":[{"path":"abso.yml","added":19,"removed":0,"diff":"--- /dev/null\n+++ b/abso.yml\n@@ -0,0 +1,19 @@\n+pipelines:\n+  npm:\n+    # Build on push; only the green run may publish. Each run packs its own exact version.\n+    on: [push, green]\n+    only: shared\n+    jobs:\n+      pack:\n+        run: >-\n+          npm ci --ignore-scripts --no-audit --no-fund &&\n+          node scripts/npm-package.mjs dist/npm &&\n+          npm pack ./dist/npm/abso --ignore-scripts --pack-destination dist/npm\n+        keep: [dist/npm/**]\n+      publish:\n+        needs: [pack]\n+        uses: npm-publish\n+        from: npm.pack\n+        packages: [\"@abso-cli/abso\"]\n+        tag: latest\n+    required: [pack, publish]"},{"path":"package-lock.json","blob":{"before":"b10521cd9bad10eb98035f0fbc6a047bd7cd4c708d1db2dd836dc455e32db3ad","after":"9ffbbcbab4063436fcaf996d3d8ff48cbe95b700e22a556dc156f6bc38d2ca64"},"added":0,"removed":0,"diff":"Binary file package-lock.json changed: b10521cd9bad -> 9ffbbcbab406"},{"path":"package.json","added":1,"removed":0,"diff":"--- a/package.json\n+++ b/package.json\n@@ -19,6 +19,7 @@\n \t\"devDependencies\": {\n \t\t\"@biomejs/biome\": \"2.5.15\",\n \t\t\"@types/node\": \"^24.19.1\",\n+\t\t\"esbuild\": \"0.28.2\",\n \t\t\"typescript\": \"^5.9.3\"\n \t},\n \t\"dependencies\": {"},{"path":"scripts/npm-package-lib.mjs","added":44,"removed":0,"diff":"--- /dev/null\n+++ b/scripts/npm-package-lib.mjs\n@@ -0,0 +1,44 @@\n+import { mkdirSync, realpathSync, rmSync } from \"node:fs\";\n+import { isAbsolute, join, relative, resolve, sep } from \"node:path\";\n+\n+/** Rebuild only a generated package under this checkout's dist folder, including on reused workspaces. */\n+export function preparePackageDirectory(root, output) {\n+\tconst generated = resolve(root, \"dist\");\n+\tconst out = resolve(output);\n+\tconst under = relative(generated, out);\n+\tif (isAbsolute(under) || under === \"..\" || under.startsWith(`..${sep}`))\n+\t\tthrow new Error(\"npm-package output must be inside this checkout's dist folder\");\n+\tmkdirSync(out, { recursive: true });\n+\tconst realGenerated = join(realpathSync(root), \"dist\");\n+\tconst realOut = realpathSync(out);\n+\tconst realUnder = relative(realGenerated, realOut);\n+\tif (isAbsolute(realUnder) || realUnder === \"..\" || realUnder.startsWith(`..${sep}`))\n+\t\tthrow new Error(\"npm-package output resolves outside this checkout's dist folder\");\n+\tconst destination = join(realOut, \"abso\");\n+\t// The resolved parent is checked above. rm removes a symlink at destination itself without following it.\n+\trmSync(destination, { recursive: true, force: true });\n+\treturn destination;\n+}\n+\n+/** A package version tied to the exact shared version the build runner provides. */\n+export function packageVersion(sharedVersion) {\n+\tif (\n+\t\ttypeof sharedVersion !== \"string\" ||\n+\t\t!/^[1-9][0-9]*$/.test(sharedVersion) ||\n+\t\t!Number.isSafeInteger(Number(sharedVersion))\n+\t)\n+\t\tthrow new Error(\"npm-package needs ABSO_VERSION set to the positive shared version being built\");\n+\treturn `0.${sharedVersion}.0`;\n+}\n+\n+/** Reject accidental server code, embedded credentials and private capability URLs. Setting names are fine. */\n+export function bundleProblems(source) {\n+\tconst forbidden = [\n+\t\t[\"admin token\", /AVCS_ADMIN_TOKEN\\s*[:=]\\s*['\"][^'\"]{8,}/],\n+\t\t[\"key secret\", /KEY_HMAC_SECRET\\s*[:=]\\s*['\"][^'\"]{8,}/],\n+\t\t[\"zone token\", /CLOUDFLARE_ZONE_TOKEN\\s*[:=]\\s*['\"][^'\"]{8,}/],\n+\t\t[\"server source\", /from [\"']cloudflare:workers[\"']/],\n+\t\t[\"preview link\", /\\/v\\/[A-Za-z0-9._-]+\\/\\d+\\/[0-9a-f]{24}\\//],\n+\t];\n+\treturn forbidden.filter(([, expression]) => expression.test(source)).map(([name]) => name);\n+}"},{"path":"scripts/npm-package.mjs","added":68,"removed":0,"diff":"--- /dev/null\n+++ b/scripts/npm-package.mjs\n@@ -0,0 +1,68 @@\n+// Builds a self-contained npm package from this checkout. Never publishes or reads authentication.\n+import { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\n+import { dirname, join } from \"node:path\";\n+import { fileURLToPath } from \"node:url\";\n+import { build, transform } from \"esbuild\";\n+import { bundleProblems, packageVersion, preparePackageDirectory } from \"./npm-package-lib.mjs\";\n+\n+const root = fileURLToPath(new URL(\"../\", import.meta.url));\n+const args = process.argv.slice(2);\n+if (args.length !== 1 || !args[0]) {\n+\tconsole.error(\"Use: ABSO_VERSION=<shared version> node scripts/npm-package.mjs <folder under dist>\");\n+\tprocess.exit(2);\n+}\n+const version = packageVersion(process.env.ABSO_VERSION);\n+const canonical = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\"));\n+const minimumNode = canonical.engines?.node?.match(/^>=([1-9][0-9]*)$/)?.[1];\n+if (!minimumNode) throw new Error(\"npm-package needs the canonical minimum Node major in engines.node\");\n+const built = await build({\n+\tentryPoints: [join(root, \"client/abso.ts\")],\n+\tbundle: true,\n+\tplatform: \"node\",\n+\tformat: \"esm\",\n+\ttarget: `node${minimumNode}`,\n+\twrite: false,\n+\toutfile: \"abso.mjs\",\n+\tbanner: { js: `globalThis.__ABSO_PACKAGE_VERSION__ = ${JSON.stringify(version)};` },\n+\tlogLevel: \"warning\",\n+});\n+const plain = built.outputFiles[0].text;\n+const body = (await transform(plain, { minify: true, format: \"esm\", target: `node${minimumNode}`, loader: \"js\" })).code;\n+const problems = [...new Set([...bundleProblems(plain), ...bundleProblems(body)])];\n+if (problems.length) throw new Error(`npm-package: the bundle holds ${problems.join(\", \")}`);\n+const files = {\n+\t\"package.json\": `${JSON.stringify(\n+\t\t{\n+\t\t\tname: \"@abso-cli/abso\",\n+\t\t\tversion,\n+\t\t\tdescription: \"abso: version control built for AI agents first. The command line client.\",\n+\t\t\tlicense: \"MIT\",\n+\t\t\thomepage: \"https://abso.dev\",\n+\t\t\ttype: \"module\",\n+\t\t\tengines: { node: `>=${minimumNode}` },\n+\t\t\tbin: { abso: \"bin/abso.mjs\" },\n+\t\t\tfiles: [\"bin\", \"dist\"],\n+\t\t\tpublishConfig: { access: \"public\" },\n+\t\t},\n+\t\tnull,\n+\t\t2,\n+\t)}\\n`,\n+\t\"bin/abso.mjs\": `#!/usr/bin/env node\n+const major = Number(process.versions.node.split(\".\")[0]);\n+if (major < ${minimumNode}) {\n+\tprocess.stderr.write(\"abso needs Node ${minimumNode} or later, and this is Node \" + process.versions.node + \". Install a newer Node from https://nodejs.org and run abso again.\\\\n\");\n+\tprocess.exit(1);\n+}\n+import(\"../dist/abso.mjs\");\n+`,\n+\t\"dist/abso.mjs\": body,\n+\t\"README.md\": `# abso\\n\\nabso is version control for agents. This package provides the abso command line.\\n\\nRequires Node ${minimumNode} or later. Install with \\`npm install -g @abso-cli/abso\\`, or run \\`npx @abso-cli/abso help\\`.\\n\\n[abso.dev](https://abso.dev)\\n`,\n+\tLICENSE: readFileSync(join(root, \"LICENSE\"), \"utf8\"),\n+};\n+const destination = preparePackageDirectory(root, args[0]);\n+for (const [relative, text] of Object.entries(files)) {\n+\tconst path = join(destination, relative);\n+\tmkdirSync(dirname(path), { recursive: true });\n+\twriteFileSync(path, text);\n+}\n+console.log(`npm-package: @abso-cli/abso ${version} (${body.length} bundle bytes)`);"},{"path":"scripts/npm-package.test.ts","added":94,"removed":0,"diff":"--- /dev/null\n+++ b/scripts/npm-package.test.ts\n@@ -0,0 +1,94 @@\n+import assert from \"node:assert/strict\";\n+import { spawnSync } from \"node:child_process\";\n+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { dirname, join } from \"node:path\";\n+import { test } from \"node:test\";\n+import { fileURLToPath } from \"node:url\";\n+import { runInNewContext } from \"node:vm\";\n+import { readPipelineFile } from \"../src/pipeline/pipeline.ts\";\n+import { plan } from \"../src/pipeline/plan.ts\";\n+// @ts-expect-error: the package builder's plain JavaScript helpers\n+import { bundleProblems, packageVersion, preparePackageDirectory } from \"./npm-package-lib.mjs\";\n+\n+test(\"npm versions use only the runner's positive exact shared version\", () => {\n+\tassert.equal(packageVersion(\"101\"), \"0.101.0\");\n+\tfor (const value of [undefined, \"\", \"0\", \"-1\", \"001\", \"1.5\", \"1;echo\", \"9007199254740992\"])\n+\t\tassert.throws(() => packageVersion(value), /ABSO_VERSION/);\n+});\n+\n+test(\"npm bundles refuse server code and embedded credentials\", () => {\n+\tassert.deepEqual(bundleProblems('const name = \"ABSO_KEY_FILE\";'), []);\n+\tassert.deepEqual(bundleProblems('import { WorkerEntrypoint } from \"cloudflare:workers\";'), [\"server source\"]);\n+\tassert.deepEqual(bundleProblems('KEY_HMAC_SECRET = \"synthetic-test-value\";'), [\"key secret\"]);\n+});\n+\n+test(\"rebuilding a package removes stale bin and dist assets before npm can include them\", () => {\n+\tconst root = dirname(dirname(fileURLToPath(import.meta.url)));\n+\tconst dist = join(root, \"dist\");\n+\tmkdirSync(dist, { recursive: true });\n+\tconst output = mkdtempSync(join(dist, \"npm-rebuild-test-\"));\n+\ttry {\n+\t\tfor (const directory of [\"bin\", \"dist\"]) {\n+\t\t\tmkdirSync(join(output, \"abso\", directory), { recursive: true });\n+\t\t\twriteFileSync(join(output, \"abso\", directory, \"stale.js\"), \"stale package asset\");\n+\t\t}\n+\t\tconst built = spawnSync(process.execPath, [join(root, \"scripts/npm-package.mjs\"), output], {\n+\t\t\tcwd: root,\n+\t\t\tenv: { ...process.env, ABSO_VERSION: \"101\" },\n+\t\t\tencoding: \"utf8\",\n+\t\t\twindowsHide: true,\n+\t\t});\n+\t\tassert.equal(built.status, 0, built.stderr);\n+\t\tfor (const directory of [\"bin\", \"dist\"])\n+\t\t\tassert.equal(existsSync(join(output, \"abso\", directory, \"stale.js\")), false);\n+\t\tconst packaged = JSON.parse(readFileSync(join(output, \"abso/package.json\"), \"utf8\"));\n+\t\tconst canonical = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\"));\n+\t\tassert.equal(packaged.engines.node, canonical.engines.node);\n+\t\tconst minimumNode = Number(canonical.engines.node.match(/^>=([1-9][0-9]*)$/)?.[1]);\n+\t\tassert.equal(minimumNode, 24);\n+\t\tassert.match(readFileSync(join(output, \"abso/README.md\"), \"utf8\"), /Requires Node 24 or later/);\n+\t\tconst bin = readFileSync(join(output, \"abso/bin/abso.mjs\"), \"utf8\");\n+\t\tlet error = \"\";\n+\t\tconst exited = new Error(\"old Node exited before loading the bundle\");\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\trunInNewContext(bin, {\n+\t\t\t\t\tprocess: {\n+\t\t\t\t\t\tversions: { node: \"23.0.0\" },\n+\t\t\t\t\t\tstderr: {\n+\t\t\t\t\t\t\twrite: (text: string) => {\n+\t\t\t\t\t\t\t\terror += text;\n+\t\t\t\t\t\t\t},\n+\t\t\t\t\t\t},\n+\t\t\t\t\t\texit: (code: number) => {\n+\t\t\t\t\t\t\tassert.equal(code, 1);\n+\t\t\t\t\t\t\tthrow exited;\n+\t\t\t\t\t\t},\n+\t\t\t\t\t},\n+\t\t\t\t}),\n+\t\t\t(value) => value === exited,\n+\t\t);\n+\t\tassert.match(error, /abso needs Node 24 or later, and this is Node 23\\.0\\.0/);\n+\t\tassert.equal(existsSync(join(output, \"abso/dist/abso.mjs\")), true);\n+\t\tassert.throws(() => preparePackageDirectory(root, root), /inside this checkout/);\n+\t} finally {\n+\t\t// output is the mkdtemp directory immediately under this checkout's generated dist folder.\n+\t\trmSync(output, { recursive: true, force: true });\n+\t}\n+});\n+\n+test(\"npm pipeline builds pushed shared versions and repacks the same version when green\", () => {\n+\tconst checked = readPipelineFile(readFileSync(new URL(\"../abso.yml\", import.meta.url), \"utf8\"), \"abso.yml\");\n+\tassert.ok(checked.ok, JSON.stringify(checked));\n+\tfor (const kind of [\"publish\", \"green\"] as const)\n+\t\tassert.equal(plan(checked.file, { kind, space: \"shared\" }).start[0]?.name, \"npm\");\n+\tassert.equal(plan(checked.file, { kind: \"publish\", space: \"feature\" }).start.length, 0);\n+\tassert.equal(plan(checked.file, { kind: \"draft\", space: \"shared\" }).start.length, 0);\n+\tconst pipeline = checked.file.pipelines[0]!;\n+\tconst publish = pipeline.jobs.find((job) => job.name === \"publish\")!;\n+\tassert.deepEqual(publish.needs, [\"pack\"]);\n+\tassert.equal(publish.from, \"npm.pack\");\n+\tassert.deepEqual(publish.with, { packages: [\"@abso-cli/abso\"], tag: \"latest\" });\n+\tassert.deepEqual(publish.secrets, []);\n+\tassert.equal(publish.abso, undefined);\n+});"}]}