openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 2.96 kB
JavaScript
import{t as appendConfigPathSegment}from"./dot-path-B1bYAWM5.mjs";import{r as resolveStateDir}from"./state-dir-BwIClCab.mjs";import{T as resolveOAuthDir,l as isNixMode,m as resolveConfigPath}from"./paths-D_FOvGon.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{r as formatConfigIssueSummary}from"./issue-format-CeCSO2Ku.mjs";import{m as readSourceConfigBestEffort,s as readConfigFileSnapshot}from"./io.runtime-BvSeVFIY.mjs";import"./config-DkZ8y8Gv.mjs";import{n as resolveGatewayService}from"./service-Bz63n2ee.mjs";import{t as buildCleanupPlan}from"./cleanup-utils-OK0KVVTl.mjs";
//!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})}}async function resolveCleanupPlanForDryRun(){return buildCleanupPlanForConfig(await readSourceConfigBestEffort())}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)}
//!src/commands/cleanup-service.ts
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}export{resolveCleanupPlanForDryRun as n,resolveCleanupPlanForRemoval as r,stopGatewayForCleanup as t};