import {
  SHA256_INTEGRITY_PREFIX,
  computeDeterministicPackHash
} from "./chunk-HANJXVKW.js";
import {
  WU_OPTIONS,
  createWUParser,
  runCLI
} from "./chunk-2GXVIN57.js";

// src/pack-hash.ts
import { resolve } from "path";
var LOG_PREFIX = "[pack:hash]";
var DEFAULT_PACKS_ROOT = "packages/@lumenflow/packs";
function resolvePackRoot(options) {
  const { directPackRoot, packId, packsRoot } = options;
  if (directPackRoot) {
    return resolve(directPackRoot);
  }
  if (packId && packsRoot) {
    return resolve(packsRoot, packId);
  }
  return null;
}
async function computePackHash(options) {
  const { packRoot, hashExclusions } = options;
  const absolutePackRoot = resolve(packRoot);
  const hex = await computeDeterministicPackHash({
    packRoot: absolutePackRoot,
    exclusions: hashExclusions
  });
  return `${SHA256_INTEGRITY_PREFIX}${hex}`;
}
var PACK_HASH_OPTIONS = {
  packId: {
    name: "id",
    flags: "--id <packId>",
    description: "Pack ID to hash (resolves under --packs-root)"
  },
  packsRoot: {
    name: "packsRoot",
    flags: "--packs-root <dir>",
    description: `Root directory containing packs (default: "${DEFAULT_PACKS_ROOT}")`
  },
  packRoot: {
    name: "packRoot",
    flags: "--pack-root <dir>",
    description: "Direct path to pack directory (overrides --id and --packs-root)"
  }
};
async function main() {
  const opts = createWUParser({
    name: "pack-hash",
    description: "Compute integrity hash for a LumenFlow domain pack",
    options: [
      PACK_HASH_OPTIONS.packId,
      PACK_HASH_OPTIONS.packsRoot,
      PACK_HASH_OPTIONS.packRoot,
      WU_OPTIONS.force
    ]
  });
  const packId = opts.id;
  const packsRoot = opts.packsRoot ?? DEFAULT_PACKS_ROOT;
  const directPackRoot = opts.packRoot;
  const resolvedPackRoot = resolvePackRoot({ directPackRoot, packId, packsRoot });
  if (!resolvedPackRoot) {
    console.error(`${LOG_PREFIX} Error: Provide --id <packId> or --pack-root <dir>`);
    process.exit(1);
  }
  const hash = await computePackHash({ packRoot: resolvedPackRoot });
  console.log(hash);
}
if (import.meta.main) {
  void runCLI(main);
}

export {
  LOG_PREFIX,
  resolvePackRoot,
  computePackHash,
  main
};
