UNPKG

@code-yeongyu/senpi

Version:

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

74 lines • 4.32 kB
/** Value accepted by the runtime pin environment variable. */ export type RuntimeName = "node" | "bun"; /** Environment variable that pins the runtime explicitly, bypassing detection. */ export declare const RUNTIME_ENV_VAR = "SENPI_RUNTIME"; /** Injected view of the world. Defaults read the real process, tests inject fakes. */ export interface BunRuntimeOptions { readonly env: NodeJS.ProcessEnv; readonly homedir: string; readonly platform: NodeJS.Platform; readonly exists: (path: string) => boolean; readonly realpath: (path: string) => string; /** `<bun> --version` output, or `undefined` when the binary cannot be run. */ readonly bunVersion: (bunPath: string) => string | undefined; } /** Oldest Bun release a non-Bun install is handed to; older releases miss runtime APIs senpi uses. */ export declare const MIN_BUN_VERSION = "1.4.0"; /** Why the process stayed on its current runtime. Surfaced for tests and diagnostics. */ export type StayReason = "already-bun" | "runtime-pinned-node" | "inspector" | "bun-not-found" | "bun-too-old" | "not-bun-install"; export type BunReexecDecision = { readonly action: "stay"; readonly reason: StayReason; } | { readonly action: "reexec"; readonly bunPath: string; }; export interface BunReexecInput { /** Real path (symlinks resolved) of the script this process was started with. */ readonly scriptRealPath: string; /** `process.versions`; a `bun` entry means this process already IS Bun. */ readonly versions: Readonly<Record<string, string | undefined>>; /** Whether this process inherited a `--inspect*` option. */ readonly hasInheritedInspectorOption: boolean; readonly options: BunRuntimeOptions; } /** * Report whether the executed script lives inside Bun's global install tree. * * The caller must pass an already-resolved real path: `~/.bun/bin/<name>` is a symlink, and the * link itself is not under `install/global/`, so an unresolved path never matches. The tree root * is compared both as configured and as resolved, so a symlinked install root still matches. */ export declare function isUnderBunGlobalTree(scriptRealPath: string, options: BunRuntimeOptions): boolean; /** * Report whether the executed script belongs to an installed package (npm, pnpm, yarn, npx, or a * project-local install), as opposed to a source checkout. Only installed packages are handed to a * discovered Bun: a checkout run on Node is a developer's deliberate choice. */ export declare function isInstalledPackageScript(scriptRealPath: string): boolean; /** True when `version` (e.g. `1.4.2`, `1.5.0-canary.3`) is at least {@link MIN_BUN_VERSION}. */ export declare function bunVersionSatisfies(version: string | undefined): boolean; /** * Locate a Bun binary: the configured install root first, then the default `~/.bun` root, then * a PATH scan. Returns `undefined` when Bun is not installed — a missing Bun is never an error, * the process simply stays on Node. */ export declare function findBunBinary(options: BunRuntimeOptions): string | undefined; /** * Decide whether this process should re-exec itself under Bun. First match wins: * * 1. already running Bun — never re-exec, that would loop forever; * 2. `SENPI_RUNTIME=node` — an explicit opt-out always wins; * 3. an inherited Inspector option — a debugger session owns a Node socket, keep it; * 4. `SENPI_RUNTIME=bun` with Bun installed — explicit opt-in; * 5. the script lives in Bun's global install tree with Bun installed — the install implies it; * 6. any other installed package with Bun >= {@link MIN_BUN_VERSION} — a machine that has a * current Bun runs senpi on it, whichever package manager installed it; * 7. otherwise stay (source checkouts, no Bun, or an older Bun). */ export declare function resolveBunReexec(input: BunReexecInput): BunReexecDecision; /** Run `<bun> --version`; any failure (missing, not executable, timeout) means "unknown". */ export declare function readBunVersion(bunPath: string): string | undefined; /** Build the default, process-backed options for the real CLI entry point. */ export declare function processBunRuntimeOptions(exists: (path: string) => boolean, realpath: (path: string) => string): BunRuntimeOptions; //# sourceMappingURL=bun-runtime.d.ts.map