import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
import {
  isProcessAlive
} from "./chunk-25DJSF2K.js";
import "./chunk-SAKJMNSR.js";
import "./chunk-MWW62YZP.js";
import "./chunk-RNWALAFP.js";
import "./chunk-WBLTISAK.js";
import "./chunk-PZUWP5VK.js";

// src/cli/restart.ts
import fs from "fs";
import path from "path";
async function run(_args, vaultDir) {
  const daemonPath = path.join(vaultDir, "daemon.json");
  if (fs.existsSync(daemonPath)) {
    try {
      const daemon = JSON.parse(fs.readFileSync(daemonPath, "utf-8"));
      if (isProcessAlive(daemon.pid)) {
        process.kill(daemon.pid, "SIGTERM");
        console.log(`Stopped daemon (pid ${daemon.pid})`);
      } else {
        console.log(`Daemon pid ${daemon.pid} was already dead`);
      }
    } catch {
    }
    try {
      fs.unlinkSync(daemonPath);
    } catch {
    }
  }
  const { DaemonClient } = await import("./client-FDKJ4BY7.js");
  const client = new DaemonClient(vaultDir);
  console.log("Waiting for health check...");
  const healthy = await client.ensureRunning();
  if (healthy) {
    try {
      const info = JSON.parse(fs.readFileSync(daemonPath, "utf-8"));
      console.log(`Daemon healthy on port ${info.port}`);
      console.log(`Dashboard: http://localhost:${info.port}/`);
    } catch {
      console.log("Daemon healthy");
    }
  } else {
    console.error("Daemon failed to become healthy");
  }
}
export {
  run
};
//# sourceMappingURL=restart-WSJRHRHI.js.map