UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

97 lines (96 loc) • 3.65 kB
import { t as appendConfigPathSegment } from "./dot-path-BJ4tyWKJ.mjs"; import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import { T as resolveOAuthDir, l as isNixMode, m as resolveConfigPath } from "./paths-DAcAg5aV.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { r as formatConfigIssueSummary } from "./issue-format-WaYQX-7p.mjs"; import { m as readSourceConfigBestEffort, s as readConfigFileSnapshot } from "./io.runtime-DsJ2dLCQ.mjs"; import "./config-CMA-J084.mjs"; import { n as resolveGatewayService } from "./service-hQiIzcTo.mjs"; import { t as buildCleanupPlan } from "./cleanup-utils-Dk4WWDhW.mjs"; //#region src/commands/cleanup-plan.ts function buildCleanupPlanForConfig(e) { const t = resolveStateDir(); const n = resolveConfigPath(); const r = resolveOAuthDir(); return { cfg: e, stateDir: t, configPath: n, oauthDir: r, ...buildCleanupPlan({ cfg: e, stateDir: t, configPath: n, oauthDir: r }) }; } /** Build a read-only cleanup preview without recording config health state. */ async function resolveCleanupPlanForDryRun() { return buildCleanupPlanForConfig(await readSourceConfigBestEffort()); } /** Resolve destructive cleanup inputs without mutating the state being guarded. */ async function resolveCleanupPlanForRemoval(e) { const t = await readConfigFileSnapshot({ observe: false, pluginValidation: "core-only" }); const n = /* @__PURE__ */ new Set(["agents.defaults.workspace", ...Object.keys(t.runtimeConfig.agents?.entries ?? {}).map((e) => `${appendConfigPathSegment("agents.entries", e)}.workspace`)]); const r = t.warnings.filter((e) => n.has(e.path)); if (!t.valid || r.length > 0) { const n = t.valid ? r : t.issues; const i = formatConfigIssueSummary(n) ?? "configuration read failed"; e.error(`Cannot safely remove OpenClaw state because workspace configuration could not be resolved: ${i}. Fix the configuration and retry.`); return; } return buildCleanupPlanForConfig(t.runtimeConfig); } //#endregion //#region src/commands/cleanup-service.ts /** Settle managed service teardown before reset or uninstall may remove user data. */ async function stopGatewayForCleanup(e, t) { const n = t === "uninstall"; if (isNixMode) { if (n) e.error(`Nix mode detected; service uninstall is disabled. Manage the service through your Nix profile instead, then run ${formatCliCommand("openclaw status")} to verify.`); return !n; } const reportFailure = (t, r, i) => { e.error(n ? `${t}: ${formatErrorMessage(r)}. Run ${formatCliCommand("openclaw gateway status --deep")} ${i}.` : `${t}: ${String(r)}`); }; const r = resolveGatewayService(); let i; try { if (n && await r.isAbsent?.({ env: process.env })) { e.error("No Gateway service to remove. Continuing uninstall."); return true; } i = await r.isLoaded({ env: process.env }); } catch (e) { reportFailure("Gateway service check failed", e, "for service diagnostics"); return false; } let a = true; if (i) try { await r.stop({ env: process.env, stdout: process.stdout }); } catch (e) { a = false; reportFailure("Gateway stop failed", e, "before retrying uninstall"); } else if (n) e.log(`Gateway service ${r.notLoadedText}.`); if (n) try { await r.uninstall({ env: process.env, stdout: process.stdout }); } catch (e) { reportFailure("Gateway uninstall failed", e, "for the service state"); return false; } return a; } //#endregion export { resolveCleanupPlanForDryRun as n, resolveCleanupPlanForRemoval as r, stopGatewayForCleanup as t };