diff --git a/src/cli/program/root-help.test.ts b/src/cli/program/root-help.test.ts index 869ba8a3c4f..69e86ae4f82 100644 --- a/src/cli/program/root-help.test.ts +++ b/src/cli/program/root-help.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { renderRootHelpText } from "./root-help.js"; const getPluginCliCommandDescriptorsMock = vi.fn( @@ -53,6 +53,10 @@ vi.mock("../../plugins/cli.js", () => ({ })); describe("root help", () => { + beforeEach(() => { + getPluginCliCommandDescriptorsMock.mockClear(); + }); + it("passes isolated config and env through to plugin CLI descriptor loading", async () => { const config = { agents: { @@ -71,11 +75,17 @@ describe("root help", () => { }); it("includes plugin CLI descriptors alongside core and sub-CLI commands", async () => { - const text = await renderRootHelpText(); + const text = await renderRootHelpText({ includePluginDescriptors: true }); expect(text).toContain("status"); expect(text).toContain("config"); expect(text).toContain("matrix"); expect(text).toContain("Matrix channel utilities"); }); + + it("does not load plugin CLI descriptors by default", async () => { + await renderRootHelpText(); + + expect(getPluginCliCommandDescriptorsMock).not.toHaveBeenCalled(); + }); }); diff --git a/src/cli/program/root-help.ts b/src/cli/program/root-help.ts index dfb7bdf0ef3..2b1962ce191 100644 --- a/src/cli/program/root-help.ts +++ b/src/cli/program/root-help.ts @@ -14,6 +14,7 @@ import { getSubCliEntries } from "./subcli-descriptors.js"; export type RootHelpRenderOptions = Pick & { config?: OpenClawConfig; env?: NodeJS.ProcessEnv; + includePluginDescriptors?: boolean; }; async function buildRootHelpProgram(renderOptions?: RootHelpRenderOptions): Promise { @@ -25,14 +26,19 @@ async function buildRootHelpProgram(renderOptions?: RootHelpRenderOptions): Prom agentChannelOptions: "", }); + const pluginDescriptors = + renderOptions?.includePluginDescriptors === true || renderOptions?.config + ? await getPluginCliCommandDescriptors(renderOptions.config, renderOptions.env, { + pluginSdkResolution: renderOptions.pluginSdkResolution, + }) + : []; + addCommandDescriptorsToProgram( program, collectUniqueCommandDescriptors([ getCoreCliCommandDescriptors(), getSubCliEntries(), - await getPluginCliCommandDescriptors(renderOptions?.config, renderOptions?.env, { - pluginSdkResolution: renderOptions?.pluginSdkResolution, - }), + pluginDescriptors, ]), );