#!/usr/bin/env node // Imports only node builtins: A top-level import resolves before the gate below runs, so an // unresolvable dependency would replace this file's build-first message with ERR_MODULE_NOT_FOUND. import { existsSync } from 'node:fs'; // See packages/agents/README.md ("Bin wrapper pattern") for why this indirection exists. const entryPoint = new URL('../dist/esm/cli/index.js', import.meta.url); // Gate on the entry file itself: Because Node raises ERR_MODULE_NOT_FOUND for any // unresolved module in the graph, keying the build-first message off the error code // would also fire when the build is present and one of its imports is missing. if (!existsSync(entryPoint)) { process.stderr.write( 'kb: build output not found. In a source checkout, run `pnpm run bootstrap`; otherwise reinstall the package.\n', ); process.exit(1); } try { await import(entryPoint.href); } catch (error) { // eslint-disable-next-line no-restricted-syntax -- The shared helper is not a builtin; see the import note above. const message = error instanceof Error ? error.message : String(error); process.stderr.write(`kb: failed to load: ${message}\n`); process.exit(1); }