openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
9 lines • 8.6 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{o as hasConfiguredSecretInput}from"./types.secrets-UWdyCdE6.mjs";import{r as resolveStateDir}from"./state-dir-BwIClCab.mjs";import{f as shortenHomePath}from"./utils-Dlk0IYAa.mjs";import{C as resolveIsNixMode}from"./paths-D_FOvGon.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{l as redactSupportDiagnosticLine}from"./diagnostic-support-redaction-fdb2R4EP.mjs";import{n as runExec}from"./exec-c5tqm8tb.mjs";import{t as mergeGatewayServiceEnv}from"./service-env-merge-Db3tXSCb.mjs";import{n as resolveLaunchAgentLabel}from"./launchd-label-Daj1UmUS.mjs";import{n as resolveGatewayService}from"./service-Bz63n2ee.mjs";import{i as isLaunchAgentLoaded,r as isLaunchAgentEnabled,s as launchAgentPlistExists}from"./launchd-runtime-CGjMI2Ve.mjs";import{n as findStaleOpenClawUpdateLaunchdJobs}from"./launchd-BpufAYg5.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{r as confirmDoctorServiceRepair}from"./doctor-service-repair-policy-gYXaFNLg.mjs";import fs from"node:fs";import path from"node:path";import os from"node:os";
//!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(`
`)}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(`
`),`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);let r;try{r=await findStaleOpenClawUpdateLaunchdJobs(n)}catch(t){return`Could not inspect stale OpenClaw updater launchd jobs: ${redactSupportDiagnosticLine(formatErrorMessage(t),{env:n,stateDir:resolveStateDir(n)})}; interrupted-update leftovers were NOT checked. Check launchctl availability and rerun ${formatCliCommand(`openclaw doctor`,e)}.`}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(`
`)}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(`
`)}async function noteMacGatewayPlatformWarnings(e,t,n=process.env){if(process.platform!==`darwin`)return;for(const t of await collectGatewayPlatformWarnings(e))note(t,`Gateway (macOS)`);if(resolveIsNixMode(n)||e.gateway?.mode===`remote`)return;const{inspectLaunchAgentEnvironmentQuotes:r}=await import(`./launchd-service-files-BK2cEwND.mjs`);const{withGatewayServiceOperationLock:i}=await import(`./service-operation-lock-BR4RIMlV.mjs`);const{resolveNodeServiceIdentityEnvironment:a}=await import(`./constants-DPk8-sMa.mjs`);for(const[e,o]of[[`gateway`,n],[`node`,{...n,...a(n)}]])try{await i(o,async i=>{const a=await r(o);if(!a)return;note(`${a.filePath}: values have wrapping double quotes (${a.keys.join(`, `)}). These may be legacy corruption or intentional data. Run interactive ${formatCliCommand(`openclaw doctor`,n)} to review removal; values are never displayed.`,`Service environment`);if(!t||!await confirmDoctorServiceRepair(t,{message:`Back up ${e} service env and remove one outer double-quote pair from ${a.keys.join(`, `)}? Only approve if these quotes are unintended.`,initialValue:false,requiresInteractiveConfirmation:true}))return;const s=await a.repair(i);note(`Repaired ${a.keys.join(`, `)}. Backup: ${s}. Restart with ${formatCliCommand(`openclaw ${e} restart`,n)} to apply. If your shell inherited the quoted values, correct it before reinstalling.`,`Service environment`)})}catch{note(`Could not inspect or repair the ${e} service env. Existing files and any .quotes-*.bak recovery copy were retained; check permissions and rerun doctor.`,`Service environment`)}}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-B2kam1Hj.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(`
`))}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(`
`),`Startup optimization`)}export{collectGatewayPlatformWarnings,noteMacDisabledGatewayLaunchAgent,noteMacGatewayPlatformWarnings,noteStartupOptimizationHints};