#!/usr/bin/env node
import {
  runCli
} from "../chunk-4U4CSRBE.js";
import {
  logger
} from "../chunk-K44MW7JJ.js";

// src/cli/index.ts
var MIN_HEAP_MB = 6144;
var DEFAULT_HEAP_MB = 8192;
function getCurrentHeapMB() {
  const arg = process.execArgv.find((a) => a.startsWith("--max-old-space-size="));
  if (arg) return Number.parseInt(arg.split("=")[1], 10);
  const m = (process.env["NODE_OPTIONS"] ?? "").match(/--max-old-space-size=(\d+)/);
  return m ? Number.parseInt(m[1], 10) : 0;
}
var currentHeap = getCurrentHeapMB();
if (currentHeap < MIN_HEAP_MB && !process.env["OPENFOX_HEAP_INCREASED"]) {
  const { spawnSync } = await import("child_process");
  const { totalmem } = await import("os");
  const heapMB = Math.min(DEFAULT_HEAP_MB, Math.max(4096, Math.floor(totalmem() / (1024 * 1024) * 0.55)));
  const env = { ...process.env, OPENFOX_HEAP_INCREASED: "1" };
  const cleanNodeOptions = (env["NODE_OPTIONS"] ?? "").replace(/--max-old-space-size=\d+/g, "").trim();
  env["NODE_OPTIONS"] = cleanNodeOptions || void 0;
  const scriptPath = process.argv[1];
  const result = spawnSync(
    process.execPath,
    ["--max-old-space-size=" + heapMB, ...process.execArgv, scriptPath, ...process.argv.slice(2)],
    { stdio: "inherit", env }
  );
  process.exit(result.status ?? 0);
}
var mode = process.env["OPENFOX_MODE"] ?? "production";
runCli({ mode }).catch((error) => {
  logger.error("CLI fatal error", { error: error instanceof Error ? error.message : String(error) });
  process.exit(1);
});
//# sourceMappingURL=index.js.map