Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): prepare public canary artifacts (#1950)

OwenKephart760c14a3606f
diff --git a/.changeset/publish-main-canaries.md b/.changeset/publish-main-canaries.md
new file mode 100644
index 000000000..24f062f58
--- /dev/null
+++ b/.changeset/publish-main-canaries.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Allow canary builds to scaffold projects pinned to their exact package artifact URL.
diff --git a/apps/package-artifacts/README.md b/apps/package-artifacts/README.md
new file mode 100644
index 000000000..5baeb01ef
--- /dev/null
+++ b/apps/package-artifacts/README.md
@@ -0,0 +1,28 @@
+# eve package artifacts
+
+Git-linked Vercel project that builds an eve tarball from each `vercel/eve` `main` commit and uploads immutable SHA-addressed package and manifest artifacts to public Vercel Blob using deployment OIDC.
+
+```text
+/main/eve.tgz
+/main/latest.json
+/<full-sha>/eve.tgz
+```
+
+Set `EVE_PACKAGE_BASE_URL` in Production to the project's public HTTPS origin, without a route suffix. For example, if it is `https://packages.example.com`, initialize an agent from the current `main` build with:
+
+```bash
+npm exec --yes --package=https://packages.example.com/main/eve.tgz -- eve init my-agent
+```
+
+The production deployment resolves `main` to its checked-out commit. Its `latest.json` exposes metadata for that package, including the source SHA, immutable Blob URL, and checksum. The packaged CLI stamps its immutable commit URL into generated projects, so a project created through the moving `main` URL remains pinned to the package used to create it.
+
+The Vercel project must:
+
+- use this directory as its project root;
+- deploy `main` to Production;
+- connect a public Blob store to Production;
+- set `EVE_PACKAGE_BASE_URL` to its public production origin;
+- omit `BLOB_READ_WRITE_TOKEN` so Blob writes use Vercel OIDC; and
+- disable Deployment Protection so npm can reach the production origin anonymously.
+
+Only production builds of `main` publish artifacts. Other builds produce a placeholder deployment; configure the project's Ignored Build Step as `test "$VERCEL_GIT_COMMIT_REF" != "main"` to skip non-`main` deployments before install and build. The smoke check verifies public access and the downloaded artifact's gzip signature.
diff --git a/apps/package-artifacts/api/package.js b/apps/package-artifacts/api/package.js
new file mode 100644
index 000000000..75694c1e9
--- /dev/null
+++ b/apps/package-artifacts/api/package.js
@@ -0,0 +1,49 @@
+import { get } from "@vercel/blob";
+
+import { SHA_PATTERN, packageManifestPath } from "../lib/package.mjs";
+
+export default async function handler(request, response) {
+ const ref = request.query.ref;
+ if (typeof ref !== "string" || (ref !== "main" && !SHA_PATTERN.test(ref))) {
+ return packageNotFound(response);
+ }
+
+ // Resolve `main` to the commit represented by the current production deployment.
+ const sourceSha = ref === "main" ? process.env.VERCEL_GIT_COMMIT_SHA : ref;
+ if (!SHA_PATTERN.test(sourceSha ?? "")) {
+ return packageNotFound(response);
+ }
+
+ const manifest = await resolveManifest(sourceSha);
+ if (manifest === undefined) return packageNotFound(response);
+
+ response.setHeader(
+ "Cache-Control",
+ ref === "main" ? "public, max-age=60" : "public, max-age=31536000, immutable",
+ );
+ if (request.query.manifest === "1") {
+ if (ref !== "main") return packageNotFound(response);
+ return response.status(200).json(manifest);
+ }
+ return response.redirect(302, manifest.tarball);
+}
+
+function packageNotFound(response) {
+ return response.status(404).send("Package not found.\n");
+}
+
+async function resolveManifest(sourceSha) {
+ const result = await get(packageManifestPath(sourceSha), { access: "public", useCache: false });
+ if (result === null) return undefined;
+
+ const manifest = JSON.parse(await new Response(result.stream).text());
+ if (
+ manifest.sourceSha !== sourceSha ||
+ typeof manifest.version !== "string" ||
+ typeof manifest.tarball !== "string" ||
+ typeof manifest.sha256 !== "string"
+ ) {
+ return undefined;
+ }
+ return manifest;
+}
diff --git a/apps/package-artifacts/api/package.test.mjs b/apps/package-artifacts/api/package.test.mjs
new file mode 100644
index 000000000..7f9db6508
--- /dev/null
+++ b/apps/package-artifacts/api/package.test.mjs
@@ -0,0 +1,79 @@
+import { beforeEach, describe, expect, test, vi } from "vitest";
+
+const get = vi.fn();
+vi.mock("@vercel/blob", () => ({ get }));
+
+const { default: handler } = await import("./package.js");
+const sha = "a".repeat(40);
+const manifest = {
+ sourceSha: sha,
+ version: `0.33.1-main.${sha}`,
+ tarball: "https://example.public.blob.vercel-storage.com/eve.tgz",
+ sha256: "b".repeat(64),
+};
+
+function response() {
+ return {
+ status: vi.fn().mockReturnThis(),
+ send: vi.fn().mockReturnThis(),
+ json: vi.fn().mockReturnThis(),
+ redirect: vi.fn().mockReturnThis(),
+ setHeader: vi.fn(),
+ };
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ process.env.VERCEL_GIT_COMMIT_SHA = sha;
+ get.mockImplementation(async () => ({
+ stream: new Blob([JSON.stringify(manifest)]).stream(),
+ }));
+});
+
+describe("package route", () => {
+ test("resolves main through the deployment commit", async () => {
+ const res = response();
+ await handler({ query: { ref: "main" } }, res);
+
+ expect(get).toHaveBeenCalledWith(`packages/${sha}/manifest.json`, {
+ access: "public",
+ useCache: false,
+ });
+ expect(res.setHeader).toHaveBeenCalledWith("Cache-Control", "public, max-age=60");
+ expect(res.redirect).toHaveBeenCalledWith(302, manifest.tarball);
+ });
+
+ test("serves the current main manifest", async () => {
+ const res = response();
+ await handler({ query: { ref: "main", manifest: "1" } }, res);
+
+ expect(res.status).toHaveBeenCalledWith(200);
+ expect(res.json).toHaveBeenCalledWith(manifest);
+ });
+
+ test("serves SHA tarballs but not SHA latest manifests", async () => {
+ const artifact = response();
+ await handler({ query: { ref: sha } }, artifact);
+ expect(artifact.setHeader).toHaveBeenCalledWith(
+ "Cache-Control",
+ "public, max-age=31536000, immutable",
+ );
+ expect(artifact.redirect).toHaveBeenCalledWith(302, manifest.tarball);
+
+ const latest = response();
+ await handler({ query: { ref: sha, manifest: "1" } }, latest);
+ expect(latest.status).toHaveBeenCalledWith(404);
+ });
+
+ test("rejects unsupported refs and missing artifacts", async () => {
+ const invalid = response();
+ await handler({ query: { ref: "feature/test" } }, invalid);
+ expect(invalid.status).toHaveBeenCalledWith(404);
+ expect(get).not.toHaveBeenCalled();
+
+ get.mockResolvedValueOnce(null);
+ const missing = response();
+ await handler({ query: { ref: sha } }, missing);
+ expect(missing.status).toHaveBeenCalledWith(404);
+ });
+});
diff --git a/apps/package-artifacts/lib/package.mjs b/apps/package-artifacts/lib/package.mjs
new file mode 100644
index 000000000..8416c1ab9
--- /dev/null
+++ b/apps/package-artifacts/lib/package.mjs
@@ -0,0 +1,27 @@
+export const SHA_PATTERN = /^[0-9a-f]{40}$/i;
+
+export function packageArtifactPath(sourceSha) {
+ return `packages/${sourceSha}/eve.tgz`;
+}
+
+export function packageManifestPath(sourceSha) {
+ return `packages/${sourceSha}/manifest.json`;
+}
+
+export function packageDependencyUrl(baseUrl, sourceSha) {
+ const url = new URL(baseUrl);
+ if (url.protocol !== "https:") throw new Error("EVE_PACKAGE_BASE_URL must use HTTPS.");
+ url.pathname = `${url.pathname.replace(/\/$/, "")}/${sourceSha}/eve.tgz`;
+ return url.toString();
+}
+
+export function packageVersion(stableVersion, sourceSha) {
+ const match = stableVersion.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/);
+ if (match === null) throw new Error(`Expected a stable eve version, received ${stableVersion}.`);
+ const [, major, minor, patch] = match;
+ return `${major}.${minor}.${Number(patch) + 1}-main.${sourceSha}`;
+}
+
+export function preparePackageJson(packageJson, sourceSha) {
+ return { ...packageJson, version: packageVersion(packageJson.version, sourceSha) };
+}
diff --git a/apps/package-artifacts/lib/package.test.mjs b/apps/package-artifacts/lib/package.test.mjs
new file mode 100644
index 000000000..319e91c0a
--- /dev/null
+++ b/apps/package-artifacts/lib/package.test.mjs
@@ -0,0 +1,42 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ packageArtifactPath,
+ packageDependencyUrl,
+ packageManifestPath,
+ packageVersion,
+ preparePackageJson,
+} from "./package.mjs";
+
+const sha = "a".repeat(40);
+
+describe("package artifacts", () => {
+ test("derives the next patch main version", () => {
+ expect(packageVersion("0.33.0", sha)).toBe(`0.33.1-main.${sha}`);
+ });
+
+ test("derives immutable artifact and dependency URLs", () => {
+ expect(packageArtifactPath(sha)).toBe(`packages/${sha}/eve.tgz`);
+ expect(packageManifestPath(sha)).toBe(`packages/${sha}/manifest.json`);
+ expect(packageDependencyUrl("https://packages.example.com", sha)).toBe(
+ `https://packages.example.com/${sha}/eve.tgz`,
+ );
+ });
+
+ test("requires an HTTPS package base URL", () => {
+ expect(() => packageDependencyUrl("http://packages.example.com", sha)).toThrow("use HTTPS");
+ });
+
+ test("prepares package metadata without mutating the source", () => {
+ const source = { name: "eve", version: "0.33.0" };
+ expect(preparePackageJson(source, sha)).toEqual({
+ name: "eve",
+ version: `0.33.1-main.${sha}`,
+ });
+ expect(source.version).toBe("0.33.0");
+ });
+
+ test("rejects non-stable source versions", () => {
+ expect(() => packageVersion("0.33.1-main.1", sha)).toThrow("Expected a stable eve version");
+ });
+});
diff --git a/apps/package-artifacts/package.json b/apps/package-artifacts/package.json
new file mode 100644
index 000000000..bae5f96e9
--- /dev/null
+++ b/apps/package-artifacts/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "eve-package-artifacts",
+ "version": "0.0.0",
+ "private": true,
+ "type": "module",
+ "scripts": {
+ "build": "node scripts/build.mjs",
+ "test": "vitest run --config vitest.config.ts",
+ "test:smoke": "node scripts/check-smoke.mjs"
+ },
+ "dependencies": {
+ "@vercel/blob": "2.4.0"
+ },
+ "devDependencies": {
+ "vitest": "catalog:"
+ }
+}
diff --git a/apps/package-artifacts/scripts/build.mjs b/apps/package-artifacts/scripts/build.mjs
new file mode 100644
index 000000000..385b2a168
--- /dev/null
+++ b/apps/package-artifacts/scripts/build.mjs
@@ -0,0 +1,113 @@
+import { execFile as execFileCallback } from "node:child_process";
+import { createHash } from "node:crypto";
+import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { promisify } from "node:util";
+
+import { get, head, put } from "@vercel/blob";
+
+import {
+ SHA_PATTERN,
+ packageArtifactPath,
+ packageDependencyUrl,
+ packageManifestPath,
+ preparePackageJson,
+} from "../lib/package.mjs";
+
+const execFile = promisify(execFileCallback);
+const appRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
+const repoRoot = resolve(appRoot, "../..");
+const packageRoot = join(repoRoot, "packages/eve");
+const packageJsonPath = join(packageRoot, "package.json");
+const artifactDirectory = join(appRoot, ".artifacts");
+const sourceSha = process.env.VERCEL_GIT_COMMIT_SHA;
+const branch = process.env.VERCEL_GIT_COMMIT_REF;
+const baseUrl = process.env.EVE_PACKAGE_BASE_URL;
+
+if (!SHA_PATTERN.test(sourceSha ?? "")) {
+ throw new Error("VERCEL_GIT_COMMIT_SHA must be a 40-character Git commit SHA.");
+}
+if (branch !== "main" || process.env.VERCEL_ENV !== "production") {
+ await mkdir(join(appRoot, "public"), { recursive: true });
+ await writeFile(
+ join(appRoot, "public/index.html"),
+ "<!doctype html><title>eve packages</title><p>Artifacts are only published from main.</p>\n",
+ );
+ process.exit(0);
+}
+
+if (typeof baseUrl !== "string" || baseUrl.length === 0) {
+ throw new Error("EVE_PACKAGE_BASE_URL is required for package publishing.");
+}
+
+const originalPackageJson = await readFile(packageJsonPath, "utf8");
+const preparedPackageJson = preparePackageJson(JSON.parse(originalPackageJson), sourceSha);
+const version = preparedPackageJson.version;
+// Generated projects pin this deployment's immutable SHA route, never the moving main route.
+const dependencyUrl = packageDependencyUrl(baseUrl, sourceSha);
+const artifactPath = packageArtifactPath(sourceSha);
+
+try {
+ await rm(artifactDirectory, { force: true, recursive: true });
+ await writeFile(packageJsonPath, `${JSON.stringify(preparedPackageJson, null, 2)}\n`);
+ await execFile("pnpm", ["--dir", packageRoot, "pack", "--pack-destination", artifactDirectory], {
+ cwd: repoRoot,
+ env: { ...process.env, EVE_MAIN_DEPENDENCY_URL: dependencyUrl },
+ });
+
+ const tarball = await readFile(join(artifactDirectory, `eve-${version}.tgz`));
+ const sha256 = createHash("sha256").update(tarball).digest("hex");
+ let artifact;
+ try {
+ artifact = await put(artifactPath, tarball, {
+ access: "public",
+ addRandomSuffix: false,
+ allowOverwrite: false,
+ cacheControlMaxAge: 31_536_000,
+ contentType: "application/gzip",
+ });
+ } catch (error) {
+ // Redeploys are valid only when this commit still produces identical package bytes.
+ if (!(error instanceof Error) || !error.message.includes("already exists")) throw error;
+ artifact = await head(artifactPath);
+ const publishedTarball = await fetch(artifact.url);
+ if (!publishedTarball.ok) {
+ throw new Error(`Published package artifact returned ${publishedTarball.status}.`);
+ }
+ const publishedSha256 = createHash("sha256")
+ .update(Buffer.from(await publishedTarball.arrayBuffer()))
+ .digest("hex");
+ if (publishedSha256 !== sha256) {
+ throw new Error(`Commit ${sourceSha} was already published with different package contents.`);
+ }
+ }
+
+ const manifest = { sourceSha, version, tarball: artifact.url, sha256 };
+ const manifestPath = packageManifestPath(sourceSha);
+ const existingManifest = await get(manifestPath, { access: "public", useCache: false });
+ if (existingManifest === null) {
+ await put(manifestPath, JSON.stringify(manifest), {
+ access: "public",
+ addRandomSuffix: false,
+ allowOverwrite: false,
+ cacheControlMaxAge: 31_536_000,
+ contentType: "application/json",
+ });
+ } else {
+ const published = JSON.parse(await new Response(existingManifest.stream).text());
+ if (published.sha256 !== sha256) {
+ throw new Error(`Commit ${sourceSha} was already published with different package contents.`);
+ }
+ }
+
+ await mkdir(join(appRoot, "public"), { recursive: true });
+ await writeFile(
+ join(appRoot, "public/index.html"),
+ `<!doctype html><title>eve packages</title><pre>${JSON.stringify(manifest, null, 2)}</pre>\n`,
+ );
+ process.stdout.write(`${JSON.stringify(manifest)}\n`);
+} finally {
+ await writeFile(packageJsonPath, originalPackageJson);
+ await rm(artifactDirectory, { force: true, recursive: true });
+}
diff --git a/apps/package-artifacts/scripts/check-smoke.mjs b/apps/package-artifacts/scripts/check-smoke.mjs
new file mode 100644
index 000000000..83554c19b
--- /dev/null
+++ b/apps/package-artifacts/scripts/check-smoke.mjs
@@ -0,0 +1,20 @@
+const origin = process.env.DEPLOYMENT_URL;
+if (!origin) throw new Error("DEPLOYMENT_URL is required.");
+
+const artifact = await fetch(`${origin.replace(/\/$/, "")}/main/eve.tgz`, { redirect: "manual" });
+const location = artifact.headers.get("location") ?? "";
+if (
+ location.includes("vercel.com/login") ||
+ location.includes("vercel.com/sso-api") ||
+ location.includes("/_vercel/login")
+) {
+ throw new Error("Package deployment is protected; disable Deployment Protection.");
+}
+if (artifact.status !== 302) throw new Error(`/main/eve.tgz returned ${artifact.status}.`);
+
+const tarball = await fetch(location);
+if (!tarball.ok) throw new Error(`Package artifact returned ${tarball.status}.`);
+const signature = new Uint8Array(await tarball.arrayBuffer()).subarray(0, 2);
+if (signature[0] !== 0x1f || signature[1] !== 0x8b) {
+ throw new Error("Package artifact is not a gzip tarball.");
+}
diff --git a/apps/package-artifacts/vercel.json b/apps/package-artifacts/vercel.json
new file mode 100644
index 000000000..0fce886a5
--- /dev/null
+++ b/apps/package-artifacts/vercel.json
@@ -0,0 +1,13 @@
+{
+ "$schema": "https://openapi.vercel.sh/vercel.json",
+ "buildCommand": "pnpm --filter eve-package-artifacts build",
+ "installCommand": "pnpm install --frozen-lockfile",
+ "outputDirectory": "public",
+ "rewrites": [
+ { "source": "/:ref*/eve.tgz", "destination": "/api/package?ref=:ref" },
+ {
+ "source": "/main/latest.json",
+ "destination": "/api/package?ref=main&manifest=1"
+ }
+ ]
+}
diff --git a/apps/package-artifacts/vitest.config.ts b/apps/package-artifacts/vitest.config.ts
new file mode 100644
index 000000000..9e0439707
--- /dev/null
+++ b/apps/package-artifacts/vitest.config.ts
@@ -0,0 +1,3 @@
+import { defineConfig } from "vitest/config";
+
+export default defineConfig({ test: { include: ["{api,lib}/**/*.test.mjs"] } });
diff --git a/packages/eve/scripts/stamp-version-tokens.mjs b/packages/eve/scripts/stamp-version-tokens.mjs
index 36d7aa09d..5ff4e652b 100644
--- a/packages/eve/scripts/stamp-version-tokens.mjs
+++ b/packages/eve/scripts/stamp-version-tokens.mjs
@@ -39,8 +39,11 @@ if (typeof nodeEngine !== "string") {
throw new Error("eve package.json is missing a string engines.node");
}
+const evePackageDependencyVersion = process.env.EVE_MAIN_DEPENDENCY_URL ?? packageJson.version;
+
const replacements = {
__EVE_PACKAGE_VERSION__: packageJson.version,
+ __EVE_PACKAGE_DEPENDENCY_VERSION__: evePackageDependencyVersion,
__NODE_ENGINE__: nodeEngine,
__AI_SDK_VERSION__: await resolveCatalogVersion("ai"),
__BETTER_AUTH_VERSION__: await resolveCatalogVersion("better-auth"),
diff --git a/packages/eve/src/setup/scaffold/create/project.ts b/packages/eve/src/setup/scaffold/create/project.ts
index bad0ddfbe..cff5967e8 100644
--- a/packages/eve/src/setup/scaffold/create/project.ts
+++ b/packages/eve/src/setup/scaffold/create/project.ts
@@ -37,7 +37,7 @@ export interface EvePackageContract {
}
export const DEFAULT_EVE_PACKAGE_CONTRACT: EvePackageContract = {
- version: "__EVE_PACKAGE_VERSION__",
+ version: "__EVE_PACKAGE_DEPENDENCY_VERSION__",
nodeEngine: "__NODE_ENGINE__",
};
diff --git a/packages/eve/src/setup/scaffold/version-tokens.test.ts b/packages/eve/src/setup/scaffold/version-tokens.test.ts
index da700ca7e..c6ddd9870 100644
--- a/packages/eve/src/setup/scaffold/version-tokens.test.ts
+++ b/packages/eve/src/setup/scaffold/version-tokens.test.ts
@@ -25,13 +25,21 @@ describe("resolveVersionToken", () => {
expect(manifest).toContain(`"@vercel/connect": "${resolved}"`);
});
- it("resolves the eve version token from eve's own package.json", () => {
- const resolved = resolveVersionToken("evePackage.version", "__EVE_PACKAGE_VERSION__");
+ it("resolves eve runtime and dependency version tokens from eve's own package.json", () => {
+ const runtimeVersion = resolveVersionToken(
+ "evePackage.runtimeVersion",
+ "__EVE_PACKAGE_VERSION__",
+ );
+ const dependencyVersion = resolveVersionToken(
+ "evePackage.version",
+ "__EVE_PACKAGE_DEPENDENCY_VERSION__",
+ );
const packageJson = JSON.parse(readFileSync(fileURLToPath(EVE_PACKAGE_JSON_URL), "utf8")) as {
version: string;
};
- expect(resolved).toBe(packageJson.version);
+ expect(runtimeVersion).toBe(packageJson.version);
+ expect(dependencyVersion).toBe(packageJson.version);
});
it("resolves the node engine token from eve's own package.json engines.node", () => {
diff --git a/packages/eve/src/setup/scaffold/version-tokens.ts b/packages/eve/src/setup/scaffold/version-tokens.ts
index 0cb46eb55..59e2494cc 100644
--- a/packages/eve/src/setup/scaffold/version-tokens.ts
+++ b/packages/eve/src/setup/scaffold/version-tokens.ts
@@ -30,6 +30,7 @@ const NODE_ENGINE_TOKEN = bareToken("NODE_ENGINE");
const TOKEN_SOURCES: Readonly<Record<string, TokenSource>> = {
[versionToken("EVE_PACKAGE")]: { kind: "eve-version" },
+ [versionToken("EVE_PACKAGE_DEPENDENCY")]: { kind: "eve-version" },
[NODE_ENGINE_TOKEN]: { kind: "eve-node-engine" },
[versionToken("AI_SDK")]: { kind: "catalog", packageName: "ai" },
[versionToken("VERCEL_CONNECT")]: { kind: "catalog", packageName: "@vercel/connect" },
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index cba93a11f..681083bd0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -543,6 +543,16 @@ importers:
specifier: 'catalog:'
version: 25.9.1
+ apps/package-artifacts:
+ dependencies:
+ '@vercel/blob':
+ specifier: 2.4.0
+ version: 2.4.0
+ devDependencies:
+ vitest:
+ specifier: 'catalog:'
+
e2e/fixtures/agent-basic-runtime:
dependencies:
'@eve-e2e/config':