BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib/node_modules/openclaw/dist/path-env-Js9KsvFg.js
import { t as isTruthyEnvValue } from "./env-DkKx0PT3.js";
import { n as resolveBrewPathDirs } from "./brew-BGR64d64.js";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

//#region src/infra/path-env.ts
function isExecutable(filePath) {
	try {
		fs.accessSync(filePath, fs.constants.X_OK);
		return true;
	} catch {
		return false;
	}
}
function isDirectory(dirPath) {
	try {
		return fs.statSync(dirPath).isDirectory();
	} catch {
		return false;
	}
}
function mergePath(params) {
	const partsExisting = params.existing.split(path.delimiter).map((part) => part.trim()).filter(Boolean);
	const partsPrepend = (params.prepend ?? []).map((part) => part.trim()).filter(Boolean);
	const partsAppend = (params.append ?? []).map((part) => part.trim()).filter(Boolean);
	const seen = /* @__PURE__ */ new Set();
	const merged = [];
	for (const part of [
		...partsPrepend,
		...partsExisting,
		...partsAppend
	]) if (!seen.has(part)) {
		seen.add(part);
		merged.push(part);
	}
	return merged.join(path.delimiter);
}
function candidateBinDirs(opts) {
	const execPath = opts.execPath ?? process.execPath;
	const cwd = opts.cwd ?? process.cwd();
	const homeDir = opts.homeDir ?? os.homedir();
	const platform = opts.platform ?? process.platform;
	const prepend = [];
	const append = [];
	try {
		const execDir = path.dirname(execPath);
		if (isExecutable(path.join(execDir, "openclaw"))) prepend.push(execDir);
	} catch {}
	if (opts.allowProjectLocalBin === true || isTruthyEnvValue(process.env.OPENCLAW_ALLOW_PROJECT_LOCAL_BIN)) {
		const localBinDir = path.join(cwd, "node_modules", ".bin");
		if (isExecutable(path.join(localBinDir, "openclaw"))) append.push(localBinDir);
	}
	const miseDataDir = process.env.MISE_DATA_DIR ?? path.join(homeDir, ".local", "share", "mise");
	const miseShims = path.join(miseDataDir, "shims");
	if (isDirectory(miseShims)) prepend.push(miseShims);
	prepend.push(...resolveBrewPathDirs({ homeDir }));
	if (platform === "darwin") prepend.push(path.join(homeDir, "Library", "pnpm"));
	if (process.env.XDG_BIN_HOME) prepend.push(process.env.XDG_BIN_HOME);
	prepend.push(path.join(homeDir, ".local", "bin"));
	prepend.push(path.join(homeDir, ".local", "share", "pnpm"));
	prepend.push(path.join(homeDir, ".bun", "bin"));
	prepend.push(path.join(homeDir, ".yarn", "bin"));
	prepend.push("/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin");
	return {
		prepend: prepend.filter(isDirectory),
		append: append.filter(isDirectory)
	};
}
/**
* Best-effort PATH bootstrap so skills that require the `openclaw` CLI can run
* under launchd/minimal environments (and inside the macOS app bundle).
*/
function ensureOpenClawCliOnPath(opts = {}) {
	if (isTruthyEnvValue(process.env.OPENCLAW_PATH_BOOTSTRAPPED)) return;
	process.env.OPENCLAW_PATH_BOOTSTRAPPED = "1";
	const existing = opts.pathEnv ?? process.env.PATH ?? "";
	const { prepend, append } = candidateBinDirs(opts);
	if (prepend.length === 0 && append.length === 0) return;
	const merged = mergePath({
		existing,
		prepend,
		append
	});
	if (merged) process.env.PATH = merged;
}

//#endregion
export { ensureOpenClawCliOnPath as t };