File size: 3,543 Bytes
d197cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import type { PluginRuntimeApplication } from "../../packages/gateway-protocol/src/schema/plugins.js";
import type { unsetConfiguredMcpServer } from "../agents/mcp-config-mutation.js";
import type { listConfiguredMcpServers } from "../config/mcp-config.js";
import type { purgeAgentSessionStoreEntries } from "../config/sessions/cleanup-service.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import type { OpenClawStateDatabaseOptions } from "../state/openclaw-state-db.js";
import type { ClawCronGateway } from "./cron.js";
import type { ClawTrashPath, RemovedWorkspaceFile } from "./lifecycle-delete-support.js";
import type { ClawMonitorCleanupGateway } from "./monitor-cleanup-contract.js";
import type { ClawPackageRemovalGateway } from "./package-remove-contract.js";
import type {
  ClawPackageRemovalResult,
  ClawReferencedCleanup,
  PackageRemovalDeps,
} from "./package-remove.js";
import { CLAW_OUTPUT_STABILITY } from "./types.js";

export const CLAW_REMOVE_PLAN_SCHEMA_VERSION = "openclaw.clawRemovePlan.v1" as const;

export type ClawRemovePlanAction = {
  kind:
    | "agent"
    | "configBinding"
    | "agentAllow"
    | "workspace"
    | "agentState"
    | "sessionIndex"
    | "sessionTranscripts"
    | "scheduledJob"
    | "workspaceFile"
    | "bootstrap"
    | "packageRef"
    | "mcpServer"
    | "cronJob"
    | "installRecord";
  id: string;
  action: "remove" | "delete" | "retain" | "release" | "uninstall" | "trash";
  target: string;
  blocked: boolean;
  reason?: string;
  details?: Record<string, unknown>;
};

export type ClawRemovePlan = {
  schemaVersion: typeof CLAW_REMOVE_PLAN_SCHEMA_VERSION;
  stability: typeof CLAW_OUTPUT_STABILITY;
  dryRun: true;
  mutationAllowed: false;
  planIntegrity: string;
  target: string;
  agentId?: string;
  actions: ClawRemovePlanAction[];
  blockers: Array<{ code: string; message: string }>;
};

type RemovedCronJob = {
  manifestId: string;
  schedulerJobId?: string;
  action: "removed" | "error";
  message?: string;
};

export type RemovedMcpServer = {
  name: string;
  action: "removed" | "missing" | "released" | "error";
  message?: string;
};

export type ClawRemovePlanOptions = OpenClawStateDatabaseOptions & {
  config?: OpenClawConfig;
  sourceMcpServers?: Record<string, Record<string, unknown>>;
  listMcpServers?: typeof listConfiguredMcpServers;
  packageDeps?: PackageRemovalDeps;
  referencedCleanup?: ClawReferencedCleanup;
  monitorGateway?: ClawMonitorCleanupGateway;
};

export type ClawRemoveApplyOptions = ClawRemovePlanOptions & {
  packageGateway?: ClawPackageRemovalGateway;
  purgeSessions?: (
    ...args: Parameters<typeof purgeAgentSessionStoreEntries>
  ) => Promise<boolean | void>;
  trashPath?: ClawTrashPath;
  consentPlanIntegrity?: string;
  unsetMcpServer?: typeof unsetConfiguredMcpServer;
  cronGateway?: Pick<ClawCronGateway, "get" | "remove">;
};

export const CLAW_REMOVE_RESULT_SCHEMA_VERSION = "openclaw.clawRemoveResult.v1" as const;
export type ClawRemoveResult = {
  schemaVersion: typeof CLAW_REMOVE_RESULT_SCHEMA_VERSION;
  stability: typeof CLAW_OUTPUT_STABILITY;
  dryRun: false;
  status: "complete" | "partial";
  agentId: string;
  agentRemoved: boolean;
  bootstrap?: RemovedWorkspaceFile;
  workspaceFiles: RemovedWorkspaceFile[];
  packages: ClawPackageRemovalResult[];
  mcpServers: RemovedMcpServer[];
  cronJobs: RemovedCronJob[];
  packageRefsReleased: number;
  pluginRuntime?: PluginRuntimeApplication;
  warnings?: string[];
  error?: { code: string; message: string };
};