import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  initFts
} from "./chunk-6FQISQNA.js";
import {
  MycoIndex
} from "./chunk-TWSTAVLO.js";
import {
  run
} from "./chunk-IWBWZQK6.js";
import {
  run as run2
} from "./chunk-XNAM6Z4O.js";
import {
  VAULT_GITIGNORE,
  configureVaultEnv
} from "./chunk-25DJSF2K.js";
import {
  parseStringFlag
} from "./chunk-SAKJMNSR.js";
import "./chunk-MWW62YZP.js";
import {
  MycoConfigSchema,
  require_dist
} from "./chunk-JSK7L46L.js";
import {
  resolveVaultDir
} from "./chunk-N33KUCFP.js";
import "./chunk-RNWALAFP.js";
import "./chunk-WBLTISAK.js";
import {
  __toESM
} from "./chunk-PZUWP5VK.js";

// src/cli/init.ts
var import_yaml = __toESM(require_dist(), 1);
import fs from "fs";
import path from "path";
import os from "os";
async function run3(args) {
  const vaultPath = parseStringFlag(args, "--vault");
  const user = parseStringFlag(args, "--user") ?? "";
  const teamEnabled = args.includes("--team");
  const vaultDir = vaultPath ? vaultPath.startsWith("~/") ? path.join(os.homedir(), vaultPath.slice(2)) : path.resolve(vaultPath) : path.join(resolveVaultDir());
  if (fs.existsSync(path.join(vaultDir, "myco.yaml"))) {
    console.log(`Vault already initialized at ${vaultDir}`);
    return;
  }
  console.log(`Initializing Myco vault at ${vaultDir}`);
  const dirs = ["sessions", "plans", "spores", "artifacts", "team", "buffer", "logs"];
  for (const dir of dirs) {
    fs.mkdirSync(path.join(vaultDir, dir), { recursive: true });
  }
  const config = MycoConfigSchema.parse({
    version: 2,
    team: { user, enabled: teamEnabled }
  });
  fs.writeFileSync(
    path.join(vaultDir, "myco.yaml"),
    import_yaml.default.stringify(config),
    "utf-8"
  );
  fs.writeFileSync(path.join(vaultDir, ".gitignore"), VAULT_GITIGNORE, "utf-8");
  const index = new MycoIndex(path.join(vaultDir, "index.db"));
  initFts(index);
  index.close();
  const llmFlags = [];
  const llmProvider = parseStringFlag(args, "--llm-provider");
  const llmModel = parseStringFlag(args, "--llm-model");
  const llmUrl = parseStringFlag(args, "--llm-url");
  if (llmProvider) llmFlags.push("--llm-provider", llmProvider);
  if (llmModel) llmFlags.push("--llm-model", llmModel);
  if (llmUrl) llmFlags.push("--llm-url", llmUrl);
  const embeddingProvider = parseStringFlag(args, "--embedding-provider");
  const embeddingModel = parseStringFlag(args, "--embedding-model");
  const embeddingUrl = parseStringFlag(args, "--embedding-url");
  if (embeddingProvider) llmFlags.push("--embedding-provider", embeddingProvider);
  if (embeddingModel) llmFlags.push("--embedding-model", embeddingModel);
  if (embeddingUrl) llmFlags.push("--embedding-url", embeddingUrl);
  if (llmFlags.length > 0) {
    await run(llmFlags, vaultDir);
  }
  const digestFlags = [];
  const tiers = parseStringFlag(args, "--tiers");
  const injectTier = parseStringFlag(args, "--inject-tier");
  const contextWindow = parseStringFlag(args, "--context-window");
  if (tiers) digestFlags.push("--tiers", tiers);
  if (injectTier) digestFlags.push("--inject-tier", injectTier);
  if (contextWindow) digestFlags.push("--context-window", contextWindow);
  if (digestFlags.length > 0) {
    await run2(digestFlags, vaultDir);
  }
  console.log("");
  console.log("=== Myco Vault Initialized ===");
  console.log(`Path:               ${vaultDir}`);
  console.log(`Team mode:          ${teamEnabled ? "enabled" : "disabled"}`);
  if (user) console.log(`User:               ${user}`);
  console.log("");
  const projectRoot = path.resolve(".");
  const isProjectLocal = vaultDir.startsWith(projectRoot);
  if (!isProjectLocal) {
    configureVaultEnv(projectRoot, vaultDir);
  }
  console.log("Next: start a coding session \u2014 Myco will begin capturing automatically.");
}
export {
  run3 as run
};
//# sourceMappingURL=init-7N7F6W6U.js.map