Skip to content

Commit 9f7b652

Browse files
refactor(claws): extract lifecycle state contracts
1 parent d593dc8 commit 9f7b652

2 files changed

Lines changed: 107 additions & 87 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import type { PersistedClawCronRef } from "./cron.js";
2+
import type { ClawManagedFileStatus, RemovedWorkspaceFile } from "./lifecycle-delete-support.js";
3+
import type { ClawPackageInspection, ClawPackageRemovalResult } from "./package-remove.js";
4+
import type { PersistedClawInstall } from "./provenance.js";
5+
import type { CLAW_OUTPUT_STABILITY } from "./types.js";
6+
7+
export const CLAW_STATUS_SCHEMA_VERSION = "openclaw.clawStatus.v1" as const;
8+
export const CLAW_REMOVE_PLAN_SCHEMA_VERSION = "openclaw.clawRemovePlan.v1" as const;
9+
export const CLAW_REMOVE_RESULT_SCHEMA_VERSION = "openclaw.clawRemoveResult.v1" as const;
10+
11+
export type ClawStatusRecord = {
12+
install: PersistedClawInstall;
13+
orphaned?: boolean;
14+
agentState: "present" | "modified" | "missing";
15+
workspaceFiles: ClawManagedFileStatus[];
16+
packages: ClawPackageInspection[];
17+
cronJobs: PersistedClawCronRef[];
18+
};
19+
20+
export type ClawStatusResult = {
21+
schemaVersion: typeof CLAW_STATUS_SCHEMA_VERSION;
22+
stability: typeof CLAW_OUTPUT_STABILITY;
23+
target?: string;
24+
records: ClawStatusRecord[];
25+
summary: {
26+
claws: number;
27+
partial: number;
28+
missingAgents: number;
29+
driftedFiles: number;
30+
packageRefs: number;
31+
missingPackages: number;
32+
driftedPackages: number;
33+
incompletePackages: number;
34+
cronRefs: number;
35+
unresolvedCronRefs: number;
36+
};
37+
};
38+
39+
export type ClawRemovePlanAction = {
40+
kind:
41+
| "agent"
42+
| "configBinding"
43+
| "agentAllow"
44+
| "workspace"
45+
| "agentState"
46+
| "sessionIndex"
47+
| "sessionTranscripts"
48+
| "scheduledJob"
49+
| "workspaceFile"
50+
| "packageRef"
51+
| "cronJob"
52+
| "installRecord";
53+
id: string;
54+
action: "remove" | "delete" | "retain" | "release" | "uninstall" | "trash";
55+
target: string;
56+
blocked: boolean;
57+
reason?: string;
58+
details?: Record<string, unknown>;
59+
};
60+
61+
export type ClawRemovePlan = {
62+
schemaVersion: typeof CLAW_REMOVE_PLAN_SCHEMA_VERSION;
63+
stability: typeof CLAW_OUTPUT_STABILITY;
64+
dryRun: true;
65+
mutationAllowed: false;
66+
planIntegrity: string;
67+
target: string;
68+
agentId?: string;
69+
actions: ClawRemovePlanAction[];
70+
blockers: Array<{ code: string; message: string }>;
71+
};
72+
73+
export type RemovedCronJob = {
74+
manifestId: string;
75+
schedulerJobId?: string;
76+
action: "removed" | "error";
77+
message?: string;
78+
};
79+
80+
export type ClawRemoveResult = {
81+
schemaVersion: typeof CLAW_REMOVE_RESULT_SCHEMA_VERSION;
82+
stability: typeof CLAW_OUTPUT_STABILITY;
83+
dryRun: false;
84+
status: "complete" | "partial";
85+
agentId: string;
86+
agentRemoved: boolean;
87+
workspaceFiles: RemovedWorkspaceFile[];
88+
packages: ClawPackageRemovalResult[];
89+
cronJobs: RemovedCronJob[];
90+
packageRefsReleased: number;
91+
error?: { code: string; message: string };
92+
};

‎src/claws/lifecycle-state.ts‎

Lines changed: 15 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* oxlint-disable max-lines -- Resource-specific removal helpers split into owner modules in subsequent lifecycle slices. */
21
import { createHash } from "node:crypto";
32
import { stableStringify } from "../agents/stable-stringify.js";
43
import { getRuntimeConfig } from "../config/config.js";
@@ -14,7 +13,6 @@ import {
1413
markClawCronRefRemoved,
1514
readClawCronRefs,
1615
type ClawCronGateway,
17-
type PersistedClawCronRef,
1816
} from "./cron.js";
1917
import {
2018
claimClawAgentConfigRemoval,
@@ -34,111 +32,41 @@ import {
3432
removeClawWorkspaceFile,
3533
synthesizeOrphanInstall,
3634
workspaceContainsUntrackedEntries,
37-
type ClawManagedFileStatus,
3835
type ClawTrashPath,
3936
type RemovedWorkspaceFile,
4037
} from "./lifecycle-delete-support.js";
38+
import {
39+
CLAW_REMOVE_PLAN_SCHEMA_VERSION,
40+
CLAW_REMOVE_RESULT_SCHEMA_VERSION,
41+
CLAW_STATUS_SCHEMA_VERSION,
42+
type ClawRemovePlan,
43+
type ClawRemovePlanAction,
44+
type ClawRemoveResult,
45+
type ClawStatusRecord,
46+
type ClawStatusResult,
47+
type RemovedCronJob,
48+
} from "./lifecycle-state-contract.js";
4149
import { projectClawPackageRemovePlan } from "./package-remove-plan.js";
4250
import {
4351
applyClawPackageRemovals,
4452
inspectClawPackage,
4553
planClawPackageRemovals,
46-
type ClawPackageInspection,
47-
type ClawPackageRemovalResult,
4854
type ClawReferencedCleanup,
4955
type PackageRemovalDeps,
5056
} from "./package-remove.js";
5157
import {
5258
readClawInstallRecords,
5359
readClawPackageRefs,
5460
updateClawInstallRecordStatus,
55-
type PersistedClawInstall,
5661
} from "./provenance.js";
5762
import { CLAW_OUTPUT_STABILITY } from "./types.js";
5863
import { readClawWorkspaceFiles } from "./workspace.js";
5964

6065
export { ClawRemoveError } from "./lifecycle-delete-support.js";
61-
62-
const CLAW_STATUS_SCHEMA_VERSION = "openclaw.clawStatus.v1" as const;
63-
export const CLAW_REMOVE_PLAN_SCHEMA_VERSION = "openclaw.clawRemovePlan.v1" as const;
64-
export const CLAW_REMOVE_RESULT_SCHEMA_VERSION = "openclaw.clawRemoveResult.v1" as const;
65-
type ClawStatusRecord = {
66-
install: PersistedClawInstall;
67-
orphaned?: boolean;
68-
agentState: "present" | "modified" | "missing";
69-
workspaceFiles: ClawManagedFileStatus[];
70-
packages: ClawPackageInspection[];
71-
cronJobs: PersistedClawCronRef[];
72-
};
73-
type ClawStatusResult = {
74-
schemaVersion: typeof CLAW_STATUS_SCHEMA_VERSION;
75-
stability: typeof CLAW_OUTPUT_STABILITY;
76-
target?: string;
77-
records: ClawStatusRecord[];
78-
summary: {
79-
claws: number;
80-
partial: number;
81-
missingAgents: number;
82-
driftedFiles: number;
83-
packageRefs: number;
84-
missingPackages: number;
85-
driftedPackages: number;
86-
incompletePackages: number;
87-
cronRefs: number;
88-
unresolvedCronRefs: number;
89-
};
90-
};
91-
type ClawRemovePlanAction = {
92-
kind:
93-
| "agent"
94-
| "configBinding"
95-
| "agentAllow"
96-
| "workspace"
97-
| "agentState"
98-
| "sessionIndex"
99-
| "sessionTranscripts"
100-
| "scheduledJob"
101-
| "workspaceFile"
102-
| "packageRef"
103-
| "cronJob"
104-
| "installRecord";
105-
id: string;
106-
action: "remove" | "delete" | "retain" | "release" | "uninstall" | "trash";
107-
target: string;
108-
blocked: boolean;
109-
reason?: string;
110-
details?: Record<string, unknown>;
111-
};
112-
type ClawRemovePlan = {
113-
schemaVersion: typeof CLAW_REMOVE_PLAN_SCHEMA_VERSION;
114-
stability: typeof CLAW_OUTPUT_STABILITY;
115-
dryRun: true;
116-
mutationAllowed: false;
117-
planIntegrity: string;
118-
target: string;
119-
agentId?: string;
120-
actions: ClawRemovePlanAction[];
121-
blockers: Array<{ code: string; message: string }>;
122-
};
123-
type RemovedCronJob = {
124-
manifestId: string;
125-
schedulerJobId?: string;
126-
action: "removed" | "error";
127-
message?: string;
128-
};
129-
type ClawRemoveResult = {
130-
schemaVersion: typeof CLAW_REMOVE_RESULT_SCHEMA_VERSION;
131-
stability: typeof CLAW_OUTPUT_STABILITY;
132-
dryRun: false;
133-
status: "complete" | "partial";
134-
agentId: string;
135-
agentRemoved: boolean;
136-
workspaceFiles: RemovedWorkspaceFile[];
137-
packages: ClawPackageRemovalResult[];
138-
cronJobs: RemovedCronJob[];
139-
packageRefsReleased: number;
140-
error?: { code: string; message: string };
141-
};
66+
export {
67+
CLAW_REMOVE_PLAN_SCHEMA_VERSION,
68+
CLAW_REMOVE_RESULT_SCHEMA_VERSION,
69+
} from "./lifecycle-state-contract.js";
14270

14371
export async function readClawStatus(
14472
target?: string,

0 commit comments

Comments
 (0)