import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  MycoIndex
} from "./chunk-TWSTAVLO.js";
import "./chunk-PZUWP5VK.js";

// src/cli/session.ts
import fs from "fs";
import path from "path";
function run(args, vaultDir) {
  const idOrLatest = args[0];
  const index = new MycoIndex(path.join(vaultDir, "index.db"));
  const sessions = index.query({ type: "session" });
  if (sessions.length === 0) {
    console.log("No sessions found");
    index.close();
    return;
  }
  let target;
  if (!idOrLatest || idOrLatest === "latest") {
    target = sessions[sessions.length - 1];
  } else {
    target = sessions.find((s) => s.id.includes(idOrLatest));
  }
  if (!target) {
    console.error(`Session not found: ${idOrLatest}`);
    console.log("Available:", sessions.map((s) => s.id).join(", "));
    index.close();
    return;
  }
  const fullPath = path.join(vaultDir, target.path);
  if (fs.existsSync(fullPath)) {
    console.log(fs.readFileSync(fullPath, "utf-8"));
  } else {
    console.log(`Title: ${target.title}`);
    console.log(`Content:
${target.content?.slice(0, 2e3)}`);
  }
  index.close();
}
export {
  run
};
//# sourceMappingURL=session-F326AWCH.js.map