import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  LmStudioBackend,
  OllamaBackend
} from "./chunk-MWW62YZP.js";
import {
  AgentRegistry
} from "./chunk-RNWALAFP.js";

// src/cli/shared.ts
import fs from "fs";
import path from "path";
import os from "os";
function loadEnv() {
  const envPath = path.resolve(process.cwd(), ".env");
  if (!fs.existsSync(envPath)) return;
  for (const line of fs.readFileSync(envPath, "utf-8").split("\n")) {
    const match = line.match(/^\s*([^#=]+?)\s*=\s*(.*?)\s*$/);
    if (match && !process.env[match[1]]) {
      process.env[match[1]] = match[2];
    }
  }
}
function isProcessAlive(pid) {
  try {
    process.kill(pid, 0);
    return true;
  } catch {
    return false;
  }
}
var PROVIDER_DEFAULTS = {
  ollama: { base_url: OllamaBackend.DEFAULT_BASE_URL },
  "lm-studio": { base_url: LmStudioBackend.DEFAULT_BASE_URL }
};
var VAULT_GITIGNORE = `# Runtime \u2014 rebuilt on daemon startup
index.db
index.db-wal
index.db-shm
vectors.db

# Daemon state \u2014 per-machine, ephemeral
daemon.json
_portal.md
buffer/
logs/

# Obsidian \u2014 per-user workspace config
.obsidian/
`;
function collapseHomePath(absPath) {
  const home = os.homedir();
  if (absPath.startsWith(home + path.sep) || absPath === home) {
    return "~" + absPath.slice(home.length);
  }
  return absPath;
}
function configureVaultEnv(projectRoot, vaultDir) {
  const registry = new AgentRegistry();
  const active = registry.detectActiveAgent();
  const portableDir = collapseHomePath(vaultDir);
  if (active) {
    if (active.configureVaultEnv(projectRoot, portableDir)) {
      console.log(`Set MYCO_VAULT_DIR for ${active.displayName}`);
    }
  } else {
    for (const name of registry.adapterNames) {
      const adapter = registry.getAdapter(name);
      if (adapter?.configureVaultEnv(projectRoot, portableDir)) {
        console.log(`Set MYCO_VAULT_DIR for ${adapter.displayName}`);
      }
    }
  }
  console.log(`
For other agents, add to your shell profile:`);
  console.log(`  export MYCO_VAULT_DIR="${portableDir}"
`);
}

export {
  loadEnv,
  isProcessAlive,
  VAULT_GITIGNORE,
  configureVaultEnv
};
//# sourceMappingURL=chunk-25DJSF2K.js.map