fix: quiet update banner and skip duplicate plugin CLI

This commit is contained in:
Peter Steinberger
2026-01-21 07:36:39 +00:00
parent bc8a59faa4
commit fe860de148
4 changed files with 70 additions and 3 deletions

45
src/plugins/cli.test.ts Normal file
View File

@@ -0,0 +1,45 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
memoryRegister: vi.fn(),
otherRegister: vi.fn(),
}));
vi.mock("./loader.js", () => ({
loadClawdbotPlugins: () => ({
cliRegistrars: [
{
pluginId: "memory-core",
register: mocks.memoryRegister,
commands: ["memory"],
source: "bundled",
},
{
pluginId: "other",
register: mocks.otherRegister,
commands: ["other"],
source: "bundled",
},
],
}),
}));
import { registerPluginCliCommands } from "./cli.js";
describe("registerPluginCliCommands", () => {
beforeEach(() => {
mocks.memoryRegister.mockClear();
mocks.otherRegister.mockClear();
});
it("skips plugin CLI registrars when commands already exist", () => {
const program = new Command();
program.command("memory");
registerPluginCliCommands(program, {} as any);
expect(mocks.memoryRegister).not.toHaveBeenCalled();
expect(mocks.otherRegister).toHaveBeenCalledTimes(1);
});
});

View File

@@ -24,7 +24,20 @@ export function registerPluginCliCommands(program: Command, cfg?: ClawdbotConfig
logger,
});
const existingCommands = new Set(program.commands.map((cmd) => cmd.name()));
for (const entry of registry.cliRegistrars) {
if (entry.commands.length > 0) {
const overlaps = entry.commands.filter((command) => existingCommands.has(command));
if (overlaps.length > 0) {
log.debug(
`plugin CLI register skipped (${entry.pluginId}): command already registered (${overlaps.join(
", ",
)})`,
);
continue;
}
}
try {
const result = entry.register({
program,
@@ -37,6 +50,9 @@ export function registerPluginCliCommands(program: Command, cfg?: ClawdbotConfig
log.warn(`plugin CLI register failed (${entry.pluginId}): ${String(err)}`);
});
}
for (const command of entry.commands) {
existingCommands.add(command);
}
} catch (err) {
log.warn(`plugin CLI register failed (${entry.pluginId}): ${String(err)}`);
}