Files
openclaw/src/cli/plugin-registry-loader.ts
T
Vincent Koc 6293b54250 perf(cli): split plugin registry startup timing (#119318)
* perf(cli): split plugin registry startup timing

Punchcard-Session: coral-workshop-workshop-3f

* test(cli): use managed temp directory cleanup

Punchcard-Session: coral-workshop-workshop-3f
2026-08-05 04:08:35 +08:00

43 lines
1.6 KiB
TypeScript

// Lazy plugin-registry loader for CLI commands that need plugin command/capability metadata.
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { loggingState } from "../logging/state.js";
import { createLazyImportLoader } from "../shared/lazy-promise.js";
import type { CliPluginRegistryScope } from "./command-catalog.js";
import { measureCliCommandStartup } from "./command-startup-timing.js";
const pluginRegistryModuleLoader = createLazyImportLoader(() => import("./plugin-registry.js"));
function loadPluginRegistryModule() {
return pluginRegistryModuleLoader.load();
}
/** Load the CLI plugin registry and optionally route activation logs to stderr. */
export async function ensureCliPluginRegistryLoaded(params: {
scope: CliPluginRegistryScope;
routeLogsToStderr?: boolean;
config?: OpenClawConfig;
activationSourceConfig?: OpenClawConfig;
}) {
const { ensurePluginRegistryLoaded } = await measureCliCommandStartup(
"plugin-registry-module-import",
loadPluginRegistryModule,
);
await measureCliCommandStartup("plugin-registry-runtime-load", () => {
const previousForceStderr = loggingState.forceConsoleToStderr;
if (params.routeLogsToStderr) {
loggingState.forceConsoleToStderr = true;
}
try {
ensurePluginRegistryLoaded({
scope: params.scope,
...(params.config ? { config: params.config } : {}),
...(params.activationSourceConfig
? { activationSourceConfig: params.activationSourceConfig }
: {}),
});
} finally {
loggingState.forceConsoleToStderr = previousForceStderr;
}
});
}