Lines 31-71javascript
33 * 1. `$KESTREL_BUN` — an EXPLICIT operator pin. If it does not probe clean the launcher fails LOUD
34 * (exit 4) and NEVER substitutes another bun: silently re-execing onto a runtime other than the
35 * one an operator pinned would void exactly the pinned-Bun certification this re-exec preserves.
36 * 2. Every `bun` on `$PATH`, in order.
37 * 3. The bundled `bun` optionalDependency — its postinstall-materialized `bun/bin/bun.exe` FIRST,
38 * then the `@oven/bun-*` packages filtered by platform+arch+libc (non-baseline before baseline),
39 * because npm installs every wrong-libc/baseline variant and bun's postinstall MOVES the correct
41 * A candidate that fails the probe (or the exec) is SKIPPED and the next tried. `KESTREL_NO_BUNDLED_BUN=1`
42 * excludes the bundled package entirely — by REALPATH, so its `.bin/bun` symlink (which npx puts first
43 * on PATH) cannot smuggle it back in.
45 * Only when EVERY candidate fails does the launcher fall through in-process: the heavy verb then faults
46 * through `loadHeavy` into the existing loud exit-4 RUNTIME_UNAVAILABLE refusal, rendered in the
47 * caller's mode — never a raw stack.
52const { spawnSync } = require("node:child_process");
53const fs = require("node:fs");
MediumDynamic Require
Package source references dynamic require/import behavior.
bin/kestrel.cjsView on unpkg · L51 54const os = require("node:os");
55const path = require("node:path");
56const { pathToFileURL } = require("node:url");
58const CLI = path.join(__dirname, "..", "dist", "cli.js");
60/** The floor `package.json#engines.bun` promises. An older bun ships an older `bun:sqlite`. */
61const BUN_FLOOR = [1, 1, 0];
63// `sim` is LIGHT by construction (kestrel-585): it drives the hosted funnel over fetch only
64// (no bun:sqlite/chdb), so the site's hero snippet runs under plain node via npx.
65const LIGHT_VERBS = new Set(["version", "help", "parse", "validate", "print", "frame", "percept", "sim", "register"]);
66const HEAVY_VERBS = new Set(["run", "day", "runs", "lineage", "leaderboard", "agent"]);
67/** Global flags that CONSUME the next token — so `--api run` can never be misread as the `run` verb. */
68const VALUE_FLAGS = new Set(["--format", "--color", "--api"]);
71 * Scan argv in order; the FIRST known verb decides. Help/version flags anywhere force LIGHT (the