openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
39 lines (38 loc) • 1.88 kB
JavaScript
import { H as resolveGatewayCatalogCommandPath } from "./argv-DNjh_yaF.js";
import { t as resolveCliArgvInvocation } from "./argv-invocation-C1WhAkJL.js";
import { r as resolveCliContainerTarget } from "./container-target-yd6OnwF_.js";
import { n as tryProcessCwd } from "./safe-cwd-DOxDm8mD.js";
import { w as resolveStateDir } from "./paths-D2sRr1a_.js";
import { t as loadGlobalRuntimeDotEnvFiles } from "./dotenv-global-BxHOyAmz.js";
import { n as loadWorkspaceDotEnvFile } from "./dotenv-BHEKhHyV.js";
import path from "node:path";
//#region src/cli/dotenv.ts
/** Load `.env` files for normal CLI commands without overriding existing process env. */
function loadCliDotEnv(opts) {
const quiet = opts?.quiet ?? true;
const cwd = tryProcessCwd();
if (cwd) loadWorkspaceDotEnvFile(path.join(cwd, ".env"), { quiet });
if (opts?.loadGlobalEnv === false) return;
loadGlobalRuntimeDotEnvFiles({
quiet,
stateEnvPath: path.join(resolveStateDir(process.env), ".env")
});
}
/** Load only the dotenv scope an early CLI failure may consult for diagnostic formatting. */
async function loadCliDotEnvForEarlyDiagnostic(argv, env = process.env) {
if (resolveCliContainerTarget(argv, env)) return;
const invocation = resolveCliArgvInvocation(argv);
if (invocation.commandPath[0] === "agent" && invocation.commandPath[1] === "exec") return;
if (invocation.primary === "agent" && !argv.includes("--local")) {
const { loadGatewayDispatchCliDotEnv } = await import("./gateway-dispatch-dotenv-Bfa0rkuJ.js");
await loadGatewayDispatchCliDotEnv({ quiet: true });
return;
}
const gatewayPath = resolveGatewayCatalogCommandPath(argv);
loadCliDotEnv({
loadGlobalEnv: !(!invocation.hasHelpOrVersion && (gatewayPath?.length === 1 || gatewayPath?.length === 2 && gatewayPath[1] === "run")),
quiet: true
});
}
//#endregion
export { loadCliDotEnv, loadCliDotEnvForEarlyDiagnostic };