openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 2.65 kB
JavaScript
import { o as isDefaultInstallIdentity } from "./paths-FklbMVOH.mjs";
import { t as formatErrorMessage } from "./errors-BSdPMFao.mjs";
import { t as formatCliCommand } from "./command-format-Cte1SWM4.mjs";
import { n as sanitizeTerminalText } from "./safe-text-C6FhHCw7.mjs";
import { t as note } from "./note-BpWs6H5N.mjs";
import { n as formatForeignLaunchdJobs, r as repairForeignLaunchdJob, t as findForeignLaunchdJobs } from "./launchd-foreign-jobs-MaNQciKX.mjs";
import { t as readGatewayForcedRestartSummary } from "./restart-storm-Q-foKK-K.mjs";
import { a as isServiceRepairDeferred, l as shouldManageGatewayService, s as resolveServiceRepairPolicy } from "./doctor-service-repair-policy-BJrQJIOB.mjs";
//#region src/commands/doctor-foreign-launchd-jobs.ts
/** Reports foreign launchd jobs; only explicit Doctor repair may remove lifecycle jobs. */
async function noteMacForeignLaunchdJobs(options, runtime, env = process.env) {
if (process.platform !== "darwin") return;
let jobs;
try {
jobs = await findForeignLaunchdJobs(env);
} catch (error) {
note(`Could not inspect foreign launchd jobs: ${sanitizeTerminalText(formatErrorMessage(error))}. No jobs were removed.`, "Foreign launchd jobs (macOS)");
return;
}
if (jobs.length === 0) return;
const lines = [formatForeignLaunchdJobs(jobs)];
const restarts = readGatewayForcedRestartSummary(env);
if (restarts.count > 0) lines.push(`${restarts.count} external forced Gateway restart(s) in the last ${Math.round(restarts.windowMs / 6e4)} minutes. Listed lifecycle jobs may be responsible; this is not proof of attribution.`);
const candidates = jobs.filter((job) => job.safeToRemove);
if (candidates.length > 0) lines.push(`Run ${formatCliCommand("openclaw doctor --fix", env)} to remove confirmed stray Gateway lifecycle jobs.`);
note(lines.join("\n"), "Foreign launchd jobs (macOS)");
if (options.repair !== true || candidates.length === 0) return;
if (!isDefaultInstallIdentity(env) || isServiceRepairDeferred(resolveServiceRepairPolicy(env)) || !await shouldManageGatewayService(env)) {
runtime.log("Foreign launchd job repair skipped: this Doctor invocation does not own service repair or an update is in progress. No jobs were removed.");
return;
}
for (const job of candidates) try {
const result = await repairForeignLaunchdJob(job, env);
runtime.log(result.removed ? result.detail : `Removal not confirmed for launchd job ${job.label}: ${result.detail}`);
} catch (error) {
runtime.log(`Removal not confirmed for launchd job ${job.label}: ${sanitizeTerminalText(formatErrorMessage(error))}`);
}
}
//#endregion
export { noteMacForeignLaunchdJobs };