import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  runRebuild
} from "./chunk-PQWQC3RF.js";
import {
  VectorIndex
} from "./chunk-4RMSHZE4.js";
import "./chunk-ALBVNGCF.js";
import "./chunk-RGVBGTD6.js";
import {
  createEmbeddingProvider
} from "./chunk-V5R6O6RP.js";
import "./chunk-RY76WEN3.js";
import "./chunk-6FQISQNA.js";
import {
  MycoIndex
} from "./chunk-TWSTAVLO.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/rebuild.ts
import path from "path";
async function run(_args, vaultDir) {
  console.log(`Rebuilding index for ${vaultDir}...`);
  const config = loadConfig(vaultDir);
  const index = new MycoIndex(path.join(vaultDir, "index.db"));
  let vectorIndex;
  let embeddingProvider;
  try {
    embeddingProvider = createEmbeddingProvider(config.intelligence.embedding);
    const testEmbed = await embeddingProvider.embed("test");
    vectorIndex = new VectorIndex(path.join(vaultDir, "vectors.db"), testEmbed.dimensions);
  } catch (e) {
    console.log(`Vector rebuild skipped: ${e.message}`);
  }
  try {
    const result = await runRebuild(
      { vaultDir, config, index, vectorIndex },
      embeddingProvider,
      (done, total) => process.stdout.write(`\rEmbedded ${done}/${total}`)
    );
    console.log(`Indexed ${result.ftsCount} notes (FTS)`);
    if (vectorIndex) {
      console.log(`
Embedded ${result.embeddedCount} notes (vectors)`);
      if (result.failedCount > 0) {
        console.log(`Failed: ${result.failedCount}`);
      }
      console.log(`Skipped ${result.skippedCount} superseded/archived`);
    }
  } finally {
    vectorIndex?.close();
    index.close();
  }
}
export {
  run
};
//# sourceMappingURL=rebuild-WXKQ5HZO.js.map