
























@@ -25,12 +25,12 @@ import {
2525} from "../plugins/status.js";
2626import type { PluginLogger } from "../plugins/types.js";
2727import {
28+applyPluginUninstallDirectoryRemoval,
2829formatUninstallActionLabels,
2930formatUninstallSlotResetPreview,
31+planPluginUninstall,
3032resolveUninstallChannelConfigKeys,
31-resolveUninstallDirectoryTarget,
3233UNINSTALL_ACTION_LABELS,
33-uninstallPlugin,
3434} from "../plugins/uninstall.js";
3535import { defaultRuntime } from "../runtime.js";
3636import { formatDocsLink } from "../terminal/links.js";
@@ -614,50 +614,51 @@ export function registerPluginsCli(program: Command) {
614614return defaultRuntime.exit(1);
615615}
616616617-const install = cfg.plugins?.installs?.[pluginId];
618-const isLinked = install?.source === "path";
617+const channelIds = plugin?.status === "loaded" ? plugin.channelIds : undefined;
618+const plan = planPluginUninstall({
619+config: cfg,
620+ pluginId,
621+ channelIds,
622+deleteFiles: !keepFiles,
623+ extensionsDir,
624+});
625+if (!plan.ok) {
626+defaultRuntime.error(plan.error);
627+return defaultRuntime.exit(1);
628+}
629+619630const preview: string[] = [];
620-if (hasEntry) {
631+if (plan.actions.entry) {
621632preview.push(UNINSTALL_ACTION_LABELS.entry);
622633}
623-if (hasInstall) {
634+if (plan.actions.install) {
624635preview.push(UNINSTALL_ACTION_LABELS.install);
625636}
626-if (cfg.plugins?.allow?.includes(pluginId)) {
637+if (plan.actions.allowlist) {
627638preview.push(UNINSTALL_ACTION_LABELS.allowlist);
628639}
629-if (
630-isLinked &&
631-install?.sourcePath &&
632-cfg.plugins?.load?.paths?.includes(install.sourcePath)
633-) {
640+if (plan.actions.denylist) {
641+preview.push(UNINSTALL_ACTION_LABELS.denylist);
642+}
643+if (plan.actions.loadPath) {
634644preview.push(UNINSTALL_ACTION_LABELS.loadPath);
635645}
636-if (cfg.plugins?.slots?.memory === pluginId) {
646+if (plan.actions.memorySlot) {
637647preview.push(formatUninstallSlotResetPreview("memory"));
638648}
639-if (cfg.plugins?.slots?.contextEngine === pluginId) {
649+if (plan.actions.contextEngineSlot) {
640650preview.push(formatUninstallSlotResetPreview("contextEngine"));
641651}
642-const channelIds = plugin?.status === "loaded" ? plugin.channelIds : undefined;
643652const channels = cfg.channels as Record<string, unknown> | undefined;
644-if (hasInstall && channels) {
653+if (plan.actions.channelConfig && hasInstall && channels) {
645654for (const key of resolveUninstallChannelConfigKeys(pluginId, { channelIds })) {
646655if (Object.hasOwn(channels, key)) {
647656preview.push(`${UNINSTALL_ACTION_LABELS.channelConfig} (channels.${key})`);
648657}
649658}
650659}
651-const deleteTarget = !keepFiles
652- ? resolveUninstallDirectoryTarget({
653- pluginId,
654- hasInstall,
655-installRecord: install,
656- extensionsDir,
657-})
658- : null;
659-if (deleteTarget) {
660-preview.push(`directory: ${shortenHomePath(deleteTarget)}`);
660+if (plan.directoryRemoval) {
661+preview.push(`directory: ${shortenHomePath(plan.directoryRemoval.target)}`);
661662}
662663663664const pluginName = plugin?.name || pluginId;
@@ -679,24 +680,8 @@ export function registerPluginsCli(program: Command) {
679680}
680681}
681682682-const result = await uninstallPlugin({
683-config: cfg,
684- pluginId,
685- channelIds,
686-deleteFiles: !keepFiles,
687- extensionsDir,
688-});
689-690-if (!result.ok) {
691-defaultRuntime.error(result.error);
692-return defaultRuntime.exit(1);
693-}
694-for (const warning of result.warnings) {
695-defaultRuntime.log(theme.warn(warning));
696-}
697-698683const nextInstallRecords = removePluginInstallRecordFromRecords(installRecords, pluginId);
699-const nextConfig = withoutPluginInstallRecords(result.config);
684+const nextConfig = withoutPluginInstallRecords(plan.config);
700685await commitPluginInstallRecordsWithConfig({
701686previousInstallRecords: installRecords,
702687 nextInstallRecords,
@@ -711,8 +696,15 @@ export function registerPluginsCli(program: Command) {
711696warn: (message) => defaultRuntime.log(theme.warn(message)),
712697},
713698});
699+const directoryResult = await applyPluginUninstallDirectoryRemoval(plan.directoryRemoval);
700+for (const warning of directoryResult.warnings) {
701+defaultRuntime.log(theme.warn(warning));
702+}
714703715-const removed = formatUninstallActionLabels(result.actions);
704+const removed = formatUninstallActionLabels({
705+ ...plan.actions,
706+directory: directoryResult.directoryRemoved,
707+});
716708717709defaultRuntime.log(
718710`Uninstalled plugin "${pluginId}". Removed: ${removed.length > 0 ? removed.join(", ") : "nothing"}.`,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。