import { f as safeRealpathSync, i as isPathInside } from "./path-BlG8lhgR.js";
import { p as resolveUserPath } from "./utils-BQafJ6e6.js";
import "./path-safety-CSmLs9q3.js";
import fs from "node:fs";
import path from "node:path";
//#region src/plugins/dev-source-root.ts
const DEX_DEV_SOURCE_ROOT_ENV = "DEX_DEV_SOURCE_ROOT";
function readPackageName(packageJsonPath) {
	try {
		const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
		return typeof parsed.name === "string" ? parsed.name : null;
	} catch {
		return null;
	}
}
function resolveOpenClawDevSourceRoot(env = process.env) {
	const rawRoot = env[DEX_DEV_SOURCE_ROOT_ENV]?.trim();
	if (!rawRoot) return null;
	const realRoot = safeRealpathSync(resolveUserPath(rawRoot, env));
	if (!realRoot) return null;
	if (readPackageName(path.join(realRoot, "package.json")) !== "openclaw") return null;
	if (!fs.existsSync(path.join(realRoot, "src"))) return null;
	if (!fs.existsSync(path.join(realRoot, "extensions"))) return null;
	return realRoot;
}
function isBundledPluginInsideDevSourceRoot(params) {
	const devSourceRoot = resolveOpenClawDevSourceRoot(params.env);
	if (!devSourceRoot) return false;
	const extensionsRoot = safeRealpathSync(path.join(devSourceRoot, "extensions"));
	const pluginRoot = safeRealpathSync(resolveUserPath(params.rootDir, params.env));
	if (!extensionsRoot || !pluginRoot) return false;
	return isPathInside(extensionsRoot, pluginRoot);
}
//#endregion
export { resolveOpenClawDevSourceRoot as n, isBundledPluginInsideDevSourceRoot as t };
