UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

104 lines • 4.73 kB
/** * The "running on Node.js" startup notice: when to show it and what it says. * * The only trigger is the runtime itself. Every install path that can run on Bun already * re-execs there (`bun-runtime.ts` for senpi, the OmO Native launcher for omo), so a process * still on Node here is one the user can fix: Bun is missing or too old, or the package was * installed by a manager that keeps it on Node. Everything in this file is pure; the * interactive mode supplies the facts through `runtime-notice-presenter.ts`. */ import { MIN_BUN_VERSION, RUNTIME_ENV_VAR } from "../../bun-runtime.js"; export const SKIP_RUNTIME_NOTICE_ENV_SUFFIX = "SKIP_RUNTIME_NOTICE"; /** * The variable that pins the runtime from the user's side. The OmO Native launcher always * forwards its own runtime as `SENPI_RUNTIME`, so under OmO Native only `OMO_RUNTIME` is the * user's choice; a forwarded `SENPI_RUNTIME=node` just means the launcher could not use Bun. */ export function runtimePinEnvName(env) { return env.OMO_NATIVE === "1" ? "OMO_RUNTIME" : RUNTIME_ENV_VAR; } export function runtimeNoticeSkipReason(gate) { if (gate.versions.bun !== undefined) return "bun-runtime"; if (gate.env[runtimePinEnvName(gate.env)] === "node") return "node-pinned"; if (gate.hasInheritedInspectorOption) return "inspector"; if (gate.skipRequested) return "skip-requested"; if (gate.shownVersion === gate.engineVersion) return "already-shown"; return undefined; } export function reinstallTarget(brand, packageName) { if (brand === undefined) return { packageName, installSpec: packageName, ignoreScripts: true }; const update = brand.update; // A brand without an update channel manages its own installs; there is no command to offer. if (update === undefined) return undefined; const installSpec = update.distTag === "latest" ? update.packageName : `${update.packageName}@${update.distTag}`; // Branded products may rely on their install script; senpi documents --ignore-scripts. return { packageName: update.packageName, installSpec, ignoreScripts: false }; } function uninstallCommand(method, packageName) { switch (method) { case "npm": return `npm uninstall -g ${packageName}`; case "pnpm": return `pnpm remove -g ${packageName}`; case "yarn": return `yarn global remove ${packageName}`; case "bun": case "bun-binary": case "unknown": return undefined; } } /** Clean reinstall: remove the Node-managed copy so PATH cannot keep resolving it, then add it with Bun. */ export function bunReinstallCommand(method, target) { const install = `bun add -g ${target.ignoreScripts ? "--ignore-scripts " : ""}${target.installSpec}`; const uninstall = uninstallCommand(method, target.packageName); return uninstall === undefined ? install : `${uninstall} && ${install}`; } export function installBunCommand(platform) { return platform === "win32" ? `powershell -c "irm bun.sh/install.ps1 | iex"` : "curl -fsSL https://bun.sh/install | bash"; } function bunStep(input) { switch (input.bun.kind) { case "missing": return { text: `Install Bun: ${installBunCommand(input.platform)}`, tone: "accent" }; case "outdated": return { text: `Upgrade Bun (found ${input.bun.version ?? "an unreadable version"}, needs ${MIN_BUN_VERSION}+): bun upgrade`, tone: "accent", }; case "ready": return undefined; } } function reinstallStep(input, afterBunStep) { const lead = afterBunStep ? "Then reinstall" : "Reinstall"; // A Bun-global install needs no reinstall: a current Bun takes it over on the next launch. if (input.installMethod === "bun" || input.target === undefined) { return { text: `${afterBunStep ? "Then restart" : "Restart"} ${input.appCommand}.`, tone: "accent" }; } return { text: `${lead} with Bun: ${bunReinstallCommand(input.installMethod, input.target)}`, tone: "accent" }; } export function buildRuntimeNotice(input) { const first = bunStep(input); const extra = [ ...(first === undefined ? [] : [first]), reinstallStep(input, first !== undefined), { text: `To stay on Node.js and hide this notice, set ${input.pinEnvName}=node.` }, ]; return { title: "Running on Node.js", tone: "warning", why: `${input.appName} is running on Node.js ${input.nodeVersion}. It starts faster and every feature works on Bun ${MIN_BUN_VERSION}+.`, extra, }; } //# sourceMappingURL=runtime-notice.js.map