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

// src/version.ts
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
var cached;
function getPluginVersion() {
  if (cached) return cached;
  const pluginRoot = new AgentRegistry().resolvePluginRoot();
  if (pluginRoot) {
    cached = readVersionFrom(pluginRoot);
    if (cached) return cached;
  }
  let dir = path.dirname(fileURLToPath(import.meta.url));
  for (let i = 0; i < 5; i++) {
    const version = readVersionFrom(dir);
    if (version) {
      cached = version;
      return cached;
    }
    dir = path.dirname(dir);
  }
  cached = readVersionFrom(process.cwd()) ?? "0.0.0";
  return cached;
}
function readVersionFrom(dir) {
  const pkgPath = path.join(dir, "package.json");
  try {
    const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
    return pkg.version;
  } catch {
    return void 0;
  }
}

export {
  getPluginVersion
};
//# sourceMappingURL=chunk-CK24O5YQ.js.map