openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
142 lines (141 loc) • 7.62 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { o as hasConfiguredSecretInput } from "./types.secrets-BmNLLnHp.mjs";
import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs";
import { p as shortenHomePath } from "./utils-C8YECn2Q.mjs";
import { C as resolveIsNixMode } from "./paths-DAcAg5aV.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { n as runExec } from "./exec-aRIvS9s4.mjs";
import { t as mergeGatewayServiceEnv } from "./service-env-merge-994N__ny.mjs";
import { n as resolveLaunchAgentLabel } from "./launchd-label-DdmmL_TH.mjs";
import { n as resolveGatewayService } from "./service-hQiIzcTo.mjs";
import { i as isLaunchAgentLoaded, r as isLaunchAgentEnabled, s as launchAgentPlistExists } from "./launchd-runtime-DS9pQoDc.mjs";
import { n as findStaleOpenClawUpdateLaunchdJobs } from "./launchd-BlyjKZEQ.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
//#region src/commands/doctor-platform-notes.ts
const DOCTOR_LAUNCHCTL_TIMEOUT_MS = 5e3;
function collectMacLaunchAgentOverrideWarning() {
if (process.platform !== "darwin") return null;
const e = path.join(resolveStateDir(), "disable-launchagent");
if (!fs.existsSync(e)) return null;
const t = shortenHomePath(e);
return [
`- LaunchAgent writes are disabled via ${t}.`,
"- To restore default behavior:",
` rm ${t}`
].join("\n");
}
function noteMacGatewayWarning(e) {
if (e) note(e, "Gateway (macOS)");
}
/** Diagnose persistent disablement without taking activation authority from update or Doctor. */
async function noteMacDisabledGatewayLaunchAgent(e = process.env) {
if (process.platform !== "darwin" || !await launchAgentPlistExists(e) || await isLaunchAgentLoaded({ env: e }) || await isLaunchAgentEnabled({ env: e })) return;
const t = resolveLaunchAgentLabel(e);
const n = e.OPENCLAW_LAUNCHD_LABEL?.trim() ? `OPENCLAW_LAUNCHD_LABEL=${t} ` : "";
note([
`Gateway LaunchAgent ${t} is installed but unloaded and disabled in launchd.`,
"A terminated update helper can leave it disabled across logins. Doctor does not automatically re-enable it.",
`After verifying the installation is safe to run, use ${n}${formatCliCommand("openclaw gateway start", e)} to re-enable and start it. Keep the same state/config overrides.`,
`If an update was interrupted or installation safety is uncertain, run ${formatCliCommand("openclaw update", e)} or ${formatCliCommand("openclaw doctor", e)} and ${formatCliCommand("openclaw triage", e)} before starting it.`
].join("\n"), "Gateway (macOS)");
}
async function collectMacStaleOpenClawUpdateLaunchdJobsWarning() {
if (process.platform !== "darwin") return null;
const e = process.env;
const t = await resolveGatewayService().readCommand(e).catch(() => null);
const n = mergeGatewayServiceEnv(e, t);
const r = await findStaleOpenClawUpdateLaunchdJobs(n).catch(() => []);
if (r.length === 0) return null;
return [
"- Stale OpenClaw updater launchd job(s) detected.",
...r.map((e) => {
const t = e.lastExitStatus !== void 0 ? `, last exit ${e.lastExitStatus}` : "";
const n = e.pid !== void 0 ? `, pid ${e.pid}` : "";
return `- ${e.label}${n}${t}`;
}),
"- Fix after confirming no update is running:",
" launchctl remove <label>",
` ${formatCliCommand("openclaw gateway restart")}`
].join("\n");
}
async function launchctlGetenv(e) {
try {
const t = await runExec("/bin/launchctl", ["getenv", e], {
logOutput: false,
timeoutMs: DOCTOR_LAUNCHCTL_TIMEOUT_MS
});
return normalizeOptionalString(t.stdout);
} catch {
return;
}
}
async function collectMacLaunchctlGatewayEnvOverrideWarning(e) {
if (process.platform !== "darwin") return null;
if (![
e.gateway?.auth?.token,
e.gateway?.auth?.password,
e.gateway?.remote?.token,
e.gateway?.remote?.password
].some((t) => hasConfiguredSecretInput(t, e.secrets?.defaults))) return null;
const t = await launchctlGetenv("OPENCLAW_GATEWAY_TOKEN");
const n = await launchctlGetenv("OPENCLAW_GATEWAY_PASSWORD");
if (!t && !n) return null;
return [
"- Host-wide launchctl gateway auth overrides detected.",
"- Current managed Gateway installs do not need these values unless config intentionally references the env var.",
t ? "- `OPENCLAW_GATEWAY_TOKEN` is set; explicit environment URL or node-host targets can use a different token than gateway.auth.token." : void 0,
n ? "- `OPENCLAW_GATEWAY_PASSWORD` is set; explicit environment URL or node-host targets can use a different password than gateway.auth.password." : void 0,
"- Clear overrides and restart the app/gateway:",
t ? " launchctl unsetenv OPENCLAW_GATEWAY_TOKEN" : void 0,
n ? " launchctl unsetenv OPENCLAW_GATEWAY_PASSWORD" : void 0
].filter((e) => Boolean(e)).join("\n");
}
async function noteMacGatewayPlatformWarnings(e) {
noteMacGatewayWarning(collectMacLaunchAgentOverrideWarning());
noteMacGatewayWarning(await collectMacStaleOpenClawUpdateLaunchdJobsWarning());
noteMacGatewayWarning(await collectMacLaunchctlGatewayEnvOverrideWarning(e));
}
async function collectGatewayPlatformWarnings(e) {
if (process.platform === "linux") {
if (e.gateway?.mode === "remote" || resolveIsNixMode()) return [];
const { auditGatewayServiceConfig: t, SERVICE_AUDIT_CODES: n } = await import("./service-audit-LS9qYwWz.mjs");
return (await t({
env: process.env,
command: null
})).issues.filter((e) => e.code === n.systemdKillModeControlGroup || e.code === n.systemdKillModeProcessOrNone || e.repair === "host").map((e) => e.repair === "host" ? `${e.message} (${e.detail})` : [e.detail ? `${e.message} (${e.detail})` : e.message, `Run ${formatCliCommand("openclaw gateway install --force")} only after verification; inspect drop-ins separately.`].join("\n"));
}
return [
collectMacLaunchAgentOverrideWarning(),
await collectMacStaleOpenClawUpdateLaunchdJobsWarning(),
await collectMacLaunchctlGatewayEnvOverrideWarning(e)
].filter((e) => Boolean(e));
}
function noteStartupOptimizationHints(e = process.env) {
const t = process.platform;
if (t === "win32") return;
const n = os.arch();
const r = os.totalmem();
if (!(t === "linux" && (n === "arm" || n === "arm64" || t === "linux" && r > 0 && r <= 8 * 1024 ** 3))) return;
const i = normalizeOptionalString(e.NODE_COMPILE_CACHE) ?? "";
const a = normalizeOptionalString(e.NODE_DISABLE_COMPILE_CACHE) ?? "";
const o = normalizeOptionalString(e.OPENCLAW_NO_RESPAWN) ?? "";
const s = [];
if (!i) s.push("- NODE_COMPILE_CACHE is not set; repeated CLI runs can be slower on small hosts (Raspberry Pi/VM).");
else if (/^\/(?:private\/)?tmp(?:\/|$)/.test(i)) s.push("- NODE_COMPILE_CACHE points to /tmp; use /var/tmp so cache survives reboots and warms startup reliably.");
if (a) s.push("- NODE_DISABLE_COMPILE_CACHE is set; startup compile cache is disabled.");
if (o !== "1") s.push("- OPENCLAW_NO_RESPAWN is not set to 1; set it when you want routine gateway restarts to stay in-process instead of handing off to a managed supervisor.");
if (s.length === 0) return;
const c = [
"- Suggested env for low-power hosts:",
" export NODE_COMPILE_CACHE=/var/tmp/openclaw-compile-cache",
" mkdir -p /var/tmp/openclaw-compile-cache",
" export OPENCLAW_NO_RESPAWN=1",
a ? " unset NODE_DISABLE_COMPILE_CACHE" : void 0
].filter((e) => Boolean(e));
note([...s, ...c].join("\n"), "Startup optimization");
}
//#endregion
export { collectGatewayPlatformWarnings, noteMacDisabledGatewayLaunchAgent, noteMacGatewayPlatformWarnings, noteStartupOptimizationHints };