@@ -62,6 +62,39 @@ type BundledHealthCheckSelection = {
6262
6363type BundledHealthCheckPluginStateMode = "direct" | "deferred" | "isolated" ;
6464
65+ type BundledHealthCheckParams = {
66+ cfg : OpenClawConfig ;
67+ cwd ?: string ;
68+ env ?: NodeJS . ProcessEnv ;
69+ runWithPluginStateSnapshot ?: < T > (
70+ run : ( pluginMetadataEnv : NodeJS . ProcessEnv ) => Promise < T > ,
71+ ) => Promise < T > ;
72+ } ;
73+
74+ function defineHealthCheckRegistration (
75+ register : ( params : BundledHealthCheckParams , registerCheck : typeof registerHealthCheck ) => void ,
76+ updateReadiness ?: "post-plugin" ,
77+ ) {
78+ // Owners retain callback and check identities when refreshing their registration state.
79+ // Declare phase ownership before loading their implementation, then carry it onto each check.
80+ const registerCheck = updateReadiness
81+ ? ( check : Parameters < typeof registerHealthCheck > [ 0 ] ) =>
82+ registerHealthCheck ( Object . assign ( check , { updateReadiness } ) )
83+ : registerHealthCheck ;
84+ return {
85+ updateReadiness,
86+ register : ( params : BundledHealthCheckParams ) => register ( params , registerCheck ) ,
87+ } ;
88+ }
89+
90+ const HEALTH_CHECK_REGISTRATIONS = [
91+ defineHealthCheckRegistration ( registerMemoryCoreHealthChecks , "post-plugin" ) ,
92+ defineHealthCheckRegistration ( registerCodexHealthChecks ) ,
93+ defineHealthCheckRegistration ( registerPolicyHealthChecks ) ,
94+ defineHealthCheckRegistration ( registerCuaHealthChecks ) ,
95+ defineHealthCheckRegistration ( registerBundledWorkerProviderHealthChecks ) ,
96+ ] ;
97+
6598function loadMemoryCoreHealthApi ( ) : BundledHealthApi {
6699 return loadBundledPluginPublicArtifactModuleSync < BundledHealthApi > ( {
67100 dirName : "memory-core" ,
@@ -100,18 +133,28 @@ export function resolveBundledHealthCheckPluginStateMode(
100133}
101134
102135/** Registers bundled health checks that are explicitly enabled by config and owner policy. */
103- export function registerBundledHealthChecks ( params : {
104- cfg : OpenClawConfig ;
105- cwd ?: string ;
106- env ?: NodeJS . ProcessEnv ;
107- runWithPluginStateSnapshot ?: < T > (
108- run : ( pluginMetadataEnv : NodeJS . ProcessEnv ) => Promise < T > ,
109- ) => Promise < T > ;
110- } ) : void {
136+ export function registerBundledHealthChecks (
137+ params : BundledHealthCheckParams & { updateReadiness ?: "post-plugin" } ,
138+ ) : void {
139+ for ( const registration of HEALTH_CHECK_REGISTRATIONS ) {
140+ if (
141+ params . updateReadiness !== undefined &&
142+ registration . updateReadiness !== params . updateReadiness
143+ ) {
144+ continue ;
145+ }
146+ registration . register ( params ) ;
147+ }
148+ }
149+
150+ function registerMemoryCoreHealthChecks (
151+ params : BundledHealthCheckParams ,
152+ registerCheck : typeof registerHealthCheck ,
153+ ) : void {
111154 const env = params . env ?? process . env ;
112155 loadMemoryCoreHealthApi ( ) . registerMemoryCoreDoctorChecks ?.( {
113156 getHealthCheck,
114- registerHealthCheck,
157+ registerHealthCheck : registerCheck ,
115158 async inspectEmbeddingProviderSetup ( providerParams ) {
116159 const inspect = async ( pluginMetadataEnv : NodeJS . ProcessEnv ) => {
117160 const manifestRegistry : PluginManifestRegistry =
@@ -133,6 +176,13 @@ export function registerBundledHealthChecks(params: {
133176 } ,
134177 memoryCoreActive : isMemoryCoreActive ( params . cfg ) ,
135178 } ) ;
179+ }
180+
181+ function registerCodexHealthChecks (
182+ params : BundledHealthCheckParams ,
183+ registerCheck : typeof registerHealthCheck ,
184+ ) : void {
185+ const env = params . env ?? process . env ;
136186 if ( shouldRegisterCodexManagedHealth ( params . cfg ) ) {
137187 const registry = loadPluginManifestRegistryForPluginRegistry ( {
138188 config : params . cfg ,
@@ -157,28 +207,43 @@ export function registerBundledHealthChecks(params: {
157207 pluginRoot : owner . rootDir ,
158208 artifactBasename : "api.js" ,
159209 origin : owner . origin === "bundled" ? "bundled" : "global" ,
160- } ) . registerCodexManagedAppServerDoctorChecks ( { getHealthCheck, registerHealthCheck } ) ;
210+ } ) . registerCodexManagedAppServerDoctorChecks ( {
211+ getHealthCheck,
212+ registerHealthCheck : registerCheck ,
213+ } ) ;
161214 }
162215 }
216+ }
217+
218+ function registerPolicyHealthChecks (
219+ params : BundledHealthCheckParams ,
220+ registerCheck : typeof registerHealthCheck ,
221+ ) : void {
163222 if ( shouldRegisterPolicyHealth ( params ) ) {
164223 loadBundledPluginPublicArtifactModuleSync < BundledHealthApi > ( {
165224 dirName : "policy" ,
166225 artifactBasename : "api.js" ,
167- } ) . registerPolicyDoctorChecks ?.( { registerHealthCheck } ) ;
226+ } ) . registerPolicyDoctorChecks ?.( { registerHealthCheck : registerCheck } ) ;
168227 }
228+ }
229+
230+ function registerCuaHealthChecks (
231+ params : BundledHealthCheckParams ,
232+ registerCheck : typeof registerHealthCheck ,
233+ ) : void {
169234 if ( shouldRegisterPluginHealth ( params . cfg , "cua-computer" ) ) {
170235 loadBundledPluginPublicArtifactModuleSync < BundledHealthApi > ( {
171236 dirName : "cua-computer" ,
172237 artifactBasename : "api.js" ,
173- } ) . registerCuaDriverDoctorChecks ?.( { registerHealthCheck } ) ;
238+ } ) . registerCuaDriverDoctorChecks ?.( { registerHealthCheck : registerCheck } ) ;
174239 }
175- registerBundledWorkerProviderHealthChecks ( params , env ) ;
176240}
177241
178242function registerBundledWorkerProviderHealthChecks (
179- params : { cfg : OpenClawConfig ; cwd ?: string } ,
180- env : NodeJS . ProcessEnv ,
243+ params : BundledHealthCheckParams ,
244+ registerCheck : typeof registerHealthCheck ,
181245) : void {
246+ const env = params . env ?? process . env ;
182247 const providerIds = collectConfiguredWorkerProviderIds ( params . cfg ) ;
183248 if ( providerIds . length === 0 ) {
184249 return ;
@@ -191,7 +256,10 @@ function registerBundledWorkerProviderHealthChecks(
191256 loadBundledPluginPublicArtifactModuleFromCandidatesSync < WorkerProviderHealthApi > ( {
192257 dirName : pluginId ,
193258 artifactCandidates : [ "doctor-health-api.js" ] ,
194- } ) ?. registerWorkerProviderDoctorChecks ?.( { getHealthCheck, registerHealthCheck } ) ;
259+ } ) ?. registerWorkerProviderDoctorChecks ?.( {
260+ getHealthCheck,
261+ registerHealthCheck : registerCheck ,
262+ } ) ;
195263 }
196264}
197265
0 commit comments