feat(plugins): add registry repair command

This commit is contained in:
Vincent Koc
2026-04-25 05:12:14 -07:00
parent 521e75dea0
commit caf25fac91
4 changed files with 169 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
import type { PluginInstallRecord } from "../config/types.plugins.js";
import { enablePluginInConfig } from "../plugins/enable.js";
import { listMarketplacePlugins } from "../plugins/marketplace.js";
import { inspectPluginRegistry, refreshPluginRegistry } from "../plugins/plugin-registry.js";
import { defaultSlotIdForKey } from "../plugins/slots.js";
import { formatPluginSourceForTable, resolvePluginSourceRoots } from "../plugins/source-display.js";
import {
@@ -69,6 +70,11 @@ export type PluginUninstallOptions = {
dryRun?: boolean;
};
export type PluginRegistryOptions = {
json?: boolean;
refresh?: boolean;
};
const quietPluginJsonLogger: PluginLogger = {
debug: () => undefined,
info: () => undefined,
@@ -137,6 +143,20 @@ function formatInstallLines(install: PluginInstallRecord | undefined): string[]
return lines;
}
function countEnabledPlugins(plugins: readonly { enabled: boolean }[]): number {
return plugins.filter((plugin) => plugin.enabled).length;
}
function formatRegistryState(state: "missing" | "fresh" | "stale"): string {
if (state === "fresh") {
return theme.success(state);
}
if (state === "stale") {
return theme.warn(state);
}
return theme.warn(state);
}
export function registerPluginsCli(program: Command) {
const plugins = program
.command("plugins")
@@ -748,6 +768,65 @@ export function registerPluginsCli(program: Command) {
await runPluginUpdateCommand({ id, opts });
});
plugins
.command("registry")
.description("Inspect or rebuild the persisted plugin registry")
.option("--json", "Print JSON")
.option("--refresh", "Rebuild the persisted registry from current plugin manifests", false)
.action(async (opts: PluginRegistryOptions) => {
const cfg = loadConfig();
if (opts.refresh) {
const index = await refreshPluginRegistry({
config: cfg,
reason: "manual",
});
if (opts.json) {
defaultRuntime.writeJson({
refreshed: true,
registry: index,
});
return;
}
const total = index.plugins.length;
const enabled = countEnabledPlugins(index.plugins);
defaultRuntime.log(
`Plugin registry refreshed: ${enabled}/${total} enabled plugins indexed.`,
);
return;
}
const inspection = await inspectPluginRegistry({ config: cfg });
if (opts.json) {
defaultRuntime.writeJson({
state: inspection.state,
refreshReasons: inspection.refreshReasons,
persisted: inspection.persisted,
current: inspection.current,
});
return;
}
const currentTotal = inspection.current.plugins.length;
const currentEnabled = countEnabledPlugins(inspection.current.plugins);
const persistedTotal = inspection.persisted?.plugins.length ?? 0;
const persistedEnabled = inspection.persisted
? countEnabledPlugins(inspection.persisted.plugins)
: 0;
const lines = [
`${theme.muted("State:")} ${formatRegistryState(inspection.state)}`,
`${theme.muted("Current:")} ${currentEnabled}/${currentTotal} enabled plugins`,
`${theme.muted("Persisted:")} ${persistedEnabled}/${persistedTotal} enabled plugins`,
];
if (inspection.refreshReasons.length > 0) {
lines.push(`${theme.muted("Refresh reasons:")} ${inspection.refreshReasons.join(", ")}`);
lines.push(
`${theme.muted("Repair:")} ${theme.command("openclaw plugins registry --refresh")}`,
);
}
defaultRuntime.log(lines.join("\n"));
});
plugins
.command("doctor")
.description("Report plugin load issues")