Skip to content

Commit a4f6bdf

Browse files
authored
fix(plugins): show package provenance in CLI and chat inspection (#133140)
* fix(plugins): show package install metadata when inspecting child entries * fix(plugins): share package ownership in chat inspection * chore(plugins): remove unused chat inspection type import
1 parent f120ed7 commit a4f6bdf

7 files changed

Lines changed: 419 additions & 201 deletions

File tree

‎docs/cli/plugins.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ openclaw plugins inspect --all
489489

490490
Inspect shows identity, load status, source, manifest capabilities, policy flags, diagnostics, install metadata, bundle capabilities, and any detected MCP or LSP server support without importing plugin runtime by default. JSON output includes the plugin manifest contracts, such as `contracts.agentToolResultMiddleware` and `contracts.trustedToolPolicies`, so operators can audit trusted-surface declarations before enabling or restarting a plugin. Add `--runtime` to load the plugin module and include registered hooks, tools, commands, services, gateway methods, and HTTP routes. Runtime inspection reports missing plugin dependencies directly; installs and repairs stay in `openclaw plugins install`, `openclaw plugins update`, and `openclaw doctor --fix`.
491491

492+
For multi-entry packages, inspecting any child shows the shared package install metadata. `inspect --all --json` includes that same record for each child. If package ownership is missing or ambiguous, inspection omits install metadata rather than attributing an unrelated install record.
493+
492494
Plugin-owned CLI commands are usually installed as root `openclaw` command groups, but plugins may also register nested commands under a core parent such as `openclaw nodes`. After `inspect --runtime` shows a command under `cliCommands`, run it at the listed path; for example a plugin that registers `demo-git` can be verified with `openclaw demo-git ping`.
493495

494496
Each plugin is classified by what it actually registers at runtime:

‎docs/tools/slash-commands.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ the source and permits replacement of an existing install; it does not bypass
514514
are printed informationally; blocked releases remain non-installable.
515515
Marketplace, linked, and pinned installs remain shell-only.
516516

517+
`/plugins inspect <child>` (also `show` or `get`) and `/plugins inspect all` include the shared package install metadata for multi-entry plugins. Inspection returns `install: null` when package ownership is missing or ambiguous, and preserves its runtime capability report.
518+
517519
When `/plugins install` or `/plugins enable` requires capability consent, it
518520
returns the plugin's declared capabilities and an exact retry command. Review
519521
that reply, then rerun with `--accept-capabilities`:

‎src/auto-reply/reply/commands-plugins.test.ts‎

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
44
import type { OpenClawConfig } from "../../config/config.js";
55
import type { PluginCapabilityConsentReview } from "../../plugins/capability-consent.js";
6+
import { recordInstalledPluginIndexInstallOwner } from "../../plugins/installed-plugin-index-install-owner.js";
67
import { ManagedPluginLifecycleError } from "../../plugins/management-lifecycle-error.js";
8+
import { createInstalledPluginIndexSnapshot } from "../../plugins/status.test-fixtures.js";
79
import { handlePluginsCommand } from "./commands-plugins.js";
810
import { buildPluginsCommandParams, type ConfigSnapshotMock } from "./commands.test-harness.js";
911

1012
const readConfigFileSnapshotMock = vi.hoisted(() => vi.fn());
13+
const loadPluginMetadataSnapshotMock = vi.hoisted(() => vi.fn());
1114
const validateConfigObjectWithPluginsMock = vi.hoisted(() => vi.fn());
1215
const replaceConfigFileMock = vi.hoisted(() => vi.fn(async (_params: unknown) => undefined));
1316
const buildPluginRegistrySnapshotReportMock = vi.hoisted(() => vi.fn());
@@ -107,10 +110,9 @@ vi.mock("../../plugins/install.js", () => ({
107110
installPluginFromPath: vi.fn(),
108111
}));
109112

110-
vi.mock("../../plugins/installed-plugin-index-records.js", () => ({
111-
loadInstalledPluginIndexInstallRecords: vi.fn(
112-
async (params = {}) => params.config?.plugins?.installs ?? {},
113-
),
113+
vi.mock("../../plugins/plugin-metadata-snapshot.js", async (importOriginal) => ({
114+
...(await importOriginal<typeof import("../../plugins/plugin-metadata-snapshot.js")>()),
115+
loadPluginMetadataSnapshot: loadPluginMetadataSnapshotMock,
114116
}));
115117

116118
vi.mock("../../plugins/status.js", () => ({
@@ -208,6 +210,9 @@ function expectLastRegistryRefresh(enabled: boolean) {
208210
describe("handlePluginsCommand", () => {
209211
beforeEach(() => {
210212
vi.clearAllMocks();
213+
loadPluginMetadataSnapshotMock.mockReturnValue({
214+
index: createInstalledPluginIndexSnapshot([]),
215+
});
211216
resolvePluginCapabilityConsentMock.mockReset().mockResolvedValue(undefined);
212217
resolvePendingPluginCapabilityReviewMock.mockReset();
213218
readConfigFileSnapshotMock.mockResolvedValue({
@@ -290,6 +295,120 @@ describe("handlePluginsCommand", () => {
290295
expect(inspectAllResult?.reply?.text).toContain('"superpowers"');
291296
});
292297

298+
it("reports package-owned provenance for child inspection and all aliases", async () => {
299+
const install = {
300+
source: "npm",
301+
spec: "@example/[email protected]",
302+
version: "1.2.3",
303+
installPath: "/plugins/pack",
304+
integrity: "sha512-pack",
305+
};
306+
const reports = ["pack/one", "pack/two"].map((id) => ({
307+
plugin: { id },
308+
compatibility: [],
309+
tools: [{ name: "runtime_tool" }],
310+
}));
311+
const index = {
312+
...createInstalledPluginIndexSnapshot(
313+
reports.map(({ plugin }) =>
314+
recordInstalledPluginIndexInstallOwner(
315+
{ pluginId: plugin.id, rootDir: install.installPath },
316+
"pack",
317+
),
318+
),
319+
),
320+
installRecords: { pack: install },
321+
};
322+
loadPluginMetadataSnapshotMock.mockReturnValue({ index });
323+
buildAllPluginInspectReportsMock.mockReturnValue(reports);
324+
325+
for (const action of ["inspect", "show", "get"]) {
326+
for (const report of reports) {
327+
buildPluginInspectReportMock.mockReturnValue(report);
328+
const result = await handlePluginsCommand(
329+
buildPluginsParams(`/plugins ${action} ${report.plugin.id}`, buildCfg()),
330+
true,
331+
);
332+
const payload = JSON.parse(
333+
result?.reply?.text?.split("```json\n")[1]?.split("\n```")[0] ?? "null",
334+
);
335+
expect(payload).toEqual({ ...report, compatibilityWarnings: [], install });
336+
}
337+
const result = await handlePluginsCommand(
338+
buildPluginsParams(`/plugin ${action} all`, buildCfg()),
339+
true,
340+
);
341+
const payload = JSON.parse(
342+
result?.reply?.text?.split("```json\n")[1]?.split("\n```")[0] ?? "null",
343+
);
344+
expect(payload).toEqual(
345+
reports.map((inspect) => ({ inspect, compatibilityWarnings: [], install })),
346+
);
347+
}
348+
expect(buildPluginDiagnosticsReportMock).toHaveBeenCalled();
349+
expect(buildPluginRegistrySnapshotReportMock).not.toHaveBeenCalled();
350+
});
351+
352+
it("keeps bare inspection on the runtime report", async () => {
353+
const result = await handlePluginsCommand(
354+
buildPluginsParams("/plugins inspect", buildCfg()),
355+
true,
356+
);
357+
expect(result?.reply?.text).toContain("superpowers");
358+
expect(buildPluginDiagnosticsReportMock).toHaveBeenCalledTimes(1);
359+
expect(buildPluginRegistrySnapshotReportMock).not.toHaveBeenCalled();
360+
});
361+
362+
it.each(["list", "inspect pack/one", "enable pack/one"])(
363+
"rejects invalid config before loading plugin state for %s",
364+
async (action) => {
365+
readConfigFileSnapshotMock.mockResolvedValue({ valid: false, path: "/tmp/openclaw.json" });
366+
const result = await handlePluginsCommand(
367+
buildPluginsParams(`/plugins ${action}`, buildCfg(), {
368+
gatewayClientScopes: WRITE_GATEWAY_SCOPES,
369+
}),
370+
true,
371+
);
372+
expect(result?.reply?.text).toBe("⚠️ Config file is invalid; fix it before using /plugins.");
373+
expect(buildPluginDiagnosticsReportMock).not.toHaveBeenCalled();
374+
expect(buildPluginRegistrySnapshotReportMock).not.toHaveBeenCalled();
375+
expect(replaceConfigFileMock).not.toHaveBeenCalled();
376+
},
377+
);
378+
379+
it.each(["missing", "ambiguous", "conflicting"])(
380+
"does not attribute chat install metadata when ownership is %s",
381+
async (ownership) => {
382+
const inspect = { plugin: { id: "pack/one" }, compatibility: [] };
383+
const index = {
384+
...createInstalledPluginIndexSnapshot([
385+
recordInstalledPluginIndexInstallOwner(
386+
{ pluginId: inspect.plugin.id, rootDir: "/plugins/pack" },
387+
ownership === "conflicting" ? "pack" : undefined,
388+
ownership === "ambiguous",
389+
),
390+
]),
391+
installRecords: {
392+
pack: { source: "npm", installPath: "/plugins/pack" },
393+
"pack/one": { source: "npm", installPath: "/plugins/unrelated" },
394+
},
395+
};
396+
loadPluginMetadataSnapshotMock.mockReturnValue({ index });
397+
buildPluginInspectReportMock.mockReturnValue(inspect);
398+
buildAllPluginInspectReportsMock.mockReturnValue([inspect]);
399+
for (const name of [inspect.plugin.id, "all"]) {
400+
const result = await handlePluginsCommand(
401+
buildPluginsParams(`/plugins inspect ${name}`, buildCfg()),
402+
true,
403+
);
404+
const payload = JSON.parse(
405+
result?.reply?.text?.split("```json\n")[1]?.split("\n```")[0] ?? "null",
406+
);
407+
expect(Array.isArray(payload) ? payload[0].install : payload.install).toBeNull();
408+
}
409+
},
410+
);
411+
293412
it("rejects internal writes without operator.admin", async () => {
294413
const params = buildPluginsParams("/plugins enable superpowers", buildCfg());
295414
params.command.channel = "webchat";

‎src/auto-reply/reply/commands-plugins.ts‎

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/s
33
import { resolvePluginCapabilityConsentCliOptions } from "../../cli/plugin-capability-consent.js";
44
import { readConfigFileSnapshot, readConfigFileSnapshotForWrite } from "../../config/config.js";
55
import { assertConfigWriteAllowedInCurrentMode } from "../../config/nix-mode-write-guard.js";
6-
import type { OpenClawConfig } from "../../config/types.openclaw.js";
7-
import type { PluginInstallRecord } from "../../config/types.plugins.js";
86
import { formatErrorMessage } from "../../infra/errors.js";
97
import {
108
resolveInstallConfigMutationPreflights,
119
selectInstallMutationWriteOptions,
1210
type ConfigSnapshotForInstallPersist,
1311
} from "../../plugins/install-persistence.js";
14-
import { loadInstalledPluginIndexInstallRecords } from "../../plugins/installed-plugin-index-records.js";
12+
import type { InstalledPluginIndex } from "../../plugins/installed-plugin-index.js";
13+
import { resolveInstalledPluginPackageOwnership } from "../../plugins/installed-plugin-package-ownership.js";
1514
import { withPluginLifecycleLease } from "../../plugins/plugin-lifecycle-lease.js";
15+
import { loadPluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.js";
1616
import { refreshPluginRegistryAfterConfigMutation } from "../../plugins/registry-refresh.js";
1717
import type { PluginRecord } from "../../plugins/registry.js";
1818
import {
@@ -44,16 +44,17 @@ function renderJsonBlock(label: string, value: unknown): string {
4444

4545
function buildPluginInspectJson(
4646
inspect: ReturnType<typeof buildAllPluginInspectReports>[number],
47-
installRecords: Record<string, PluginInstallRecord>,
47+
index: InstalledPluginIndex,
4848
) {
49+
const ownership = resolveInstalledPluginPackageOwnership(index, inspect.plugin.id);
4950
return {
5051
inspect,
5152
compatibilityWarnings: inspect.compatibility.map((warning) => ({
5253
code: warning.code,
5354
severity: warning.severity,
5455
message: formatPluginCompatibilityNotice(warning),
5556
})),
56-
install: installRecords[inspect.plugin.id] ?? null,
57+
install: ownership.ok ? ownership.value.installRecord : null,
5758
};
5859
}
5960

@@ -117,38 +118,6 @@ function findPlugin(report: PluginStatusReport, rawName: string): PluginRecord |
117118
);
118119
}
119120

120-
async function loadPluginCommandState(
121-
workspaceDir: string,
122-
options?: { loadModules?: boolean },
123-
): Promise<
124-
| {
125-
ok: true;
126-
path: string;
127-
config: OpenClawConfig;
128-
report: PluginStatusReport;
129-
}
130-
| { ok: false; path: string; error: string }
131-
> {
132-
const snapshot = await readConfigFileSnapshot();
133-
if (!snapshot.valid) {
134-
return {
135-
ok: false,
136-
path: snapshot.path,
137-
error: "Config file is invalid; fix it before using /plugins.",
138-
};
139-
}
140-
const config = structuredClone(snapshot.resolved);
141-
return {
142-
ok: true,
143-
path: snapshot.path,
144-
config,
145-
report:
146-
options?.loadModules === true
147-
? buildPluginDiagnosticsReport({ config, workspaceDir })
148-
: buildPluginRegistrySnapshotReport({ config, workspaceDir }),
149-
};
150-
}
151-
152121
async function loadPluginCommandConfig(): Promise<
153122
| { ok: true; path: string; snapshot: ConfigSnapshotForInstallPersist }
154123
| { ok: false; path: string; error: string }
@@ -247,37 +216,34 @@ export const handlePluginsCommand: CommandHandler = defineAuthorizedTextCommand(
247216
}
248217

249218
const handleLoadedCommand = async () => {
250-
const loaded = await loadPluginCommandState(params.workspaceDir, {
251-
loadModules: pluginsCommand.action === "inspect",
252-
});
253-
if (!loaded.ok) {
254-
return commandReply(`⚠️ ${loaded.error}`);
255-
}
256-
257-
if (pluginsCommand.action === "list") {
258-
return commandReply(formatPluginsList(loaded.report));
219+
const snapshot = await readConfigFileSnapshot();
220+
if (!snapshot.valid) {
221+
return commandReply("⚠️ Config file is invalid; fix it before using /plugins.");
259222
}
223+
const config = structuredClone(snapshot.resolved);
224+
const reportParams = { config, workspaceDir: params.workspaceDir };
260225

261226
if (pluginsCommand.action === "inspect") {
262-
const installRecords = await loadInstalledPluginIndexInstallRecords();
227+
const metadataSnapshot = loadPluginMetadataSnapshot(reportParams);
228+
const report = buildPluginDiagnosticsReport({ ...reportParams, metadataSnapshot });
263229
if (!pluginsCommand.name) {
264-
return commandReply(formatPluginsList(loaded.report));
230+
return commandReply(formatPluginsList(report));
265231
}
266232
if (normalizeOptionalLowercaseString(pluginsCommand.name) === "all") {
267-
const reports = buildAllPluginInspectReports(loaded).map((inspect) =>
268-
buildPluginInspectJson(inspect, installRecords),
233+
const reports = buildAllPluginInspectReports({ config, report }).map((inspect) =>
234+
buildPluginInspectJson(inspect, metadataSnapshot.index),
269235
);
270236
return commandReply(renderJsonBlock("🔌 Plugins", reports));
271237
}
272238
const inspect = buildPluginInspectReport({
273239
id: pluginsCommand.name,
274-
config: loaded.config,
275-
report: loaded.report,
240+
config,
241+
report,
276242
});
277243
if (!inspect) {
278244
return commandReply(`🔌 No plugin named "${pluginsCommand.name}" found.`);
279245
}
280-
const payload = buildPluginInspectJson(inspect, installRecords);
246+
const payload = buildPluginInspectJson(inspect, metadataSnapshot.index);
281247
return commandReply(
282248
renderJsonBlock(`🔌 Plugin "${inspect.plugin.id}"`, {
283249
...inspect,
@@ -287,7 +253,11 @@ export const handlePluginsCommand: CommandHandler = defineAuthorizedTextCommand(
287253
);
288254
}
289255

290-
const plugin = findPlugin(loaded.report, pluginsCommand.name);
256+
const report = buildPluginRegistrySnapshotReport(reportParams);
257+
if (pluginsCommand.action === "list") {
258+
return commandReply(formatPluginsList(report));
259+
}
260+
const plugin = findPlugin(report, pluginsCommand.name);
291261
if (!plugin) {
292262
return commandReply(`🔌 No plugin named "${pluginsCommand.name}" found.`);
293263
}
@@ -329,7 +299,7 @@ export const handlePluginsCommand: CommandHandler = defineAuthorizedTextCommand(
329299
}
330300

331301
return commandReply(
332-
`🔌 Plugin "${plugin.id}" ${pluginsCommand.action}d in ${loaded.path}. Gateway reload will apply it to new agent turns.` +
302+
`🔌 Plugin "${plugin.id}" ${pluginsCommand.action}d in ${snapshot.path}. Gateway reload will apply it to new agent turns.` +
333303
(registryWarning ? `\n${registryWarning}` : ""),
334304
);
335305
};

‎src/cli/plugins-cli-test-helpers.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const loadPluginManifestRegistryMock: UnknownMock = vi.fn();
142142
export const buildPluginSnapshotReportMock: UnknownMock = vi.fn();
143143
export const buildPluginRegistrySnapshotReportMock: UnknownMock = vi.fn();
144144
export const buildPluginInspectReportMock: UnknownMock = vi.fn();
145-
const buildAllPluginInspectReports: UnknownMock = vi.fn();
145+
export const buildAllPluginInspectReportsMock: UnknownMock = vi.fn();
146146
export const buildPluginDiagnosticsReportMock: UnknownMock = vi.fn();
147147
export const buildPluginCompatibilityNoticesMock: UnknownMock = vi.fn();
148148
export const inspectPluginRegistryMock: AsyncUnknownMock = vi.fn();
@@ -495,7 +495,7 @@ vi.mock("../plugins/status.js", () => ({
495495
Parameters<(typeof import("../plugins/status.js"))["buildAllPluginInspectReports"]>,
496496
ReturnType<(typeof import("../plugins/status.js"))["buildAllPluginInspectReports"]>
497497
>(
498-
buildAllPluginInspectReports,
498+
buildAllPluginInspectReportsMock,
499499
...args,
500500
)) as (typeof import("../plugins/status.js"))["buildAllPluginInspectReports"],
501501
buildPluginDiagnosticsReport: ((
@@ -894,6 +894,7 @@ export function resetPluginsCliTestState() {
894894
buildPluginSnapshotReportMock.mockReset();
895895
buildPluginRegistrySnapshotReportMock.mockReset();
896896
buildPluginInspectReportMock.mockReset();
897+
buildAllPluginInspectReportsMock.mockReset();
897898
buildPluginDiagnosticsReportMock.mockReset();
898899
buildPluginCompatibilityNoticesMock.mockReset();
899900
inspectPluginRegistryMock.mockReset();

0 commit comments

Comments
 (0)