perf(plugins): lazy-load setup surfaces

This commit is contained in:
Peter Steinberger
2026-03-15 18:46:22 -07:00
parent de6666b895
commit fb991e6f31
30 changed files with 443 additions and 16 deletions

View File

@@ -91,6 +91,8 @@ describe("registerPreActionHooks", () => {
program.command("agents").action(() => {});
program.command("configure").action(() => {});
program.command("onboard").action(() => {});
const channels = program.command("channels");
channels.command("add").action(() => {});
program
.command("update")
.command("status")
@@ -167,6 +169,31 @@ describe("registerPreActionHooks", () => {
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledWith({ scope: "all" });
});
it("keeps onboarding and channels add manifest-first", async () => {
await runPreAction({
parseArgv: ["onboard"],
processArgv: ["node", "openclaw", "onboard"],
});
expect(ensureConfigReadyMock).toHaveBeenCalledWith({
runtime: runtimeMock,
commandPath: ["onboard"],
});
expect(ensurePluginRegistryLoadedMock).not.toHaveBeenCalled();
vi.clearAllMocks();
await runPreAction({
parseArgv: ["channels", "add"],
processArgv: ["node", "openclaw", "channels", "add"],
});
expect(ensureConfigReadyMock).toHaveBeenCalledWith({
runtime: runtimeMock,
commandPath: ["channels", "add"],
});
expect(ensurePluginRegistryLoadedMock).not.toHaveBeenCalled();
});
it("skips help/version preaction and respects banner opt-out", async () => {
await runPreAction({
parseArgv: ["status"],

View File

@@ -32,7 +32,6 @@ const PLUGIN_REQUIRED_COMMANDS = new Set([
"directory",
"agents",
"configure",
"onboard",
"status",
"health",
]);
@@ -72,15 +71,19 @@ function resolvePluginRegistryScope(commandPath: string[]): "channels" | "all" {
}
function shouldLoadPluginsForCommand(commandPath: string[], argv: string[]): boolean {
if (!PLUGIN_REQUIRED_COMMANDS.has(commandPath[0])) {
const [primary, secondary] = commandPath;
if (!primary || !PLUGIN_REQUIRED_COMMANDS.has(primary)) {
return false;
}
if ((commandPath[0] === "status" || commandPath[0] === "health") && hasFlag(argv, "--json")) {
if ((primary === "status" || primary === "health") && hasFlag(argv, "--json")) {
return false;
}
// Onboarding/setup should stay manifest-first and load selected plugins on demand.
if (primary === "onboard" || (primary === "channels" && secondary === "add")) {
return false;
}
return true;
}
function getRootCommand(command: Command): Command {
let current = command;
while (current.parent) {
@@ -148,6 +151,7 @@ export function registerPreActionHooks(program: Command, programVersion: string)
...(suppressDoctorStdout ? { suppressDoctorStdout: true } : {}),
});
// Load plugins for commands that need channel access
if (shouldLoadPluginsForCommand(commandPath, argv)) {
if (shouldLoadPluginsForCommand(commandPath, argv)) {
const { ensurePluginRegistryLoaded } = await loadPluginRegistryModule();
ensurePluginRegistryLoaded({ scope: resolvePluginRegistryScope(commandPath) });