Files
openclaw/src/cli/plugins-list-command.ts
Peter Steinberger 250376f885 fix: simplify bundled runtime dependency repair (#75183)
Summary:
- Merged fix: simplify bundled runtime dependency repair after ClawSweeper review.

ClawSweeper fixups:
- Included follow-up commit: fix: verify cached bundled runtime roots
- Included follow-up commit: refactor: simplify plugin runtime startup paths
- Included follow-up commit: refactor: trim plugin startup policy helpers
- Included follow-up commit: refactor: trust package manager runtime deps materialization
- Included follow-up commit: fix: narrow channel runtime deps skip policy
- Included follow-up commit: refactor: defer startup plugin runtime deps
- Ran the ClawSweeper repair loop before final review.

Validation:
- ClawSweeper review passed for head 04dc566534.
- Required merge gates passed before the squash merge.

Prepared head SHA: 04dc566534
Review: https://github.com/openclaw/openclaw/pull/75183#issuecomment-4358383786

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: Shakker <shakkerdroid@gmail.com>
Co-authored-by: clawsweeper-repair <clawsweeper-repair@users.noreply.github.com>
2026-05-01 07:49:02 +00:00

115 lines
3.7 KiB
TypeScript

import { getRuntimeConfig } from "../config/config.js";
import { formatPluginSourceForTable, resolvePluginSourceRoots } from "../plugins/source-display.js";
import { defaultRuntime } from "../runtime.js";
import { getTerminalTableWidth, renderTable } from "../terminal/table.js";
import { theme } from "../terminal/theme.js";
import { quietPluginJsonLogger } from "./plugins-command-helpers.js";
import { formatPluginLine } from "./plugins-list-format.js";
export type PluginsListOptions = {
json?: boolean;
enabled?: boolean;
verbose?: boolean;
};
export async function runPluginsListCommand(opts: PluginsListOptions): Promise<void> {
const { buildPluginRegistrySnapshotReport } = await import("../plugins/status.js");
const cfg = getRuntimeConfig();
const report = buildPluginRegistrySnapshotReport({
config: cfg,
...(opts.json ? { logger: quietPluginJsonLogger } : {}),
});
const list = opts.enabled ? report.plugins.filter((p) => p.enabled) : report.plugins;
if (opts.json) {
const payload = {
workspaceDir: report.workspaceDir,
registry: {
source: report.registrySource,
diagnostics: report.registryDiagnostics,
},
plugins: list,
diagnostics: report.diagnostics,
};
defaultRuntime.writeJson(payload);
return;
}
if (list.length === 0) {
defaultRuntime.log(theme.muted("No plugins found."));
return;
}
const enabled = list.filter((p) => p.enabled).length;
defaultRuntime.log(
`${theme.heading("Plugins")} ${theme.muted(`(${enabled}/${list.length} enabled)`)}`,
);
if (!opts.verbose) {
const tableWidth = getTerminalTableWidth();
const sourceRoots = resolvePluginSourceRoots({
workspaceDir: report.workspaceDir,
});
const usedRoots = new Set<keyof typeof sourceRoots>();
const rows = list.map((plugin) => {
const desc = plugin.description ? theme.muted(plugin.description) : "";
const formattedSource = formatPluginSourceForTable(plugin, sourceRoots);
if (formattedSource.rootKey) {
usedRoots.add(formattedSource.rootKey);
}
const sourceLine = desc ? `${formattedSource.value}\n${desc}` : formattedSource.value;
return {
Name: plugin.name || plugin.id,
ID: plugin.name && plugin.name !== plugin.id ? plugin.id : "",
Format: plugin.format ?? "openclaw",
Status:
plugin.status === "error"
? theme.error("error")
: plugin.enabled
? theme.success("enabled")
: theme.warn("disabled"),
Source: sourceLine,
Version: plugin.version ?? "",
};
});
if (usedRoots.size > 0) {
defaultRuntime.log(theme.muted("Source roots:"));
for (const key of ["stock", "workspace", "global"] as const) {
if (!usedRoots.has(key)) {
continue;
}
const dir = sourceRoots[key];
if (!dir) {
continue;
}
defaultRuntime.log(` ${theme.command(`${key}:`)} ${theme.muted(dir)}`);
}
defaultRuntime.log("");
}
defaultRuntime.log(
renderTable({
width: tableWidth,
columns: [
{ key: "Name", header: "Name", minWidth: 14, flex: true },
{ key: "ID", header: "ID", minWidth: 10, flex: true },
{ key: "Format", header: "Format", minWidth: 9 },
{ key: "Status", header: "Status", minWidth: 10 },
{ key: "Source", header: "Source", minWidth: 26, flex: true },
{ key: "Version", header: "Version", minWidth: 8 },
],
rows,
}).trimEnd(),
);
return;
}
const lines: string[] = [];
for (const plugin of list) {
lines.push(formatPluginLine(plugin, true));
lines.push("");
}
defaultRuntime.log(lines.join("\n").trim());
}