#!/usr/bin/env node
/**
 * madarX OS CLI entry point (package.json "bin": { "madarx": ... }).
 *
 * Thin shell: hand off to the subcommand router. Commands that need the data
 * home (run, and later setup/doctor/update) call applyHomeEnv() themselves, so
 * read-only commands like `version`/`help` stay instant and never create
 * ~/.madarx as a side effect. The supervisor process never opens the DB.
 */

import { dispatch } from '../lib/cli/dispatch.js';

const argv = process.argv.slice(2);
dispatch(argv)
  .then((code) => { if (typeof code === 'number' && code !== 0) process.exitCode = code; })
  .catch((err) => {
    console.error(`[madarx] ${err?.stack || err}`);
    process.exitCode = 1;
  });
