Skip to content

Commit b5a7bc2

Browse files
authored
docs(cli): explain reserved catalog roots and drop stale entries (#118040)
* docs(cli): explain reserved catalog roots and drop stale entries * test(cli): use plugin registration for catalog guard * test(cli): load memory CLI through public facade * test(cli): keep plugin catalog paths owner-scoped
1 parent 6e87d3b commit b5a7bc2

2 files changed

Lines changed: 77 additions & 7 deletions

File tree

‎src/cli/command-catalog.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
150150
exact: true,
151151
policy: { configGuard: "skip", loadPlugins: "never", networkProxy: "bypass" },
152152
},
153-
{
154-
commandPath: ["config", "models"],
155-
exact: true,
156-
policy: { configGuard: "skip", loadPlugins: "never", networkProxy: "bypass" },
157-
},
158153
{
159154
commandPath: ["migrate"],
160155
policy: { configGuard: "skip", loadPlugins: "never", networkProxy: "bypass" },
@@ -201,7 +196,6 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
201196
{ commandPath: ["gateway", "call"], exact: true, policy: { networkProxy: "bypass" } },
202197
{ commandPath: ["gateway", "diagnostics"], exact: true, policy: { networkProxy: "bypass" } },
203198
{ commandPath: ["gateway", "discover"], exact: true, policy: { networkProxy: "bypass" } },
204-
{ commandPath: ["gateway", "export"], exact: true, policy: { networkProxy: "bypass" } },
205199
{
206200
commandPath: ["gateway", "health"],
207201
exact: true,
@@ -331,10 +325,14 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
331325
route: { id: "tasks-list" },
332326
},
333327
{
328+
// This unregistered root is reserved so plugin registration cannot claim it;
329+
// the catalog entry preserves its startup policy.
334330
commandPath: ["tool"],
335331
policy: { loadPlugins: "never", ensureCliPath: false, networkProxy: "bypass" },
336332
},
337333
{
334+
// This unregistered root is reserved so plugin registration cannot claim it;
335+
// the catalog entry preserves its startup policy.
338336
commandPath: ["tools"],
339337
policy: { loadPlugins: "never", ensureCliPath: false, networkProxy: "bypass" },
340338
},

‎src/cli/program/root-command-descriptions.test.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22
// registered Commander commands. Keep those user-facing descriptions aligned.
33
import { Command } from "commander";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+
import { cliCommandCatalog } from "../command-catalog.js";
6+
import { isReservedNonPluginCommandRoot } from "../command-registration-policy.js";
57
import { collectShellCompletionCommandTree } from "../completion-command-tree.js";
68
import { getCoreCliCommandNames, registerCoreCliByName } from "./command-registry-core.js";
79
import { createProgramContext } from "./context.js";
810
import { getCoreCliCommandDescriptors } from "./core-command-descriptors.js";
9-
import { registerSubCliByName } from "./register.subclis.js";
11+
import { registerSubCliByName, registerSubCliCommands } from "./register.subclis.js";
1012
import { getSubCliEntries } from "./subcli-descriptors.js";
1113

14+
const RESERVED_CATALOG_ROOTS = {
15+
tool: "reserved so plugin registration cannot claim this unregistered root",
16+
tools: "reserved so plugin registration cannot claim this unregistered root",
17+
} as const;
18+
19+
const PLUGIN_CATALOG_PATHS = {
20+
"memory search": "registered and covered by the memory-core plugin",
21+
"memory status": "registered and covered by the memory-core plugin",
22+
} as const;
23+
1224
const JSON_NOT_APPLICABLE = {
1325
namespaces: {
1426
reason: "command group only; reporting subcommands declare JSON output individually",
@@ -242,6 +254,16 @@ function supportsJsonOutput(path: string, command: Command): boolean {
242254
);
243255
}
244256

257+
function collectRegisteredCommandPaths(...programs: Command[]): Set<string> {
258+
return new Set(
259+
programs.flatMap((program) =>
260+
collectShellCompletionCommandTree(program).descendants.flatMap((context) =>
261+
context.pathVariants.map((path) => path.join(" ")),
262+
),
263+
),
264+
);
265+
}
266+
245267
describe("root command descriptions", () => {
246268
beforeEach(() => {
247269
vi.stubEnv("OPENCLAW_ENABLE_PRIVATE_QA_CLI", "");
@@ -285,6 +307,56 @@ describe("root command descriptions", () => {
285307
expect(mismatches, "root help vs registered command description drift").toEqual([]);
286308
});
287309

310+
it("keeps startup policy catalog paths registered or explicitly reserved", async () => {
311+
const program = await registerAllBuiltInCommands();
312+
313+
// Private QA is a lazy source-checkout command. Its root placeholder proves
314+
// registration without importing the private build omitted from normal dist.
315+
vi.stubEnv("OPENCLAW_ENABLE_PRIVATE_QA_CLI", "1");
316+
const lazyProgram = new Command().name("openclaw");
317+
registerSubCliCommands(lazyProgram, ["node", "openclaw", "--help"]);
318+
319+
const registeredPaths = collectRegisteredCommandPaths(program, lazyProgram);
320+
const catalogPaths = new Set(cliCommandCatalog.map((entry) => entry.commandPath.join(" ")));
321+
const reservedPaths = new Set(Object.keys(RESERVED_CATALOG_ROOTS));
322+
const pluginPaths = new Set(Object.keys(PLUGIN_CATALOG_PATHS));
323+
324+
expect(
325+
Object.entries({ ...RESERVED_CATALOG_ROOTS, ...PLUGIN_CATALOG_PATHS }).filter(
326+
([, reason]) => reason.trim().length === 0,
327+
),
328+
"every catalog exception must document why core has no command",
329+
).toEqual([]);
330+
331+
const missing = [...catalogPaths].filter(
332+
(path) => !registeredPaths.has(path) && !reservedPaths.has(path) && !pluginPaths.has(path),
333+
);
334+
expect(missing, "catalog entries with no registered command or reserved-root decision").toEqual(
335+
[],
336+
);
337+
338+
const staleReservedRoots = [...reservedPaths].filter(
339+
(path) => !catalogPaths.has(path) || !isReservedNonPluginCommandRoot(path),
340+
);
341+
expect(
342+
staleReservedRoots,
343+
"reserved catalog roots must remain cataloged and blocked from plugin registration",
344+
).toEqual([]);
345+
346+
const stalePluginPaths = [...pluginPaths].filter(
347+
(path) => !catalogPaths.has(path) || registeredPaths.has(path),
348+
);
349+
expect(stalePluginPaths, "plugin catalog paths must remain plugin-owned").toEqual([]);
350+
351+
const reservedRootsThatNowRegister = [...reservedPaths].filter((path) =>
352+
registeredPaths.has(path),
353+
);
354+
expect(
355+
reservedRootsThatNowRegister,
356+
"registered commands must leave the reserved-root exception list",
357+
).toEqual([]);
358+
});
359+
288360
it("classifies every built-in command as JSON output or explicitly not applicable", async () => {
289361
const program = await registerAllBuiltInCommands();
290362
const contexts = collectShellCompletionCommandTree(program).descendants;

0 commit comments

Comments
 (0)