import { existsSync } from "node:fs"; import { join } from "node:path"; import { spawnSync } from "node:child_process"; export function resolvePrimeRoot() { const npmRoot = spawnSync("npm", ["root", "--global"], { encoding: "utf8" }); const candidates = [ process.env.PRIME_AGENT_ROOT, npmRoot.status === 0 ? join(npmRoot.stdout.trim(), "prime-agent") : undefined, "/opt/homebrew/lib/node_modules/prime-agent", "/usr/local/lib/node_modules/prime-agent", "/usr/lib/node_modules/prime-agent", ]; const root = candidates.find((candidate) => candidate && existsSync(join(candidate, "dist/index.d.ts")) ); if (!root) { throw new Error("Prime Agent was not found; set PRIME_AGENT_ROOT to its package directory"); } return root; }