import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  parseStringFlag
} from "./chunk-SAKJMNSR.js";
import {
  MycoConfigSchema,
  require_dist
} from "./chunk-JSK7L46L.js";
import {
  __toESM
} from "./chunk-PZUWP5VK.js";

// src/cli/setup-llm.ts
var import_yaml = __toESM(require_dist(), 1);
import fs from "fs";
import path from "path";
var CONFIG_FILENAME = "myco.yaml";
var DAEMON_STATE_FILENAME = "daemon.json";
var USAGE = `Usage: myco setup-llm [options]

Configure LLM and embedding provider settings.

Options:
  --llm-provider <name>         LLM provider (ollama, lm-studio, anthropic)
  --llm-model <name>            LLM model name
  --llm-url <url>               LLM provider base URL
  --llm-context-window <number> LLM context window (tokens)
  --llm-max-tokens <number>     LLM max output tokens
  --embedding-provider <name>   Embedding provider (ollama, lm-studio)
  --embedding-model <name>      Embedding model name
  --embedding-url <url>         Embedding provider base URL
  --show                        Show current settings and exit
`;
async function run(args, vaultDir) {
  const configPath = path.join(vaultDir, CONFIG_FILENAME);
  const raw = fs.readFileSync(configPath, "utf-8");
  const doc = import_yaml.default.parse(raw);
  if (args.includes("--show")) {
    const config = MycoConfigSchema.parse(doc);
    console.log(JSON.stringify(config.intelligence, null, 2));
    return;
  }
  if (args.length === 0) {
    console.log(USAGE);
    return;
  }
  if (!doc.intelligence || typeof doc.intelligence !== "object") {
    doc.intelligence = {};
  }
  const intelligence = doc.intelligence;
  if (!intelligence.llm || typeof intelligence.llm !== "object") {
    intelligence.llm = {};
  }
  if (!intelligence.embedding || typeof intelligence.embedding !== "object") {
    intelligence.embedding = {};
  }
  const llm = intelligence.llm;
  const embedding = intelligence.embedding;
  const llmProvider = parseStringFlag(args, "--llm-provider");
  if (llmProvider !== void 0) llm.provider = llmProvider;
  const llmModel = parseStringFlag(args, "--llm-model");
  if (llmModel !== void 0) llm.model = llmModel;
  const llmUrl = parseStringFlag(args, "--llm-url");
  if (llmUrl !== void 0) llm.base_url = llmUrl;
  const llmContextWindow = parseStringFlag(args, "--llm-context-window");
  if (llmContextWindow !== void 0) llm.context_window = parseInt(llmContextWindow, 10);
  const llmMaxTokens = parseStringFlag(args, "--llm-max-tokens");
  if (llmMaxTokens !== void 0) llm.max_tokens = parseInt(llmMaxTokens, 10);
  const embeddingProvider = parseStringFlag(args, "--embedding-provider");
  if (embeddingProvider !== void 0) embedding.provider = embeddingProvider;
  const embeddingModel = parseStringFlag(args, "--embedding-model");
  if (embeddingModel !== void 0) embedding.model = embeddingModel;
  const embeddingUrl = parseStringFlag(args, "--embedding-url");
  if (embeddingUrl !== void 0) embedding.base_url = embeddingUrl;
  const result = MycoConfigSchema.safeParse(doc);
  if (!result.success) {
    console.error("Validation error:");
    for (const issue of result.error.issues) {
      console.error(`  ${issue.path.join(".")}: ${issue.message}`);
    }
    process.exit(1);
  }
  fs.writeFileSync(configPath, import_yaml.default.stringify(doc), "utf-8");
  console.log("Intelligence configuration updated.");
  const updated = MycoConfigSchema.parse(doc);
  console.log(JSON.stringify(updated.intelligence, null, 2));
  if (embeddingModel !== void 0) {
    console.log("\nWarning: changing the embedding model requires a full vector index rebuild.");
    console.log("Run: node dist/src/cli.js rebuild");
  }
  if (fs.existsSync(path.join(vaultDir, DAEMON_STATE_FILENAME))) {
    console.log("\nNote: restart the daemon for changes to take effect (myco restart)");
  }
}

export {
  run
};
//# sourceMappingURL=chunk-IWBWZQK6.js.map