refactor(commands): share cleanup plan resolver

This commit is contained in:
Peter Steinberger
2026-02-15 17:49:30 +00:00
parent 1f1e97674f
commit 813b96a804
3 changed files with 35 additions and 36 deletions

View File

@@ -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 };
}

View File

@@ -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) {

View File

@@ -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) {