Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix: address review — 批量更新提升为模块级控制器并补齐扩权/卸载防护

Chris0d0a80441698
diff --git a/apps/desktop/src/renderer/cindy-brain/useInstalledGhosts.ts b/apps/desktop/src/renderer/cindy-brain/useInstalledGhosts.ts
index bf3a065663..8e5ed9de9c 100644
--- a/apps/desktop/src/renderer/cindy-brain/useInstalledGhosts.ts
+++ b/apps/desktop/src/renderer/cindy-brain/useInstalledGhosts.ts
@@ -85,6 +85,14 @@ export function useInstalledGhosts(): InstalledGhost[] {
return useSyncExternalStore(subscribeInstalledGhosts, getInstalledGhostsSnapshot);
}
+/**
+ * 非 hook 消费者(模块级控制器,如批量更新 runner)读取同一份清单;
+ * 与 hook 走完全相同的缓存与 ghosts:changed 刷新,不另开数据源。
+ */
+export function readInstalledGhostsSnapshot(): InstalledGhost[] {
+ return ensureLoaded();
+}
+
if (import.meta.hot) {
import.meta.hot.accept(() => {});
import.meta.hot.dispose(resetInstalledGhostsStore);
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
index c4f9413d9f..362d035e84 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
@@ -81,14 +81,15 @@ import {
sortGhostPluginItemsByRecentUse,
type GhostPluginListItem,
} from './lib/ghostPluginViewModel';
+import { isBatchFinished, updateRoundKey } from './lib/updateAllModel';
import {
- batchSummary,
- buildUpdateAllRows,
- isBatchFinished,
- updateRoundKey,
- updateRow,
- type UpdateAllRow,
-} from './lib/updateAllModel';
+ approveUpdateExpansion,
+ getUpdateAllBatchState,
+ setUpdateAllBatchHooks,
+ skipUpdateExpansion,
+ startUpdateAllBatch,
+ subscribeUpdateAllBatch,
+} from './lib/updateAllController';
import { formatSetupGateDescription } from './lib/ghostSetupGateModel';
import {
PLUGIN_MANAGEMENT_CARD_GRID_CLASS,
@@ -157,8 +158,6 @@ export function GhostPluginPage() {
const { user, mode, dataOwnerId } = useAuth();
const showEnterprise = user?.membershipKind === 'org';
const ghosts = useInstalledGhosts();
- const ghostsRef = useRef(ghosts);
- ghostsRef.current = ghosts;
const installedGhostIdsKey = ghosts
.map((ghost) => ghost.manifest.id)
.sort()
@@ -510,12 +509,12 @@ export function GhostPluginPage() {
setIgnoredRound(currentRoundKey);
}, [currentRoundKey]);
- const [updateRows, setUpdateRows] = useState<UpdateAllRow[] | null>(null);
+ // 批次状态住在模块级控制器里(生命周期长于本页:关弹窗离开 /plugins
+ // 后批次继续跑,回来仍保留待确认项的批准/跳过入口),页面只订阅快照。
+ const updateBatch = useSyncExternalStore(subscribeUpdateAllBatch, getUpdateAllBatchState);
+ const updateRows = updateBatch.rows;
+ const batchRunning = updateBatch.running;
const [updateDialogOpen, setUpdateDialogOpen] = useState(false);
- const updateRowsRef = useRef<UpdateAllRow[]>([]);
- const batchRunningRef = useRef(false);
- const [batchRunning, setBatchRunning] = useState(false);
- const finishToastShownRef = useRef(false);
const selectedGhost = selectedId
? (ghosts.find((ghost) => ghost.manifest.id === selectedId) ?? null)
: null;
@@ -667,112 +666,23 @@ export function GhostPluginPage() {
await pickAndUpdateGhost(selectedDetail.id, { t, confirm, confirmWithCheckbox });
}, [confirm, confirmWithCheckbox, selectedDetail, t]);
- const patchUpdateRow = useCallback((pluginId: string, patch: Partial<UpdateAllRow>) => {
- updateRowsRef.current = updateRow(updateRowsRef.current, pluginId, patch);
- setUpdateRows(updateRowsRef.current);
- }, []);
- const maybeFinishBatch = useCallback(() => {
- const rows = updateRowsRef.current;
- if (rows.length === 0 || !isBatchFinished(rows) || finishToastShownRef.current) return;
- finishToastShownRef.current = true;
- const summary = batchSummary(rows);
- toast.success(
- t('settings.ghosts.updateAll.doneToast', {
- done: summary.done,
- rest: summary.skipped + summary.failed,
- }),
- );
- }, [t]);
- /** 批量更新 runner:串行走「取详情 → 权限 diff → 无扩权直接装 / 有扩权停待确认」。 */
- const runBatchQueue = useCallback(async () => {
- if (batchRunningRef.current) return;
- batchRunningRef.current = true;
- setBatchRunning(true);
- try {
- for (;;) {
- const next = updateRowsRef.current.find((row) => row.status === 'pending');
- if (!next) break;
- patchUpdateRow(next.pluginId, { status: 'installing' });
- try {
- const detail = await window.electronAPI.pluginMarket.detail(next.pluginId);
- const installedManifest = ghostsRef.current.find(
- (ghost) => ghost.manifest.id === next.ghostId,
- )?.manifest;
- const diff = diffGhostPermissionItems(
- installedManifest ?? detail.manifest,
- detail.manifest,
- );
- if (diff.added.length > 0) {
- // 扩权不自动放行:停在待确认,由用户在弹窗里逐项同意或跳过。
- patchUpdateRow(next.pluginId, {
- status: 'needs-confirm',
- releaseId: detail.releaseId,
- permissionDiff: diff,
- });
- continue;
- }
- await window.electronAPI.pluginMarket.install(next.pluginId, {
- expectedReleaseId: detail.releaseId,
- ...(detail.sourceType !== 'server' ? { expectedManifest: detail.manifest } : {}),
- });
- patchUpdateRow(next.pluginId, { status: 'done' });
- } catch (error) {
- patchUpdateRow(next.pluginId, {
- status: 'failed',
- errorText: t(pluginMarketErrorKey(error)),
- });
- }
- }
- } finally {
- batchRunningRef.current = false;
- setBatchRunning(false);
- await refreshMarket();
- maybeFinishBatch();
- }
- }, [maybeFinishBatch, patchUpdateRow, refreshMarket, t]);
+ // 控制器在挂载期借用本页的市场刷新;卸载后批次继续跑,重新进页全量刷新。
+ useEffect(
+ () => setUpdateAllBatchHooks({ refreshMarket: () => refreshMarket() }),
+ [refreshMarket],
+ );
const handleUpdateAll = useCallback(() => {
- if (batchRunningRef.current) {
+ const current = getUpdateAllBatchState();
+ // 运行中或还有待确认项的批次:重开弹窗接着处理,不重建批次。
+ if (current.running || (current.rows !== null && !isBatchFinished(current.rows))) {
setUpdateDialogOpen(true);
return;
}
- const installedVersionById = new Map(
- ghostsRef.current.map((ghost) => [ghost.manifest.id, ghost.manifest.version]),
- );
- updateRowsRef.current = buildUpdateAllRows(
+ startUpdateAllBatch(
updatableInstalledItems.flatMap((item) => (item.marketUpdate ? [item.marketUpdate] : [])),
- installedVersionById,
);
- finishToastShownRef.current = false;
- setUpdateRows(updateRowsRef.current);
setUpdateDialogOpen(true);
- void runBatchQueue();
- }, [runBatchQueue, updatableInstalledItems]);
- const handleApproveExpansion = useCallback(
- async (pluginId: string) => {
- const row = updateRowsRef.current.find((candidate) => candidate.pluginId === pluginId);
- if (!row?.releaseId) return;
- patchUpdateRow(pluginId, { status: 'installing' });
- try {
- await window.electronAPI.pluginMarket.install(pluginId, {
- expectedReleaseId: row.releaseId,
- allowPermissionExpansion: true,
- });
- patchUpdateRow(pluginId, { status: 'done' });
- } catch (error) {
- patchUpdateRow(pluginId, { status: 'failed', errorText: t(pluginMarketErrorKey(error)) });
- }
- await refreshMarket();
- maybeFinishBatch();
- },
- [maybeFinishBatch, patchUpdateRow, refreshMarket, t],
- );
- const handleSkipExpansion = useCallback(
- (pluginId: string) => {
- patchUpdateRow(pluginId, { status: 'skipped' });
- maybeFinishBatch();
- },
- [maybeFinishBatch, patchUpdateRow],
- );
+ }, [updatableInstalledItems]);
const handleInstall = useCallback(async () => {
const picked = await window.electronAPI.ghosts.pickFile().catch(() => null);
@@ -1304,7 +1214,6 @@ export function GhostPluginPage() {
<button
type="button"
onClick={handleUpdateAll}
- disabled={batchRunning && !updateDialogOpen}
className="inline-flex h-9 shrink-0 items-center rounded-full bg-[var(--accent-cta-bg)] px-4 text-12 font-medium text-[var(--accent-pure-cta-fg)] transition-transform duration-150 hover:bg-[var(--accent-hover)] active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"
>
{t('settings.ghosts.page.updateAll')}
@@ -1477,8 +1386,8 @@ export function GhostPluginPage() {
open={updateDialogOpen}
rows={updateRows}
iconByGhostId={new Map(ghosts.map((ghost) => [ghost.manifest.id, ghost.iconDataUrl]))}
- onApprove={(pluginId) => void handleApproveExpansion(pluginId)}
- onSkip={handleSkipExpansion}
+ onApprove={(pluginId) => void approveUpdateExpansion(pluginId)}
+ onSkip={skipUpdateExpansion}
onClose={() => setUpdateDialogOpen(false)}
/>
) : null}
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginCard.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginCard.test.tsx
index 98b4d05c71..c2638d3e02 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginCard.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginCard.test.tsx
@@ -11,6 +11,9 @@ import { describe, expect, it, vi } from 'vitest';
vi.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string) => key }),
+ // 页面经批量更新控制器引 @/i18n,其 init 链路需要这些导出。
+ initReactI18next: { type: '3rdParty', init: vi.fn() },
+ I18nextProvider: ({ children }: { children: React.ReactNode }) => children,
}));
vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({ user: null, mode: 'signed-out', dataOwnerId: null }),
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts
new file mode 100644
index 0000000000..bc0ee01deb
--- /dev/null
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts
@@ -0,0 +1,169 @@
+/**
+ * Regression coverage for the module-level update-all batch controller:
+ * uninstall guards, reviewed-manifest passthrough on approval, and batch
+ * state surviving page unmount (review 定稿 2026-08-02).
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
+ * @vitest-environment jsdom
+ */
+
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+vi.mock('@/i18n', () => ({ i18n: { t: (key: string) => key } }));
+vi.mock('@/lib/toast', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
+
+let installedGhosts: Array<{ manifest: GhostManifest }> = [];
+vi.mock('@/cindy-brain/useInstalledGhosts', () => ({
+ readInstalledGhostsSnapshot: () => installedGhosts,
+}));
+
+import type { GhostManifest } from '../../../../shared/ghost';
+import type { PluginMarketDetail, PluginMarketItem } from '../../../../shared/pluginMarket';
+import {
+ __resetUpdateAllBatchForTest,
+ approveUpdateExpansion,
+ getUpdateAllBatchState,
+ startUpdateAllBatch,
+} from '../lib/updateAllController';
+
+function manifest(overrides: Partial<GhostManifest>): GhostManifest {
+ return {
+ id: 'ghost-a',
+ name: 'Ghost A',
+ version: '1.1.0',
+ slots: [],
+ ...overrides,
+ } as GhostManifest;
+}
+
+function marketItem(overrides: Partial<PluginMarketItem>): PluginMarketItem {
+ return {
+ pluginId: 'plugin-a',
+ ghostId: 'ghost-a',
+ name: 'Ghost A',
+ description: '',
+ author: null,
+ scope: 'public',
+ organizationId: null,
+ defaultInstall: false,
+ releaseId: 'release-2',
+ version: '1.1.0',
+ publishedAt: '2026-08-01T00:00:00.000Z',
+ icon: null,
+ installState: 'update-available',
+ enabled: true,
+ sourceType: 'server',
+ sourceMarketName: null,
+ ...overrides,
+ };
+}
+
+const detailMock = vi.fn<(pluginId: string) => Promise<PluginMarketDetail>>();
+const installMock = vi.fn(async () => ({ ghost: { manifest: manifest({}) } }) as never);
+
+function stubDetail(overrides: {
+ manifest: GhostManifest;
+ sourceType: PluginMarketDetail['sourceType'];
+}): void {
+ detailMock.mockResolvedValue({
+ ...marketItem({ sourceType: overrides.sourceType }),
+ manifest: overrides.manifest,
+ readme: null,
+ } as unknown as PluginMarketDetail);
+}
+
+async function waitForSettledBatch(): Promise<void> {
+ await vi.waitFor(() => {
+ const state = getUpdateAllBatchState();
+ expect(state.running).toBe(false);
+ expect(state.rows?.some((row) => row.status === 'pending')).toBe(false);
+ });
+}
+
+beforeEach(() => {
+ __resetUpdateAllBatchForTest();
+ detailMock.mockReset();
+ installMock.mockClear();
+ installedGhosts = [{ manifest: manifest({ version: '1.0.0' }) }];
+ (window as unknown as { electronAPI: unknown }).electronAPI = {
+ pluginMarket: { detail: detailMock, install: installMock },
+ };
+});
+
+describe('updateAllController', () => {
+ it('skips rows whose plugin was uninstalled mid-batch instead of reinstalling', async () => {
+ installedGhosts = [];
+ stubDetail({ manifest: manifest({}), sourceType: 'server' });
+
+ startUpdateAllBatch([marketItem({})]);
+ await waitForSettledBatch();
+
+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('skipped');
+ expect(installMock).not.toHaveBeenCalled();
+ });
+
+ it('passes the reviewed manifest back when approving a non-server expansion', async () => {
+ const nextManifest = manifest({ network: { hosts: ['api.example.com'] } });
+ stubDetail({ manifest: nextManifest, sourceType: 'git-market' });
+
+ startUpdateAllBatch([marketItem({ sourceType: 'git-market' })]);
+ await waitForSettledBatch();
+
+ const held = getUpdateAllBatchState().rows?.[0];
+ expect(held?.status).toBe('needs-confirm');
+ expect(held?.expectedManifest).toBe(nextManifest);
+
+ await approveUpdateExpansion('plugin-a');
+ expect(installMock).toHaveBeenCalledWith('plugin-a', {
+ expectedReleaseId: 'release-2',
+ expectedManifest: nextManifest,
+ allowPermissionExpansion: true,
+ });
+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');
+ });
+
+ it('omits expectedManifest when approving a server-source expansion', async () => {
+ stubDetail({
+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),
+ sourceType: 'server',
+ });
+
+ startUpdateAllBatch([marketItem({})]);
+ await waitForSettledBatch();
+ await approveUpdateExpansion('plugin-a');
+
+ expect(installMock).toHaveBeenCalledWith('plugin-a', {
+ expectedReleaseId: 'release-2',
+ allowPermissionExpansion: true,
+ });
+ });
+
+ it('turns approval into a skip when the plugin was uninstalled while waiting', async () => {
+ stubDetail({
+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),
+ sourceType: 'server',
+ });
+
+ startUpdateAllBatch([marketItem({})]);
+ await waitForSettledBatch();
+
+ installedGhosts = [];
+ await approveUpdateExpansion('plugin-a');
+
+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('skipped');
+ expect(installMock).not.toHaveBeenCalled();
+ });
+
+ it('keeps pending confirmations readable after the page unsubscribes (unmount)', async () => {
+ stubDetail({
+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),
+ sourceType: 'server',
+ });
+
+ startUpdateAllBatch([marketItem({})]);
+ await waitForSettledBatch();
+
+ // 模块级状态与页面订阅无关:卸载(无订阅者)后快照仍保留待确认行,
+ // 重新进页可以直接恢复批准/跳过入口。
+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('needs-confirm');
+ });
+});
diff --git a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts
new file mode 100644
index 0000000000..8472130299
--- /dev/null
+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts
@@ -0,0 +1,198 @@
+/**
+ * Window-level controller for the "update all plugins" batch flow.
+ *
+ * Inputs: the market update snapshot plus user approve/skip actions.
+ * Outputs: a subscribable batch snapshot for the Plugin page and the
+ * serial install IPC calls.
+ *
+ * 为什么在组件外:批次可以在用户关掉弹窗、离开 /plugins 后继续跑
+ * (「后台继续」语义),待确认的扩权项也必须在回到插件页后仍然保留
+ * 批准/跳过入口——状态生命周期必须长于页面组件,所以照
+ * useInstalledGhosts 的先例做成模块级单例 store。
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
+ */
+
+import { i18n } from '@/i18n';
+import { toast } from '@/lib/toast';
+import { readInstalledGhostsSnapshot } from '@/cindy-brain/useInstalledGhosts';
+import { diffGhostPermissionItems, type GhostManifest } from '../../../../shared/ghost';
+import type { PluginMarketItem } from '../../../../shared/pluginMarket';
+import { pluginMarketErrorKey } from './pluginMarketErrorKey';
+import {
+ batchSummary,
+ buildUpdateAllRows,
+ isBatchFinished,
+ updateRow,
+ type UpdateAllRow,
+} from './updateAllModel';
+
+export interface UpdateAllBatchState {
+ /** null = 从未启动过批次;数组引用随每次行迁移变化(快照语义)。 */
+ rows: UpdateAllRow[] | null;
+ running: boolean;
+}
+
+interface UpdateAllBatchHooks {
+ /** 批次推进后的市场快照刷新;页面卸载期间缺席,重新进页会全量刷新。 */
+ refreshMarket?: () => Promise<void>;
+}
+
+let state: UpdateAllBatchState = { rows: null, running: false };
+let finishToastShown = false;
+let hooks: UpdateAllBatchHooks = {};
+const listeners = new Set<() => void>();
+
+function emit(next: UpdateAllBatchState): void {
+ state = next;
+ listeners.forEach((listener) => listener());
+}
+
+function patchRow(pluginId: string, patch: Partial<UpdateAllRow>): void {
+ emit({ ...state, rows: updateRow(state.rows ?? [], pluginId, patch) });
+}
+
+export function subscribeUpdateAllBatch(listener: () => void): () => void {
+ listeners.add(listener);
+ return () => {
+ listeners.delete(listener);
+ };
+}
+
+export function getUpdateAllBatchState(): UpdateAllBatchState {
+ return state;
+}
+
+/** 页面挂载期注册环境回调;返回的清理函数在卸载时注销。 */
+export function setUpdateAllBatchHooks(next: UpdateAllBatchHooks): () => void {
+ hooks = next;
+ return () => {
+ if (hooks === next) hooks = {};
+ };
+}
+
+function installedManifestOf(ghostId: string): GhostManifest | null {
+ return (
+ readInstalledGhostsSnapshot().find((ghost) => ghost.manifest.id === ghostId)?.manifest ?? null
+ );
+}
+
+async function refreshMarketIfMounted(): Promise<void> {
+ try {
+ await hooks.refreshMarket?.();
+ } catch {
+ // 快照刷新失败不影响批次结果;下次进页会重新拉取。
+ }
+}
+
+function maybeFinishToast(): void {
+ const rows = state.rows;
+ if (!rows || rows.length === 0 || !isBatchFinished(rows) || finishToastShown) return;
+ finishToastShown = true;
+ const summary = batchSummary(rows);
+ toast.success(
+ i18n.t('settings.ghosts.updateAll.doneToast', {
+ done: summary.done,
+ rest: summary.skipped + summary.failed,
+ }),
+ );
+}
+
+/** 启动新批次(运行中调用是 no-op;是否复用未完成批次由页面判断)。 */
+export function startUpdateAllBatch(marketUpdates: readonly PluginMarketItem[]): void {
+ if (state.running) return;
+ const installedVersionById = new Map(
+ readInstalledGhostsSnapshot().map((ghost) => [ghost.manifest.id, ghost.manifest.version]),
+ );
+ finishToastShown = false;
+ emit({ rows: buildUpdateAllRows(marketUpdates, installedVersionById), running: false });
+ void runQueue();
+}
+
+/** 批量 runner:串行走「取详情 → 权限 diff → 无扩权直接装 / 有扩权停待确认」。 */
+async function runQueue(): Promise<void> {
+ if (state.running) return;
+ emit({ ...state, running: true });
+ try {
+ for (;;) {
+ const next = (state.rows ?? []).find((row) => row.status === 'pending');
+ if (!next) break;
+ patchRow(next.pluginId, { status: 'installing' });
+ try {
+ const detail = await window.electronAPI.pluginMarket.detail(next.pluginId);
+ const installedManifest = installedManifestOf(next.ghostId);
+ if (!installedManifest) {
+ // 批量期间插件已被卸载:绝不拿市场 manifest 兜底继续安装
+ // (那会把用户刚卸载的插件重新装回来),该行按跳过收束。
+ patchRow(next.pluginId, { status: 'skipped' });
+ continue;
+ }
+ const diff = diffGhostPermissionItems(installedManifest, detail.manifest);
+ if (diff.added.length > 0) {
+ // 扩权不自动放行:停在待确认,由用户在弹窗里逐项同意或跳过。
+ patchRow(next.pluginId, {
+ status: 'needs-confirm',
+ releaseId: detail.releaseId,
+ permissionDiff: diff,
+ ...(detail.sourceType !== 'server' ? { expectedManifest: detail.manifest } : {}),
+ });
+ continue;
+ }
+ await window.electronAPI.pluginMarket.install(next.pluginId, {
+ expectedReleaseId: detail.releaseId,
+ ...(detail.sourceType !== 'server' ? { expectedManifest: detail.manifest } : {}),
+ });
+ patchRow(next.pluginId, { status: 'done' });
+ } catch (error) {
+ patchRow(next.pluginId, {
+ status: 'failed',
+ errorText: i18n.t(pluginMarketErrorKey(error)),
+ });
+ }
+ }
+ } finally {
+ emit({ ...state, running: false });
+ await refreshMarketIfMounted();
+ maybeFinishToast();
+ }
+}
+
+/** 用户在弹窗里同意某个扩权项后继续安装。 */
+export async function approveUpdateExpansion(pluginId: string): Promise<void> {
+ const row = state.rows?.find((candidate) => candidate.pluginId === pluginId);
+ if (!row || row.status !== 'needs-confirm' || !row.releaseId) return;
+ if (installedManifestOf(row.ghostId) === null) {
+ // 待确认期间插件被卸载:同意也不重装,按跳过收束。
+ patchRow(pluginId, { status: 'skipped' });
+ maybeFinishToast();
+ return;
+ }
+ patchRow(pluginId, { status: 'installing' });
+ try {
+ await window.electronAPI.pluginMarket.install(pluginId, {
+ expectedReleaseId: row.releaseId,
+ ...(row.expectedManifest ? { expectedManifest: row.expectedManifest } : {}),
+ allowPermissionExpansion: true,
+ });
+ patchRow(pluginId, { status: 'done' });
+ } catch (error) {
+ patchRow(pluginId, { status: 'failed', errorText: i18n.t(pluginMarketErrorKey(error)) });
+ }
+ await refreshMarketIfMounted();
+ maybeFinishToast();
+}
+
+/** 用户在弹窗里跳过某个扩权项。 */
+export function skipUpdateExpansion(pluginId: string): void {
+ const row = state.rows?.find((candidate) => candidate.pluginId === pluginId);
+ if (!row || row.status !== 'needs-confirm') return;
+ patchRow(pluginId, { status: 'skipped' });
+ maybeFinishToast();
+}
+
+/** 仅测试用:清空模块级批次状态与回调注册。 */
+export function __resetUpdateAllBatchForTest(): void {
+ state = { rows: null, running: false };
+ finishToastShown = false;
+ hooks = {};
+ listeners.clear();
+}
diff --git a/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts b/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts
index 8e603bad6f..1708b6cb33 100644
--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts
+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts
@@ -7,7 +7,7 @@
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
*/
-import type { GhostPermissionDiff } from '../../../../shared/ghost';
+import type { GhostManifest, GhostPermissionDiff } from '../../../../shared/ghost';
import type { PluginMarketItem } from '../../../../shared/pluginMarket';
/**
@@ -33,6 +33,11 @@ export interface UpdateAllRow {
releaseId?: string;
/** 扩权详情(status 为 needs-confirm 时由运行器填充)。 */
permissionDiff?: GhostPermissionDiff;
+ /**
+ * 非 server 源在审阅时取得的 manifest:主进程对这类来源强制要求安装时
+ * 传回同一份 reviewed manifest,approve 必须原样带上,否则 INVALID_PARAMS。
+ */
+ expectedManifest?: GhostManifest;
/** status 为 failed 时的用户可读错误(已经过 i18n 映射)。 */
errorText?: string;
}
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index b070a1c3f0..7d994a79c8 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -3517,7 +3517,7 @@
},
"updateAll": {
"title": "全部更新 · {{count}} 个插件",
- "description": "权限无变化的更新会自动完成;涉及权限变更的需要你逐项确认。",
+ "description": "权限无变化的更新会自动完成;涉及权限变更的需要你逐项确认。",
"versionRange": "v{{from}} → v{{to}}",
"permissionChanged": "权限有变更",
"reviewDiff": "查看并确认",
@@ -3531,7 +3531,7 @@
"statusFailed": "更新失败",
"background": "后台继续",
"doneAction": "完成",
- "doneToast": "批量更新完成:{{done}} 个已更新,{{rest}} 个未完成"
+ "doneToast": "批量更新完成:{{done}} 个已更新,{{rest}} 个未完成"
}
},
"mcp": {