






















@@ -5,6 +5,10 @@ import { getRuntimeConfig, readConfigFileSnapshot, replaceConfigFile } from "../
55import { resolveStateDir } from "../config/paths.js";
66import type { OpenClawConfig } from "../config/types.openclaw.js";
77import type { PluginInstallRecord } from "../config/types.plugins.js";
8+import {
9+tracePluginLifecyclePhase,
10+tracePluginLifecyclePhaseAsync,
11+} from "../plugins/plugin-lifecycle-trace.js";
812import { formatPluginSourceForTable, resolvePluginSourceRoots } from "../plugins/source-display.js";
913import type { PluginLogger } from "../plugins/types.js";
1014import { defaultRuntime } from "../runtime.js";
@@ -264,18 +268,29 @@ export function registerPluginsCli(program: Command) {
264268} = await import("../plugins/status.js");
265269const { loadInstalledPluginIndexInstallRecords } =
266270await import("../plugins/installed-plugin-index-records.js");
267-const cfg = getRuntimeConfig();
268-const installRecords = await loadInstalledPluginIndexInstallRecords();
271+const cfg = tracePluginLifecyclePhase("config read", () => getRuntimeConfig(), {
272+command: "inspect",
273+});
274+const installRecords = await tracePluginLifecyclePhaseAsync(
275+"install records load",
276+() => loadInstalledPluginIndexInstallRecords(),
277+{ command: "inspect" },
278+);
269279const loggerParams = opts.json ? { logger: quietPluginJsonLogger } : {};
270280if (opts.all) {
271281if (id) {
272282defaultRuntime.error("Pass either a plugin id or --all, not both.");
273283return defaultRuntime.exit(1);
274284}
275-const report = buildPluginDiagnosticsReport({
276-config: cfg,
277- ...loggerParams,
278-});
285+const report = tracePluginLifecyclePhase(
286+"runtime plugin registry load",
287+() =>
288+buildPluginDiagnosticsReport({
289+config: cfg,
290+ ...loggerParams,
291+}),
292+{ command: "inspect", all: true },
293+);
279294const inspectAll = buildAllPluginInspectReports({
280295config: cfg,
281296 ...loggerParams,
@@ -344,22 +359,32 @@ export function registerPluginsCli(program: Command) {
344359return defaultRuntime.exit(1);
345360}
346361347-const snapshotReport = buildPluginSnapshotReport({
348-config: cfg,
349- ...loggerParams,
350-});
362+const snapshotReport = tracePluginLifecyclePhase(
363+"plugin registry snapshot",
364+() =>
365+buildPluginSnapshotReport({
366+config: cfg,
367+ ...loggerParams,
368+}),
369+{ command: "inspect" },
370+);
351371const targetPlugin = snapshotReport.plugins.find(
352372(entry) => entry.id === id || entry.name === id,
353373);
354374if (!targetPlugin) {
355375defaultRuntime.error(`Plugin not found: ${id}`);
356376return defaultRuntime.exit(1);
357377}
358-const report = buildPluginDiagnosticsReport({
359-config: cfg,
360- ...loggerParams,
361-onlyPluginIds: [targetPlugin.id],
362-});
378+const report = tracePluginLifecyclePhase(
379+"runtime plugin registry load",
380+() =>
381+buildPluginDiagnosticsReport({
382+config: cfg,
383+ ...loggerParams,
384+onlyPluginIds: [targetPlugin.id],
385+}),
386+{ command: "inspect", pluginId: targetPlugin.id },
387+);
363388const inspect = buildPluginInspectReport({
364389id: targetPlugin.id,
365390config: cfg,
@@ -603,11 +628,23 @@ export function registerPluginsCli(program: Command) {
603628await import("./plugins-registry-refresh.js");
604629const { resolvePluginUninstallId } = await import("./plugins-uninstall-selection.js");
605630const { promptYesNo } = await import("./prompt.js");
606-const snapshot = await readConfigFileSnapshot();
631+const snapshot = await tracePluginLifecyclePhaseAsync(
632+"config read",
633+() => readConfigFileSnapshot(),
634+{ command: "uninstall" },
635+);
607636const sourceConfig = (snapshot.sourceConfig ?? snapshot.config) as OpenClawConfig;
608-const installRecords = await loadInstalledPluginIndexInstallRecords();
637+const installRecords = await tracePluginLifecyclePhaseAsync(
638+"install records load",
639+() => loadInstalledPluginIndexInstallRecords(),
640+{ command: "uninstall" },
641+);
609642const cfg = withPluginInstallRecords(sourceConfig, installRecords);
610-const report = buildPluginSnapshotReport({ config: cfg });
643+const report = tracePluginLifecyclePhase(
644+"plugin registry snapshot",
645+() => buildPluginSnapshotReport({ config: cfg }),
646+{ command: "uninstall" },
647+);
611648const extensionsDir = path.join(resolveStateDir(process.env, os.homedir), "extensions");
612649const keepFiles = Boolean(opts.keepFiles || opts.keepConfig);
613650@@ -702,12 +739,17 @@ export function registerPluginsCli(program: Command) {
702739703740const nextInstallRecords = removePluginInstallRecordFromRecords(installRecords, pluginId);
704741const nextConfig = withoutPluginInstallRecords(plan.config);
705-await commitPluginInstallRecordsWithConfig({
706-previousInstallRecords: installRecords,
707- nextInstallRecords,
708- nextConfig,
709- ...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
710-});
742+await tracePluginLifecyclePhaseAsync(
743+"config mutation",
744+() =>
745+commitPluginInstallRecordsWithConfig({
746+previousInstallRecords: installRecords,
747+ nextInstallRecords,
748+ nextConfig,
749+ ...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
750+}),
751+{ command: "uninstall" },
752+);
711753const directoryResult = await applyPluginUninstallDirectoryRemoval(plan.directoryRemoval);
712754for (const warning of directoryResult.warnings) {
713755defaultRuntime.log(theme.warn(warning));
@@ -716,6 +758,7 @@ export function registerPluginsCli(program: Command) {
716758config: nextConfig,
717759reason: "source-changed",
718760installRecords: nextInstallRecords,
761+traceCommand: "uninstall",
719762logger: {
720763warn: (message) => defaultRuntime.log(theme.warn(message)),
721764},
@@ -764,8 +807,14 @@ export function registerPluginsCli(program: Command) {
764807marketplace?: string;
765808},
766809) => {
767-const { runPluginInstallCommand } = await import("./plugins-install-command.js");
768-await runPluginInstallCommand({ raw, opts });
810+await tracePluginLifecyclePhaseAsync(
811+"install command",
812+async () => {
813+const { runPluginInstallCommand } = await import("./plugins-install-command.js");
814+await runPluginInstallCommand({ raw, opts });
815+},
816+{ command: "install" },
817+);
769818},
770819);
771820此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。