import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  VectorIndex
} from "./chunk-4RMSHZE4.js";
import {
  isProcessAlive
} from "./chunk-25DJSF2K.js";

// src/services/stats.ts
import fs from "fs";
import path from "path";
var VECTOR_FALLBACK_DIMENSION = 1024;
function gatherStats(vaultDir, index, vectorIndex) {
  const typeCounts = index.countByType();
  const spore_counts = index.sporeCountsByObservationType();
  let vector_count = 0;
  if (vectorIndex) {
    vector_count = vectorIndex.count();
  } else {
    const vecDb = path.join(vaultDir, "vectors.db");
    if (fs.existsSync(vecDb)) {
      try {
        const vec = new VectorIndex(vecDb, VECTOR_FALLBACK_DIMENSION);
        vector_count = vec.count();
        vec.close();
      } catch {
      }
    }
  }
  let daemon = null;
  const daemonPath = path.join(vaultDir, "daemon.json");
  if (fs.existsSync(daemonPath)) {
    try {
      const info = JSON.parse(fs.readFileSync(daemonPath, "utf-8"));
      daemon = {
        pid: info.pid,
        port: info.port,
        started: info.started,
        active_sessions: info.sessions || [],
        alive: isProcessAlive(info.pid)
      };
    } catch {
    }
  }
  return {
    vault: {
      path: vaultDir,
      name: path.basename(vaultDir),
      spore_counts,
      session_count: typeCounts["session"] ?? 0,
      plan_count: typeCounts["plan"] ?? 0,
      artifact_count: typeCounts["artifact"] ?? 0
    },
    index: {
      fts_entries: Object.values(typeCounts).reduce((sum, n) => sum + n, 0),
      vector_count
    },
    daemon
  };
}

export {
  gatherStats
};
//# sourceMappingURL=chunk-HRGHDMYI.js.map