/**
 * # cli/bin — the executable entry (Kestrel CLI v1 §4)
 *
 * A tiny shim: import the router lazily so the file itself carries no heavy load, run `main` over
 * `process.argv.slice(2)`, and `process.exit` with its resolved code. Built to `dist/cli.js` with a
 * `#!/usr/bin/env node` banner (`bun build --target=node`), so it runs under plain node; LIGHT
 * commands need no bun/chdb, HEAVY verbs fault loud (exit 4) via `loadHeavy`. The PUBLISHED bin is
 * `bin/kestrel.cjs` (kestrel-mkn), which loads this file in-process for LIGHT verbs and re-execs
 * it under a discovered bun binary for HEAVY verbs.
 */

import { main } from "./index.ts";

main(process.argv.slice(2)).then(
  (code) => process.exit(code),
  (err) => {
    // Backstop (fail-closed): `main` is designed to ALWAYS RESOLVE with a nonzero code on error — it
    // renders every failure through `fail`. A REJECTION reaching here means a throw escaped its guards;
    // never let that exit 0 or dump a raw stack. stdout stays a clean payload channel — the reason goes
    // to stderr as the same machine-parseable skin, exit 1 (GENERIC).
    process.stderr.write(`error\tcode=GENERIC\tmessage=${err instanceof Error ? err.message : String(err)}\n`);
    process.exit(1);
  },
);
