import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  runReprocess
} from "./chunk-PQWQC3RF.js";
import {
  VectorIndex
} from "./chunk-4RMSHZE4.js";
import "./chunk-ALBVNGCF.js";
import "./chunk-RGVBGTD6.js";
import {
  createEmbeddingProvider,
  createLlmProvider
} from "./chunk-V5R6O6RP.js";
import "./chunk-RY76WEN3.js";
import {
  initFts
} from "./chunk-6FQISQNA.js";
import {
  MycoIndex
} from "./chunk-TWSTAVLO.js";
import "./chunk-25DJSF2K.js";
import {
  parseStringFlag
} 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/reprocess.ts
import path from "path";
async function run(args, vaultDir) {
  const sessionFilter = parseStringFlag(args, "--session");
  const dateFilter = parseStringFlag(args, "--date");
  const failedOnly = args.includes("--failed");
  const skipLlm = args.includes("--index-only");
  const config = loadConfig(vaultDir);
  const index = new MycoIndex(path.join(vaultDir, "index.db"));
  initFts(index);
  const llmProvider = skipLlm ? null : createLlmProvider(config.intelligence.llm);
  const embeddingProvider = createEmbeddingProvider(config.intelligence.embedding);
  let vectorIndex = null;
  try {
    const testEmbed = await embeddingProvider.embed("test");
    vectorIndex = new VectorIndex(path.join(vaultDir, "vectors.db"), testEmbed.dimensions);
  } catch (e) {
    console.log(`Vector index unavailable: ${e.message}`);
  }
  try {
    const result = await runReprocess(
      { vaultDir, config, index, vectorIndex: vectorIndex ?? void 0, log: (level, msg) => console.log(`[${level}] ${msg}`) },
      llmProvider,
      embeddingProvider,
      { session: sessionFilter, date: dateFilter, failed: failedOnly, indexOnly: skipLlm },
      (phase, done, total) => {
        process.stdout.write(`\r  ${phase}: ${done}/${total}`);
        if (done === total) process.stdout.write("\n");
      }
    );
    if (result.sessionsProcessed === 0) {
      const filters = [sessionFilter && `session="${sessionFilter}"`, dateFilter && `date="${dateFilter}"`, failedOnly && "failed"].filter(Boolean);
      console.log(filters.length ? `No sessions matching ${filters.join(", ")} found.` : "No sessions found.");
    } else {
      console.log(`
Done: ${result.sessionsProcessed} sessions reprocessed, ${result.observationsExtracted} observations extracted, ${result.summariesRegenerated} summaries regenerated.`);
    }
  } finally {
    index.close();
    vectorIndex?.close();
  }
}
export {
  run
};
//# sourceMappingURL=reprocess-PKRDV67L.js.map