import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  runDigest
} from "./chunk-PQWQC3RF.js";
import "./chunk-ALBVNGCF.js";
import "./chunk-RGVBGTD6.js";
import {
  createLlmProvider
} from "./chunk-V5R6O6RP.js";
import "./chunk-RY76WEN3.js";
import "./chunk-6FQISQNA.js";
import {
  MycoIndex
} from "./chunk-TWSTAVLO.js";
import "./chunk-25DJSF2K.js";
import {
  parseIntFlag
} from "./chunk-SAKJMNSR.js";
import "./chunk-MWW62YZP.js";
import {
  loadConfig
} from "./chunk-YG6MLLGL.js";
import "./chunk-JSK7L46L.js";
import "./chunk-RNWALAFP.js";
import "./chunk-WBLTISAK.js";
import "./chunk-PZUWP5VK.js";

// src/cli/digest.ts
import path from "path";
async function run(args, vaultDir) {
  const config = loadConfig(vaultDir);
  if (!config.digest.enabled) {
    console.error("Digest is not enabled. Set digest.enabled: true in myco.yaml.");
    process.exit(1);
  }
  const tierArg = parseIntFlag(args, "--tier");
  const isFull = args.includes("--full");
  const isReprocess = isFull || tierArg !== void 0;
  const digestLlmConfig = {
    provider: config.digest.intelligence.provider ?? config.intelligence.llm.provider,
    model: config.digest.intelligence.model ?? config.intelligence.llm.model,
    base_url: config.digest.intelligence.base_url ?? config.intelligence.llm.base_url,
    context_window: config.digest.intelligence.context_window
  };
  const llmProvider = createLlmProvider(digestLlmConfig);
  const index = new MycoIndex(path.join(vaultDir, "index.db"));
  if (isReprocess) {
    const tierLabel = tierArg ? `tier ${tierArg}` : "all tiers";
    console.log(`Full reprocess of ${tierLabel} \u2014 clean slate, all substrate`);
  } else {
    console.log("Running incremental digest cycle");
  }
  try {
    const result = await runDigest(
      {
        vaultDir,
        config,
        index,
        log: (level, message, data) => {
          const prefix = level === "warn" ? "!" : level === "info" ? ">" : "  ";
          const suffix = data ? ` ${JSON.stringify(data)}` : "";
          console.log(`${prefix} ${message}${suffix}`);
        }
      },
      llmProvider,
      { tier: tierArg, full: isFull }
    );
    if (!result) {
      console.log("No substrate found \u2014 nothing to digest.");
      return;
    }
    console.log(`
Digest cycle complete:`);
    console.log(`  Tiers generated: [${result.tiersGenerated.join(", ")}]`);
    console.log(`  Substrate: ${Object.values(result.substrate).flat().length} notes`);
    console.log(`  Duration: ${(result.durationMs / 1e3).toFixed(1)}s`);
    console.log(`  Model: ${result.model}`);
  } finally {
    index.close();
  }
}
export {
  run
};
//# sourceMappingURL=digest-PNHFM7JJ.js.map