mirror of
https://github.com/vercel-labs/agent-browser.git
synced 2026-11-22 18:01:20 +08:00
* Ship native binaries as per-platform packages - Publish each platform binary as an @agent-browser/cli-* optional dependency, so installs download only the host's binary - Link the global command to the native binary on first run when install scripts are blocked (npm 12, pnpm, bun), and in postinstall when they run - Release and CI publish the platform packages and test global installs with scripts blocked and allowed * fix: link the native binary on pnpm 12 and keep skills resolvable Three fixes on top of the per-platform packaging work. relinkPnpmShim compared the shim's cmd-shim-target marker to argv[1] with string equality. On pnpm 12 the marker keeps the ./ from the package's "./bin/agent-browser.js" and argv[1] does not, so the shim was never rewritten and every command still started Node. It now compares resolved paths, which also covers the pnpm 10 and 11 spellings. The launcher spawned the binary straight out of the platform package. npm hoists that package beside agent-browser, so skills.rs, chat.rs and upgrade.rs, which resolve their files by walking up from the executable, found nothing. It now materializes into agent-browser/bin first and runs from there. postinstall only linked when npm_config_global was set, which only npm does, so pnpm, yarn and bun never linked at install time. It now asks the invoking manager for its global bin directory and also considers the enclosing node_modules/.bin, which Yarn Classic links through. The probe is skipped for local installs so they do not pay a subprocess. The Windows shims are rewritten in a format npm's read-cmd-shim can parse, each file's own target is checked before it is replaced, and replacement is staged then renamed so a failure leaves the working launcher in place. Verified with real global installs on macOS and Linux: npm with scripts allowed and blocked, pnpm 11 and 12, and bun. Yarn could not be verified locally because it fails when an optionalDependency is unresolvable and the platform packages are unpublished. Windows is unverified. * fix(pnpm): link the shim to the binary in the package bin The pnpm branch wrote the platform package's own path into the shim, so once that package resolved, the binary ran from a directory with no skills/ above it. It now links the same materialized path the symlink and Windows branches already use. --------- Co-authored-by: Lahfir <70215676+lahfir@users.noreply.github.com>
148 lines
5.4 KiB
JavaScript
148 lines
5.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Syncs the version from package.json to all other config files.
|
|
* Run this script before building or releasing.
|
|
*/
|
|
|
|
import { execSync } from "child_process";
|
|
import { readdirSync, readFileSync, writeFileSync } from "fs";
|
|
import { dirname, join } from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const rootDir = join(__dirname, "..");
|
|
const cliDir = join(rootDir, "cli");
|
|
|
|
function nativePackageManifests() {
|
|
const scopeDir = join(rootDir, "packages", "@agent-browser");
|
|
return readdirSync(scopeDir)
|
|
.filter((name) => name.startsWith("cli-"))
|
|
.sort()
|
|
.map((name) => join(scopeDir, name, "package.json"));
|
|
}
|
|
|
|
// Read version from package.json (single source of truth)
|
|
const packageJson = JSON.parse(
|
|
readFileSync(join(rootDir, "package.json"), "utf-8")
|
|
);
|
|
const version = packageJson.version;
|
|
|
|
console.log(`Syncing version ${version} to all config files...`);
|
|
|
|
// Update Cargo.toml
|
|
const cargoTomlPath = join(cliDir, "Cargo.toml");
|
|
let cargoToml = readFileSync(cargoTomlPath, "utf-8");
|
|
const cargoVersionRegex = /^version\s*=\s*"[^"]*"/m;
|
|
const newCargoVersion = `version = "${version}"`;
|
|
|
|
let cargoTomlUpdated = false;
|
|
if (cargoVersionRegex.test(cargoToml)) {
|
|
const oldMatch = cargoToml.match(cargoVersionRegex)?.[0];
|
|
if (oldMatch !== newCargoVersion) {
|
|
cargoToml = cargoToml.replace(cargoVersionRegex, newCargoVersion);
|
|
writeFileSync(cargoTomlPath, cargoToml);
|
|
console.log(` Updated cli/Cargo.toml: ${oldMatch} -> ${newCargoVersion}`);
|
|
cargoTomlUpdated = true;
|
|
} else {
|
|
console.log(` cli/Cargo.toml already up to date`);
|
|
}
|
|
} else {
|
|
console.error(" Could not find version field in cli/Cargo.toml");
|
|
process.exit(1);
|
|
}
|
|
|
|
// Update packages/dashboard/package.json
|
|
const dashboardPkgPath = join(rootDir, "packages", "dashboard", "package.json");
|
|
const dashboardPkg = JSON.parse(readFileSync(dashboardPkgPath, "utf-8"));
|
|
if (dashboardPkg.version !== version) {
|
|
const oldVersion = dashboardPkg.version;
|
|
dashboardPkg.version = version;
|
|
writeFileSync(dashboardPkgPath, JSON.stringify(dashboardPkg, null, 2) + "\n");
|
|
console.log(` Updated packages/dashboard/package.json: ${oldVersion} -> ${version}`);
|
|
} else {
|
|
console.log(` packages/dashboard/package.json already up to date`);
|
|
}
|
|
|
|
// Update packages/@agent-browser/sandbox/package.json
|
|
const sandboxPkgPath = join(rootDir, "packages", "@agent-browser", "sandbox", "package.json");
|
|
const sandboxPkg = JSON.parse(readFileSync(sandboxPkgPath, "utf-8"));
|
|
if (sandboxPkg.version !== version) {
|
|
const oldVersion = sandboxPkg.version;
|
|
sandboxPkg.version = version;
|
|
writeFileSync(sandboxPkgPath, JSON.stringify(sandboxPkg, null, 2) + "\n");
|
|
console.log(` Updated packages/@agent-browser/sandbox/package.json: ${oldVersion} -> ${version}`);
|
|
} else {
|
|
console.log(` packages/@agent-browser/sandbox/package.json already up to date`);
|
|
}
|
|
|
|
// Update packages/@agent-browser/eve/package.json (version + workspace sandbox dependency)
|
|
const evePkgPath = join(rootDir, "packages", "@agent-browser", "eve", "package.json");
|
|
const evePkg = JSON.parse(readFileSync(evePkgPath, "utf-8"));
|
|
const eveSandboxDependency = "workspace:^";
|
|
if (evePkg.version !== version || evePkg.dependencies["@agent-browser/sandbox"] !== eveSandboxDependency) {
|
|
const oldVersion = evePkg.version;
|
|
evePkg.version = version;
|
|
evePkg.dependencies["@agent-browser/sandbox"] = eveSandboxDependency;
|
|
writeFileSync(evePkgPath, JSON.stringify(evePkg, null, 2) + "\n");
|
|
console.log(` Updated packages/@agent-browser/eve/package.json: ${oldVersion} -> ${version}`);
|
|
} else {
|
|
console.log(` packages/@agent-browser/eve/package.json already up to date`);
|
|
}
|
|
|
|
// Update packages/@agent-browser/cli-*/package.json (native binary packages)
|
|
for (const pkgPath of nativePackageManifests()) {
|
|
const relativePath = pkgPath.slice(rootDir.length + 1);
|
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
if (pkg.version !== version) {
|
|
const oldVersion = pkg.version;
|
|
pkg.version = version;
|
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
console.log(` Updated ${relativePath}: ${oldVersion} -> ${version}`);
|
|
} else {
|
|
console.log(` ${relativePath} already up to date`);
|
|
}
|
|
}
|
|
|
|
// Update package runtime version constant
|
|
const sandboxVersionPath = join(
|
|
rootDir,
|
|
"packages",
|
|
"@agent-browser",
|
|
"sandbox",
|
|
"src",
|
|
"version.ts",
|
|
);
|
|
const sandboxVersionSource = `export const AGENT_BROWSER_SANDBOX_VERSION = "${version}";\n`;
|
|
const currentSandboxVersionSource = readFileSync(sandboxVersionPath, "utf-8");
|
|
if (currentSandboxVersionSource !== sandboxVersionSource) {
|
|
writeFileSync(sandboxVersionPath, sandboxVersionSource);
|
|
console.log(` Updated packages/@agent-browser/sandbox/src/version.ts -> ${version}`);
|
|
} else {
|
|
console.log(` packages/@agent-browser/sandbox/src/version.ts already up to date`);
|
|
}
|
|
|
|
// Update Cargo.lock to match Cargo.toml
|
|
if (cargoTomlUpdated) {
|
|
try {
|
|
execSync("cargo update -p agent-browser --offline", {
|
|
cwd: cliDir,
|
|
stdio: "pipe",
|
|
});
|
|
console.log(` Updated cli/Cargo.lock`);
|
|
} catch {
|
|
// --offline may fail if package not in cache, try without it
|
|
try {
|
|
execSync("cargo update -p agent-browser", {
|
|
cwd: cliDir,
|
|
stdio: "pipe",
|
|
});
|
|
console.log(` Updated cli/Cargo.lock`);
|
|
} catch (e) {
|
|
console.error(` Warning: Could not update Cargo.lock: ${e.message}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log("Version sync complete.");
|