import { pathToFileURL } from "node:url";

import { runHatchCli } from "@owl-kestrel/hatch-runtime";

import { createTalonsHatchProductConfig } from "./talons-hatch-product.mjs";

/**
 * This is deliberately a product-owned command entrypoint, not a generic
 * updater. It imports Talons' bundled config and adapter directly; neither a
 * manifest nor a caller can select a module, policy, key, destination, or
 * command.
 */
export async function main(argv = process.argv.slice(2)) {
  try {
    return await runHatchCli({
      product: createTalonsHatchProductConfig(),
      argv,
    });
  } catch {
    // Keep the bundled product boundary fail-closed without exposing local
    // paths, package layout, or release-config contents to a caller.
    process.stderr.write(`${JSON.stringify({ ok: false, error: "Talons Hatch release authority is unavailable." })}\n`);
    return 1;
  }
}

if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
  process.exitCode = await main();
}
