fix(plugins): avoid duplicate command names in CLI metadata (#130339)

This commit is contained in:
Peter Steinberger authored and GitHub committed 2026-08-26 13:25:57 -07:00
1 parent 71a7283792
commit 28f4c9efdf
4 files changed
+19 -8

No files matched your search

@@ -9,6 +9,7 @@ describe("captured plugin registration", () => {
const captured = capturePluginRegistration({
register(api) {
api.registerCli(() => {}, {
commands: [" captured-machine ", "captured-machine", "captured-extra"],
descriptors: [
{
name: "captured-machine",
@@ -21,6 +22,7 @@ describe("captured plugin registration", () => {
},
});
expect(captured.cliRegistrars[0]?.commands).toEqual(["captured-machine", "captured-extra"]);
const descriptor = captured.cliRegistrars[0]?.descriptors[0];
expect(descriptor?.machineOutput).toBe(machineOutput);
expect(
+5 -2
View File
@@ -1,5 +1,8 @@
// Captures plugin registrations for controlled registry assembly.
import { normalizeStringEntries } from "@openclaw/normalization-core/string-normalization";
import {
normalizeStringEntries,
normalizeUniqueStringEntries,
} from "@openclaw/normalization-core/string-normalization";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import type {
AgentToolResultMiddleware,
@@ -202,7 +205,7 @@ export function createCapturedPluginRegistration(params?: {
return normalized;
})
.filter((descriptor) => descriptor.name && descriptor.description);
const commands = normalizeStringEntries([
const commands = normalizeUniqueStringEntries([
...(opts?.commands ?? []),
...descriptors.map((descriptor) => descriptor.name),
]);
+7
View File
@@ -970,6 +970,7 @@ module.exports = {
id: "machine-output-cli",
register(api) {
api.registerCli(() => {}, {
commands: [" machine-output-cli ", "machine-output-cli", "additional-cli"],
descriptors: [{
name: "machine-output-cli",
description: "Machine output CLI",
@@ -979,6 +980,7 @@ module.exports = {
});
api.registerCli(() => {}, {
parentPath: ["nodes"],
commands: ["nested-machine-output", " nested-machine-output "],
descriptors: [{
name: "nested-machine-output",
description: "Nested metadata",
@@ -999,6 +1001,10 @@ module.exports = {
const metadataRegistry = await loadOpenClawPluginCliRegistry({ cache: false, config });
const fullRegistry = loadOpenClawPlugins({ cache: false, config });
for (const registry of [metadataRegistry, fullRegistry]) {
expect(registry.cliRegistrars[0]?.commands).toEqual(["machine-output-cli", "additional-cli"]);
expect(
registry.plugins.find((entry) => entry.id === "machine-output-cli")?.cliCommands,
).toEqual(["machine-output-cli", "additional-cli", "nodes nested-machine-output"]);
const resolver = registry.cliRegistrars[0]?.descriptors[0]?.machineOutput;
expect(
resolver?.({ argv: ["node", "openclaw", "machine-output-cli"], stdoutIsTTY: false }),
@@ -1010,6 +1016,7 @@ module.exports = {
}),
).toBe(true);
const nested = registry.cliRegistrars.find((entry) => entry.parentPath.length > 0);
expect(nested?.commands).toEqual(["nested-machine-output"]);
expect(nested?.descriptors[0]).not.toHaveProperty("machineOutput");
}
});
@@ -163,12 +163,11 @@ export function createOperationRegistrars(state: PluginRegistryState) {
.filter(
(descriptor): descriptor is OpenClawPluginCliRootCommandDescriptor => descriptor !== null,
);
const commands = [
...(opts?.commands ?? []),
...descriptors.map((descriptor) => descriptor.name),
]
.map((command) => normalizeCommandRoot(command, "command"))
.filter((command): command is string => command !== null);
const commands = normalizeUniqueStringEntries(
[...(opts?.commands ?? []), ...descriptors.map((descriptor) => descriptor.name)]
.map((command) => normalizeCommandRoot(command, "command"))
.filter((command): command is string => command !== null),
);
if (commands.length === 0) {
pushDiagnostic({
level: "error",