openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
109 lines (108 loc) • 3.45 kB
JavaScript
import { l as sanitizeHostExecEnv, t as inspectHostExecEnvOverrides } from "./host-env-security-BrTYS4pH.mjs";
import { getDefaultEnvironment } from "@modelcontextprotocol/client/stdio";
//#region src/agents/agent-bundle-lsp-env.ts
/** Bundle LSP server environment: allowlisted base plus withheld-name diagnostics. */
const LSP_ENV_PASSTHROUGH_DOCS_URL = "https://docs.openclaw.ai/plugins/bundles#lsp-server-environment";
const LSP_INHERITED_ENV_KEYS = /* @__PURE__ */ new Set([
"LANG",
"LANGUAGE",
"TZ",
"TMPDIR",
"TMP",
"TEMP",
"XDG_CACHE_HOME",
"XDG_CONFIG_HOME",
"XDG_DATA_HOME",
"XDG_STATE_HOME",
"XDG_RUNTIME_DIR",
"XDG_CONFIG_DIRS",
"XDG_DATA_DIRS",
"GOROOT",
"GOMODCACHE",
"GOBIN",
"RUSTUP_HOME",
"RUSTUP_TOOLCHAIN",
"JAVA_HOME"
]);
const COMMONLY_NEEDED_LSP_ENV_NAMES = [
"HTTP_PROXY",
"HTTPS_PROXY",
"ALL_PROXY",
"NO_PROXY",
"http_proxy",
"https_proxy",
"all_proxy",
"no_proxy",
"SSL_CERT_FILE",
"SSL_CERT_DIR",
"NODE_EXTRA_CA_CERTS",
"REQUESTS_CA_BUNDLE",
"CURL_CA_BUNDLE",
"VIRTUAL_ENV",
"CONDA_PREFIX",
"PYTHONPATH",
"NODE_OPTIONS",
"NODE_PATH",
"GOPATH",
"GOFLAGS",
"GOPRIVATE",
"GOPROXY",
"GONOPROXY",
"GONOSUMDB",
"CARGO_HOME",
"CARGO_TARGET_DIR",
"GRADLE_USER_HOME",
"MAVEN_HOME",
"M2_HOME",
"DOTNET_ROOT",
"ANDROID_HOME",
"ANDROID_SDK_ROOT"
];
const SECRET_LOOKING_ENV_NAME = /TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH|COOKIE|SESSION/i;
function envLookupName(e) {
return process.platform === "win32" ? e.toUpperCase() : e;
}
/** Bundle LSP base env: the MCP stdio defaults plus toolchain locations, never Gateway secrets. */
function resolveLspBaseEnv(e) {
const t = getDefaultEnvironment();
for (const [n, r] of Object.entries(e)) {
const e = envLookupName(n);
if (r !== void 0 && (e.startsWith("LC_") || LSP_INHERITED_ENV_KEYS.has(e))) t[n] = r;
}
return t;
}
/** Child env for a bundle LSP server: allowlisted base, then the server's own `env`. */
function resolveLspServerEnv(e, t = process.env) {
return sanitizeHostExecEnv({
baseEnv: resolveLspBaseEnv(t),
overrides: e ?? null
});
}
/** Names of commonly needed, non-secret parent variables missing from a server's child env. */
function collectWithheldLspEnvNames(e) {
const t = new Set(COMMONLY_NEEDED_LSP_ENV_NAMES.map(envLookupName));
const n = new Set(Object.keys(e.childEnv).map(envLookupName));
const r = /* @__PURE__ */ new Set();
for (const [i, a] of Object.entries(e.parentEnv)) {
const e = envLookupName(i);
if (a?.trim() && t.has(e) && !n.has(e) && !SECRET_LOOKING_ENV_NAME.test(e)) r.add(i);
}
const i = {
configurable: [],
refused: []
};
for (const e of [...r].sort()) {
const { rejectedOverrideBlockedKeys: t } = inspectHostExecEnvOverrides({ overrides: { [e]: "" } });
(t.length > 0 ? i.refused : i.configurable).push(e);
}
return i;
}
/** One line per category; empty when nothing commonly needed was withheld. */
function formatWithheldLspEnvHints(e) {
const t = [];
if (e.configurable.length > 0) t.push(`${e.configurable.join(", ")}: add to the server's "env" in its bundle .lsp.json if it needs them.`);
if (e.refused.length > 0) t.push(`${e.refused.join(", ")}: refused by the host exec env policy, also in "env"; a server that needs them must set them itself (for example, a wrapper script as its "command").`);
return t;
}
//#endregion
export { LSP_ENV_PASSTHROUGH_DOCS_URL, collectWithheldLspEnvNames, formatWithheldLspEnvHints, resolveLspServerEnv };