feat(hermes): ship explicit public runtime setup

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-08 12:28:12 -05:00
1 parent af50ff553d
commit 51700ff8c6
16 files changed
+326 -55

No files matched your search

+16 -3
View File
@@ -3,17 +3,17 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { afterEach, expect, it } from "vitest";
import { resolveCursorProvisioner } from "../commands/runtime.js";
import { resolveCursorProvisioner, resolveHermesProvisioner } from "../commands/runtime.js";
const roots: string[] = [];
afterEach(async () => { await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true, force: true }))); });
async function fixture() {
async function fixture(provider = "cursor") {
const root = await realpath(await mkdtemp(join(tmpdir(), "cursor-public-setup-")));
roots.push(root);
await mkdir(join(root, "dist/vendor/paperclip-runner/cli"), { recursive: true });
await writeFile(join(root, "package.json"), JSON.stringify({ name: "@paperclipai/server" }));
await writeFile(join(root, "dist/index.js"), "throw new Error('must not import server');");
const provisioner = join(root, "dist/vendor/paperclip-runner/cli/provision-cursor.cjs");
const provisioner = join(root, `dist/vendor/paperclip-runner/cli/provision-${provider}.cjs`);
await writeFile(provisioner, "fixture");
return { root, provisioner, url: pathToFileURL(join(root, "dist/index.js")).href };
}
@@ -36,3 +36,16 @@ it("rejects a provisioner linked outside the installed package", async () => {
await rm(f.provisioner); await symlink(other.provisioner, f.provisioner);
await expect(resolveCursorProvisioner(f.url)).rejects.toThrow("escapes");
});
it("resolves Hermes from the published server without starting it", async () => {
const f = await fixture("hermes");
expect(await resolveHermesProvisioner(f.url)).toBe(f.provisioner);
});
it("Hermes rejects foreign package identities and linked setup code", async () => {
const f = await fixture("hermes"); const other = await fixture("hermes");
await rm(f.provisioner); await symlink(other.provisioner, f.provisioner);
await expect(resolveHermesProvisioner(f.url)).rejects.toThrow("escapes");
await writeFile(join(f.root, "package.json"), JSON.stringify({ name: "untrusted" }));
await expect(resolveHermesProvisioner(f.url)).rejects.toThrow("identity is invalid");
});
+20 -12
View File
@@ -5,22 +5,27 @@ import { fileURLToPath } from "node:url";
import type { Command } from "commander";
/** Resolve the installed public dependency without importing or starting it. */
export async function resolveCursorProvisioner(serverUrl: string): Promise<string> {
async function resolveRuntimeProvisioner(serverUrl: string, provider: "cursor" | "hermes"): Promise<string> {
const label = provider === "hermes" ? "Hermes" : "Cursor";
const url = new URL(serverUrl);
if (url.protocol !== "file:" || url.search || url.hash) throw new Error("Cursor setup requires an installed Paperclip server");
if (url.protocol !== "file:" || url.search || url.hash) throw new Error(`${label} setup requires an installed Paperclip server`);
const entry = await realpath(fileURLToPath(url));
if (!entry.endsWith("/dist/index.js")) throw new Error("Cursor setup requires the published server layout");
if (!entry.endsWith("/dist/index.js")) throw new Error(`${label} setup requires the published server layout`);
const root = resolve(dirname(entry), "..");
const manifest = join(root, "package.json");
const info = await lstat(manifest);
if (!info.isFile() || info.isSymbolicLink() || info.size > 65536 || JSON.parse(await readFile(manifest, "utf8")).name !== "@paperclipai/server") throw new Error("Cursor setup server package identity is invalid");
const provisioner = join(root, "dist/vendor/paperclip-runner/cli/provision-cursor.cjs");
if (await realpath(provisioner) !== provisioner || !(await lstat(provisioner)).isFile()) throw new Error("Cursor setup entrypoint escapes its server package");
if (!info.isFile() || info.isSymbolicLink() || info.size > 65536 || JSON.parse(await readFile(manifest, "utf8")).name !== "@paperclipai/server") throw new Error(`${label} setup server package identity is invalid`);
const provisioner = join(root, `dist/vendor/paperclip-runner/cli/provision-${provider}.cjs`);
if (await realpath(provisioner) !== provisioner || !(await lstat(provisioner)).isFile()) throw new Error(`${label} setup entrypoint escapes its server package`);
return provisioner;
}
export async function setupCursorRuntime(): Promise<void> {
const provisioner = await resolveCursorProvisioner(import.meta.resolve("@paperclipai/server"));
export const resolveCursorProvisioner = (serverUrl: string) => resolveRuntimeProvisioner(serverUrl, "cursor");
export const resolveHermesProvisioner = (serverUrl: string) => resolveRuntimeProvisioner(serverUrl, "hermes");
async function setupRuntime(provider: "cursor" | "hermes"): Promise<void> {
const label = provider === "hermes" ? "Hermes" : "Cursor";
const provisioner = await resolveRuntimeProvisioner(import.meta.resolve("@paperclipai/server"), provider);
const child = spawn(process.execPath, [provisioner], {
stdio: "inherit", env: { PATH: process.env.PATH ?? "/usr/bin:/bin", LANG: "C.UTF-8" },
});
@@ -32,19 +37,22 @@ export async function setupCursorRuntime(): Promise<void> {
child.on("error", error => { spawnError = error; });
child.once("close", (code, signal) => {
if (spawnError) reject(spawnError);
else if (code !== 0 || signal) reject(new Error("Cursor setup did not finish. Review its error; an invalid installation is never replaced automatically."));
else if (code !== 0 || signal) reject(new Error(`${label} setup did not finish. Review its error; an invalid installation is never replaced automatically.`));
else accept();
});
});
} finally { process.off("SIGINT", cancel); process.off("SIGTERM", cancel); }
}
export const setupCursorRuntime = () => setupRuntime("cursor");
export const setupHermesRuntime = () => setupRuntime("hermes");
export function registerRuntimeCommands(program: Command): void {
program.command("runtime").description("Manage explicitly installed agent runtimes")
.command("setup <provider>")
.description("Install and verify the pinned Cursor runtime for this host (public downloads; no model calls)")
.description("Install and verify a pinned Cursor or Hermes runtime for this host (public downloads; no model calls)")
.action(async (provider: string) => {
if (provider !== "cursor") throw new Error("Supported runtime setup: paperclipai runtime setup cursor");
await setupCursorRuntime();
if (provider !== "cursor" && provider !== "hermes") throw new Error("Supported runtime setup: paperclipai runtime setup <cursor|hermes>");
await setupRuntime(provider);
});
}