import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
import { join } from "path";
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from "fs";
import { homedir } from "os";
function workersDir() {
  return join(homedir(), ".stackmemory", "workers");
}
function registryFile() {
  return join(workersDir(), "registry.json");
}
function ensureWorkerStateDir(workerId) {
  const dir = join(workersDir(), workerId);
  if (!existsSync(dir)) {
    mkdirSync(dir, { recursive: true });
  }
  return dir;
}
function saveRegistry(session) {
  const dir = workersDir();
  if (!existsSync(dir)) {
    mkdirSync(dir, { recursive: true });
  }
  writeFileSync(registryFile(), JSON.stringify(session, null, 2));
}
function loadRegistry() {
  if (!existsSync(registryFile())) return null;
  try {
    return JSON.parse(readFileSync(registryFile(), "utf-8"));
  } catch {
    return null;
  }
}
function clearRegistry() {
  const file = registryFile();
  if (existsSync(file)) {
    rmSync(file, { force: true });
  }
}
function getWorkersDir() {
  return workersDir();
}
export {
  clearRegistry,
  ensureWorkerStateDir,
  getWorkersDir,
  loadRegistry,
  saveRegistry
};
//# sourceMappingURL=worker-registry.js.map
