"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var status_exports = {};
__export(status_exports, {
  register: () => register
});
module.exports = __toCommonJS(status_exports);
var path = __toESM(require("path"));
var import_ui = require("../ui");
function register(program) {
  program.command("status [projectPath]").description("Show index statistics").action(async (projectPath) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(projectPath ?? process.cwd());
    const cg = await KiroGraph.open(target);
    const stats = await cg.getStats();
    console.log();
    console.log((0, import_ui.section)("  Graph"));
    console.log(`  ${(0, import_ui.label)("Files")}      ${(0, import_ui.value)(String(stats.files))}`);
    console.log(`  ${(0, import_ui.label)("Symbols")}    ${(0, import_ui.value)(String(stats.nodes))}`);
    console.log(`  ${(0, import_ui.label)("Edges")}      ${(0, import_ui.value)(String(stats.edges))}`);
    if (stats.frameworks.length > 0) {
      console.log(`  ${(0, import_ui.label)("Frameworks")} ${(0, import_ui.value)(stats.frameworks.join(", "))}`);
    }
    const kindEntries = Object.entries(stats.nodesByKind).sort((a, b) => b[1] - a[1]);
    if (kindEntries.length > 0) {
      console.log(`
  ${(0, import_ui.label)("By kind")}`);
      console.log((0, import_ui.renderTable)(kindEntries.map(([k, v]) => [k, String(v)])));
    }
    const langEntries = Object.entries(stats.filesByLanguage ?? {}).sort((a, b) => b[1] - a[1]);
    if (langEntries.length > 0) {
      console.log(`
  ${(0, import_ui.label)("By language")}`);
      console.log((0, import_ui.renderTable)(langEntries.map(([k, v]) => [k, String(v)])));
    }
    const threshold = stats.syncWarningThreshold ?? 10;
    const pendingFiles = stats.pendingFiles ?? 0;
    const syncRunning = stats.syncRunning ?? false;
    console.log();
    console.log((0, import_ui.section)("  Sync"));
    if (syncRunning) {
      console.log(`  ${"\x1B[33m"}\u26A0 Sync is currently running in the background.${import_ui.reset}`);
    } else {
      console.log(`  ${(0, import_ui.label)("Status")}     ${import_ui.dim}idle${import_ui.reset}`);
    }
    if (pendingFiles > 0) {
      const warn = threshold > 0 && pendingFiles >= threshold;
      const pendingLabel = warn ? `${"\x1B[33m"}${pendingFiles} files pending${import_ui.reset}` : `${import_ui.dim}${pendingFiles} files pending${import_ui.reset}`;
      console.log(`  ${(0, import_ui.label)("Pending")}    ${pendingLabel}`);
      if (warn) {
        console.log(`  ${"\x1B[33m"}\u26A0 Index may be stale. Run \`kirograph sync\` to update.${import_ui.reset}`);
      }
    } else {
      console.log(`  ${(0, import_ui.label)("Pending")}    ${import_ui.green}up to date${import_ui.reset}`);
    }
    console.log();
    console.log((0, import_ui.section)("  Semantic Search"));
    if (stats.embeddingsEnabled) {
      const engineLabel = stats.semanticEngine === "sqlite-vec" ? `sqlite-vec  ${import_ui.dim}(${stats.vecIndexCount} entries in ANN index)${import_ui.reset}` : stats.semanticEngine === "orama" ? `orama  ${import_ui.dim}(hybrid \u2014 ${stats.vecIndexCount} docs in index)${import_ui.reset}` : stats.semanticEngine === "pglite" ? `pglite+pgvector  ${import_ui.dim}(hybrid \u2014 ${stats.vecIndexCount} rows in DB)${import_ui.reset}` : stats.semanticEngine === "lancedb" ? `lancedb  ${import_ui.dim}(${stats.vecIndexCount} entries in ANN index)${import_ui.reset}` : stats.semanticEngine === "qdrant" ? `qdrant  ${import_ui.dim}(${stats.vecIndexCount} points in collection)${import_ui.reset}` : stats.semanticEngine === "typesense" ? `typesense  ${import_ui.dim}(${stats.vecIndexCount} documents in collection)${import_ui.reset}` : `in-process cosine`;
      const total = stats.embeddableNodeCount > 0 ? stats.embeddableNodeCount : stats.nodes;
      const displayed = Math.min(stats.embeddingCount, total);
      const coverage = total > 0 ? Math.min(100, Math.round(stats.embeddingCount / total * 100)) : 0;
      console.log(`  ${(0, import_ui.label)("Status")}     ${import_ui.green}${import_ui.bold}enabled${import_ui.reset}`);
      console.log(`  ${(0, import_ui.label)("Model")}      ${(0, import_ui.value)(stats.embeddingModel)}`);
      console.log(`  ${(0, import_ui.label)("Engine")}     ${import_ui.violet}${engineLabel}${import_ui.reset}`);
      if (stats.engineFallback) {
        console.log(`  ${"\x1B[33m"}\u26A0 engine fallback: ${stats.engineFallback}${import_ui.reset}`);
      }
      console.log(`  ${(0, import_ui.label)("Indexed")}    ${(0, import_ui.value)(`${displayed} / ${total}`)}  ${import_ui.dim}(${coverage}%)${import_ui.reset}`);
    } else {
      console.log(`  ${(0, import_ui.label)("Status")}     ${import_ui.dim}disabled${import_ui.reset}`);
    }
    console.log();
    cg.close();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=status.js.map
