diff --git a/src/commands/cleanup-plan.ts b/src/commands/cleanup-plan.ts new file mode 100644 index 0000000000..534db21482 --- /dev/null +++ b/src/commands/cleanup-plan.ts @@ -0,0 +1,25 @@ +import type { OpenClawConfig } from "../config/config.js"; +import { + loadConfig, + resolveConfigPath, + resolveOAuthDir, + resolveStateDir, +} from "../config/config.js"; +import { buildCleanupPlan } from "./cleanup-utils.js"; + +export function resolveCleanupPlanFromDisk(): { + cfg: OpenClawConfig; + stateDir: string; + configPath: string; + oauthDir: string; + configInsideState: boolean; + oauthInsideState: boolean; + workspaceDirs: string[]; +} { + const cfg = loadConfig(); + const stateDir = resolveStateDir(); + const configPath = resolveConfigPath(); + const oauthDir = resolveOAuthDir(); + const plan = buildCleanupPlan({ cfg, stateDir, configPath, oauthDir }); + return { cfg, stateDir, configPath, oauthDir, ...plan }; +} diff --git a/src/commands/reset.ts b/src/commands/reset.ts index e2f791994e..fd6203c0af 100644 --- a/src/commands/reset.ts +++ b/src/commands/reset.ts @@ -1,16 +1,11 @@ import { cancel, confirm, isCancel, select } from "@clack/prompts"; import type { RuntimeEnv } from "../runtime.js"; import { formatCliCommand } from "../cli/command-format.js"; -import { - isNixMode, - loadConfig, - resolveConfigPath, - resolveOAuthDir, - resolveStateDir, -} from "../config/config.js"; +import { isNixMode } from "../config/config.js"; import { resolveGatewayService } from "../daemon/service.js"; import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.js"; -import { buildCleanupPlan, listAgentSessionDirs, removePath } from "./cleanup-utils.js"; +import { resolveCleanupPlanFromDisk } from "./cleanup-plan.js"; +import { listAgentSessionDirs, removePath } from "./cleanup-utils.js"; export type ResetScope = "config" | "config+creds+sessions" | "full"; @@ -114,16 +109,8 @@ export async function resetCommand(runtime: RuntimeEnv, opts: ResetOptions) { } const dryRun = Boolean(opts.dryRun); - const cfg = loadConfig(); - const stateDir = resolveStateDir(); - const configPath = resolveConfigPath(); - const oauthDir = resolveOAuthDir(); - const { configInsideState, oauthInsideState, workspaceDirs } = buildCleanupPlan({ - cfg, - stateDir, - configPath, - oauthDir, - }); + const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } = + resolveCleanupPlanFromDisk(); if (scope !== "config") { if (dryRun) { diff --git a/src/commands/uninstall.ts b/src/commands/uninstall.ts index e0754514e8..333d664112 100644 --- a/src/commands/uninstall.ts +++ b/src/commands/uninstall.ts @@ -1,17 +1,12 @@ import { cancel, confirm, isCancel, multiselect } from "@clack/prompts"; import path from "node:path"; import type { RuntimeEnv } from "../runtime.js"; -import { - isNixMode, - loadConfig, - resolveConfigPath, - resolveOAuthDir, - resolveStateDir, -} from "../config/config.js"; +import { isNixMode } from "../config/config.js"; import { resolveGatewayService } from "../daemon/service.js"; import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.js"; import { resolveHomeDir } from "../utils.js"; -import { buildCleanupPlan, removePath } from "./cleanup-utils.js"; +import { resolveCleanupPlanFromDisk } from "./cleanup-plan.js"; +import { removePath } from "./cleanup-utils.js"; type UninstallScope = "service" | "state" | "workspace" | "app"; @@ -157,16 +152,8 @@ export async function uninstallCommand(runtime: RuntimeEnv, opts: UninstallOptio } const dryRun = Boolean(opts.dryRun); - const cfg = loadConfig(); - const stateDir = resolveStateDir(); - const configPath = resolveConfigPath(); - const oauthDir = resolveOAuthDir(); - const { configInsideState, oauthInsideState, workspaceDirs } = buildCleanupPlan({ - cfg, - stateDir, - configPath, - oauthDir, - }); + const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } = + resolveCleanupPlanFromDisk(); if (scopes.has("service")) { if (dryRun) {