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(desktop): 插件更新后留在列表并去掉重复确认 (#2871)

Dash98929118d638
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/packagePermissionReview.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/packagePermissionReview.test.ts
new file mode 100644
index 0000000000..d3a40b9adf
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/packagePermissionReview.test.ts
@@ -0,0 +1,314 @@
+import { describe, expect, it } from 'vitest';
+
+import type { GhostManifest } from '../../../shared/ghost';
+import {
+ marketPackageHostReviewDiff,
+ marketPackageManualSummaryChanged,
+ marketPackageNeedsHostReview,
+ marketPackageOauthIdentityChanged,
+} from '../packagePermissionReview';
+
+describe('marketPackageNeedsHostReview', () => {
+ it('skips Host when the user already reviewed every permission in the real package', () => {
+ expect(
+ marketPackageNeedsHostReview({
+ mode: 'manual',
+ builtinOauthClientChanged: false,
+ addedCount: null,
+ unreviewedCount: 0,
+ extrasVersusReviewedCount: 0,
+ }),
+ ).toBe(false);
+ });
+
+ it('reviews Host when the real package adds permissions the preview missed', () => {
+ expect(
+ marketPackageNeedsHostReview({
+ mode: 'manual',
+ builtinOauthClientChanged: false,
+ addedCount: null,
+ unreviewedCount: 0,
+ extrasVersusReviewedCount: 1,
+ }),
+ ).toBe(true);
+ });
+
+ it('reviews a first manual install when no preview confirmation was supplied', () => {
+ expect(
+ marketPackageNeedsHostReview({
+ mode: 'manual',
+ builtinOauthClientChanged: false,
+ addedCount: null,
+ unreviewedCount: 0,
+ extrasVersusReviewedCount: null,
+ }),
+ ).toBe(true);
+ });
+
+ it('skips a same-permission manual update when no preview confirmation was supplied', () => {
+ expect(
+ marketPackageNeedsHostReview({
+ mode: 'manual',
+ builtinOauthClientChanged: false,
+ addedCount: 0,
+ unreviewedCount: 0,
+ extrasVersusReviewedCount: null,
+ }),
+ ).toBe(false);
+ });
+
+ it('always reviews when the built-in OAuth client changed', () => {
+ expect(
+ marketPackageNeedsHostReview({
+ mode: 'manual',
+ builtinOauthClientChanged: true,
+ addedCount: 0,
+ unreviewedCount: 0,
+ extrasVersusReviewedCount: 0,
+ }),
+ ).toBe(true);
+ });
+
+ it('reviews when only the bundled manual summary changed', () => {
+ expect(
+ marketPackageNeedsHostReview({
+ mode: 'manual',
+ builtinOauthClientChanged: false,
+ manualSummaryChanged: true,
+ addedCount: 0,
+ unreviewedCount: 0,
+ extrasVersusReviewedCount: 0,
+ }),
+ ).toBe(true);
+ });
+});
+
+function oauthManifest(clientId: string): GhostManifest {
+ return {
+ schemaVersion: 2,
+ id: 'oauth-plugin',
+ name: 'OAuth Plugin',
+ version: '1.0.0',
+ kind: 'chip',
+ entry: 'main.js',
+ slots: ['network'],
+ network: {
+ hosts: ['api.example.com'],
+ secrets: [
+ {
+ key: 'account',
+ label: 'Account',
+ source: 'oauth',
+ inject: { header: 'Authorization', format: 'Bearer {value}' },
+ oauth: {
+ authorizeUrl: 'https://accounts.example.com/authorize',
+ tokenUrl: 'https://accounts.example.com/token',
+ clientId,
+ },
+ },
+ ],
+ },
+ };
+}
+
+describe('marketPackageOauthIdentityChanged', () => {
+ it('detects a clientId mismatch between the reviewed catalog and the real package', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthManifest('preview-client'),
+ oauthManifest('real-client'),
+ oauthManifest('real-client'),
+ ),
+ ).toBe(true);
+ });
+
+ it('detects a clientId mismatch between the installed baseline and the real package', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthManifest('old-client'),
+ oauthManifest('old-client'),
+ oauthManifest('new-client'),
+ ),
+ ).toBe(true);
+ });
+
+ it('stays quiet when reviewed, installed, and real package share the same client', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthManifest('same-client'),
+ oauthManifest('same-client'),
+ oauthManifest('same-client'),
+ ),
+ ).toBe(false);
+ });
+
+ it('reviews when the catalog omitted clientId but the real package introduces one', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthManifest(''),
+ oauthManifest('real-client'),
+ oauthManifest('real-client'),
+ ),
+ ).toBe(true);
+ expect(
+ marketPackageOauthIdentityChanged(oauthManifest(''), null, oauthManifest('real-client')),
+ ).toBe(true);
+ });
+
+ it('does not treat an installed empty clientId gaining a default as a migration', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthManifest('real-client'),
+ oauthManifest(''),
+ oauthManifest('real-client'),
+ ),
+ ).toBe(false);
+ });
+
+ it('reviews when a reviewed tokenBroker slot becomes a direct clientId', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthBrokerManifest(),
+ oauthBrokerManifest(),
+ oauthManifest('direct-client'),
+ ),
+ ).toBe(true);
+ expect(
+ marketPackageOauthIdentityChanged(oauthBrokerManifest(), null, oauthManifest('direct-client')),
+ ).toBe(true);
+ });
+
+ it('reviews when a reviewed direct clientId becomes a tokenBroker', () => {
+ expect(
+ marketPackageOauthIdentityChanged(
+ oauthManifest('direct-client'),
+ oauthManifest('direct-client'),
+ oauthBrokerManifest(),
+ ),
+ ).toBe(true);
+ });
+});
+
+function oauthBrokerManifest(): GhostManifest {
+ const manifest = oauthManifest('broker-client');
+ const secret = manifest.network?.secrets?.[0];
+ if (secret?.oauth) {
+ secret.oauth.tokenBroker = 'cindy';
+ }
+ return manifest;
+}
+
+function manualManifest(items: Array<{ name: string; dir: string; description: string }>): GhostManifest {
+ return {
+ schemaVersion: 2,
+ id: 'manual-plugin',
+ name: 'Manual Plugin',
+ version: '1.0.0',
+ kind: 'chip',
+ entry: 'main.js',
+ slots: ['notify'],
+ ...(items.length > 0 ? { manual: { items } } : {}),
+ };
+}
+
+describe('marketPackageManualSummaryChanged', () => {
+ const guide = {
+ name: 'getting-started',
+ dir: 'manual/getting-started',
+ description: 'Start here',
+ };
+
+ it('stays quiet when reviewed and real package share the same manuals', () => {
+ expect(marketPackageManualSummaryChanged(manualManifest([guide]), manualManifest([guide]))).toBe(
+ false,
+ );
+ });
+
+ it('detects a count change between the reviewed catalog and the real package', () => {
+ expect(marketPackageManualSummaryChanged(manualManifest([]), manualManifest([guide]))).toBe(
+ true,
+ );
+ });
+
+ it('detects a swapped manual identity even when the count stays the same', () => {
+ expect(
+ marketPackageManualSummaryChanged(
+ manualManifest([guide]),
+ manualManifest([
+ { name: 'ops', dir: 'manual/ops', description: 'Operations' },
+ ]),
+ ),
+ ).toBe(true);
+ });
+
+ it('does not invent a reviewed baseline when the caller omitted the catalog', () => {
+ expect(marketPackageManualSummaryChanged(undefined, manualManifest([guide]))).toBe(false);
+ });
+
+ it('does not treat a newline inside one description as two manuals', () => {
+ expect(
+ marketPackageManualSummaryChanged(
+ manualManifest([
+ { name: 'a', dir: 'x', description: 'd\nb\0y\0e' },
+ ]),
+ manualManifest([
+ { name: 'a', dir: 'x', description: 'd' },
+ { name: 'b', dir: 'y', description: 'e' },
+ ]),
+ ),
+ ).toBe(true);
+ });
+});
+
+const emptyDiff = {
+ added: [],
+ removed: [],
+ unchanged: [],
+ builtinOauthClientChanged: false,
+};
+
+describe('marketPackageHostReviewDiff', () => {
+ it('does not synthesize an empty update diff on first install', () => {
+ expect(
+ marketPackageHostReviewDiff({
+ permissionDiff: null,
+ extrasVersusReviewedCount: 1,
+ builtinOauthClientChanged: true,
+ manualSummaryChanged: false,
+ }),
+ ).toBeNull();
+ });
+
+ it('uses the full package card when extras exist even if the installed diff is empty', () => {
+ expect(
+ marketPackageHostReviewDiff({
+ permissionDiff: emptyDiff,
+ extrasVersusReviewedCount: 2,
+ builtinOauthClientChanged: false,
+ manualSummaryChanged: false,
+ }),
+ ).toBeNull();
+ });
+
+ it('uses the full package card when only the manual summary changed', () => {
+ expect(
+ marketPackageHostReviewDiff({
+ permissionDiff: emptyDiff,
+ extrasVersusReviewedCount: 0,
+ builtinOauthClientChanged: false,
+ manualSummaryChanged: true,
+ }),
+ ).toBeNull();
+ });
+
+ it('keeps an update diff when only the OAuth identity changed', () => {
+ expect(
+ marketPackageHostReviewDiff({
+ permissionDiff: emptyDiff,
+ extrasVersusReviewedCount: 0,
+ builtinOauthClientChanged: true,
+ manualSummaryChanged: false,
+ }),
+ ).toEqual({ ...emptyDiff, builtinOauthClientChanged: true });
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index 067056251f..307292184f 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -78,7 +78,13 @@ import { exportGhostPackage } from './exportGhostPackage.js';
import { GhostMutationCoordinator } from './ghostMutationCoordinator.js';
import { createOneShotTicketStore } from './oneShotTickets.js';
import { withGhostInstallLock } from './ghostInstallLock.js';
-import { GhostPackagePermissionReviewRequiredError } from './packagePermissionReview.js';
+import {
+ GhostPackagePermissionReviewRequiredError,
+ marketPackageHostReviewDiff,
+ marketPackageManualSummaryChanged,
+ marketPackageNeedsHostReview,
+ marketPackageOauthIdentityChanged,
+} from './packagePermissionReview.js';
import {
clearBuiltinTombstone,
listEligibleBuiltinCommands,
@@ -4569,14 +4575,17 @@ export async function installOrUpdateMarketGhostPackage(
/** receipt 模型并发护栏:更新分支比对 receipt 派生 token(与 main 硬化叠加,决策 A)。 */
expectedInstalledApproval?: string;
/**
- * 手动首装确认真实包、同来源更新仅在真实包扩权时确认;默认安装只把
- * 市场目录 manifest 当作 fail-closed 权限上限。目录 manifest 不记作批准。
+ * 用户已确认的 reviewedManifest 是权限上限:真实包没有超出则不再弹 Host。
+ * 没有这份上限时,手动首装仍确认真实包,同来源更新仅在相对已装基线扩权时确认。
+ * 默认安装(cap)只把目录 manifest 当作 fail-closed 上限,目录本身不记作批准。
*/
permissionPolicy?:
| { mode: 'manual'; sourceType: PluginMarketItemSource }
| { mode: 'cap'; manifest: GhostManifest; sourceType: PluginMarketItemSource };
/** 安装锁内从当前已落位包读取的 canonical 权限基线。 */
permissionBaselineManifest?: GhostManifest;
+ /** 用户已在页面确认过的权限清单;真实包未超出则跳过 Host。 */
+ reviewedManifest?: GhostManifest;
/** 用户确认过的真实下载包 SHA 与确认时的已装权限基线。 */
approvedPackageSha256?: string;
reviewedBaseline?: string;
@@ -4605,6 +4614,7 @@ async function installOrUpdateMarketGhostPackageLocked(
| { mode: 'manual'; sourceType: PluginMarketItemSource }
| { mode: 'cap'; manifest: GhostManifest; sourceType: PluginMarketItemSource };
permissionBaselineManifest?: GhostManifest;
+ reviewedManifest?: GhostManifest;
approvedPackageSha256?: string;
reviewedBaseline?: string;
beforeCommitInLock?: () => void;
@@ -4675,29 +4685,59 @@ async function installOrUpdateMarketGhostPackageLocked(
inspected.canonicalManifest,
)
: [];
- const needsReview =
- permissionDiff?.builtinOauthClientChanged === true ||
- (expected.permissionPolicy.mode === 'manual'
- ? permissionDiff === null || permissionDiff.added.length > 0
- : unreviewed.length > 0);
+ const extrasVersusReviewed = expected.reviewedManifest
+ ? unreviewedGhostPermissionItems(
+ expected.reviewedManifest,
+ baselineManifest ?? undefined,
+ inspected.canonicalManifest,
+ )
+ : null;
+ const builtinOauthClientChanged = marketPackageOauthIdentityChanged(
+ expected.reviewedManifest,
+ baselineManifest,
+ inspected.canonicalManifest,
+ );
+ const manualSummaryChanged = marketPackageManualSummaryChanged(
+ expected.reviewedManifest,
+ inspected.canonicalManifest,
+ );
+ const needsReview = marketPackageNeedsHostReview({
+ mode: expected.permissionPolicy.mode,
+ builtinOauthClientChanged,
+ manualSummaryChanged,
+ addedCount: permissionDiff === null ? null : permissionDiff.added.length,
+ unreviewedCount: unreviewed.length,
+ extrasVersusReviewedCount:
+ extrasVersusReviewed === null ? null : extrasVersusReviewed.length,
+ });
if (needsReview && expected.approvedPackageSha256 === undefined) {
const reviewKeys =
- expected.permissionPolicy.mode === 'manual'
- ? (permissionDiff?.added.map((item) => item.key) ?? [])
- : unreviewed.map((item) => item.key);
+ extrasVersusReviewed !== null
+ ? extrasVersusReviewed.map((item) => item.key)
+ : expected.permissionPolicy.mode === 'manual'
+ ? (permissionDiff?.added.map((item) => item.key) ?? [])
+ : unreviewed.map((item) => item.key);
+ const reviewDiff = marketPackageHostReviewDiff({
+ permissionDiff,
+ extrasVersusReviewedCount:
+ extrasVersusReviewed === null ? null : extrasVersusReviewed.length,
+ builtinOauthClientChanged,
+ manualSummaryChanged,
+ });
const review: PluginMarketPackageReviewFacts = {
manifest: inspected.manifest,
- permissionDiff,
+ permissionDiff: reviewDiff,
isUpdate: installed !== undefined,
packageSha256: inspected.packageSha256,
installedBaseline,
sourceType: expected.permissionPolicy.sourceType,
+ builtinOauthClientChanged,
};
log.info('market package requires permission review', {
ghostId: expected.ghostId,
mode: expected.permissionPolicy.mode,
keys: reviewKeys,
- builtinOauthClientChanged: permissionDiff?.builtinOauthClientChanged === true,
+ builtinOauthClientChanged,
});
throw new GhostPackagePermissionReviewRequiredError(review);
}
diff --git a/apps/desktop/src/main/cindy-brain/packagePermissionReview.ts b/apps/desktop/src/main/cindy-brain/packagePermissionReview.ts
index fc00661af2..5c8c4bca5a 100644
--- a/apps/desktop/src/main/cindy-brain/packagePermissionReview.ts
+++ b/apps/desktop/src/main/cindy-brain/packagePermissionReview.ts
@@ -1,3 +1,8 @@
+import {
+ type GhostManifest,
+ type GhostSecretDecl,
+ type GhostPermissionDiff,
+} from '../../shared/ghost.js';
import type { PluginMarketPackageReviewFacts } from '../../shared/pluginMarket.js';
/** 真实安装包需要用户复核时,交给 PluginMarketService 转成可恢复结果。 */
@@ -6,3 +11,131 @@ export class GhostPackagePermissionReviewRequiredError extends Error {
super('The downloaded Plugin package requires permission review');
}
}
+
+/**
+ * 下载后是否还要弹窗口级 Host 权限卡。
+ * 用户已经确认过的清单(reviewed)当作上限:真实包没有超出部分就不再弹;
+ * 没有这份上限时,手动首装仍审真实包,更新只在相对已装基线扩权时审。
+ */
+export function marketPackageNeedsHostReview(input: {
+ mode: 'manual' | 'cap';
+ builtinOauthClientChanged: boolean;
+ /** 已审预览与真实包的随包手册摘要不一致。 */
+ manualSummaryChanged?: boolean;
+ /** null = 没有已装批准基线。 */
+ addedCount: number | null;
+ unreviewedCount: number;
+ /** null = 调用方没有把用户已确认的清单传来。 */
+ extrasVersusReviewedCount: number | null;
+}): boolean {
+ if (input.builtinOauthClientChanged) return true;
+ if (input.manualSummaryChanged) return true;
+ if (input.extrasVersusReviewedCount !== null) {
+ return input.extrasVersusReviewedCount > 0;
+ }
+ if (input.mode === 'manual') {
+ return input.addedCount === null || input.addedCount > 0;
+ }
+ return input.unreviewedCount > 0;
+}
+
+/**
+ * 内置 OAuth clientId 是否相对用户已确认的清单或已装基线发生了变化。
+ * 权限投影不含 clientId,必须单独比;已装基线与预览清单都要比真实包。
+ */
+export function marketPackageOauthIdentityChanged(
+ reviewed: GhostManifest | undefined,
+ installedBaseline: GhostManifest | null,
+ actual: GhostManifest,
+): boolean {
+ // 已装基线空 clientId→默认值不算迁移(令牌仍有效)。已审预览则相反。
+ if (
+ installedBaseline &&
+ oauthIdentitiesChanged(installedBaseline, actual, { emptyDirectToConcreteCounts: false })
+ ) {
+ return true;
+ }
+ if (!reviewed) return false;
+ return oauthIdentitiesChanged(reviewed, actual, { emptyDirectToConcreteCounts: true });
+}
+
+/**
+ * Host 卡要展示触发复核的全部事实。没有已装基线、真实包相对已审清单多了权限、
+ * 或手册摘要变了时,回 null,让界面改走完整真实包清单,不要合成「权限无变化」。
+ */
+export function marketPackageHostReviewDiff(input: {
+ permissionDiff: GhostPermissionDiff | null;
+ extrasVersusReviewedCount: number | null;
+ builtinOauthClientChanged: boolean;
+ manualSummaryChanged: boolean;
+}): GhostPermissionDiff | null {
+ const extrasExist = (input.extrasVersusReviewedCount ?? 0) > 0;
+ if (input.permissionDiff === null || extrasExist || input.manualSummaryChanged) {
+ return null;
+ }
+ return {
+ ...input.permissionDiff,
+ builtinOauthClientChanged:
+ input.permissionDiff.builtinOauthClientChanged || input.builtinOauthClientChanged,
+ };
+}
+
+/**
+ * 已审预览与真实包的随包手册是否不一致。
+ * 页面确认只展示手册条数与条目身份;真实包改了这些事实就必须再审。
+ */
+export function marketPackageManualSummaryChanged(
+ reviewed: GhostManifest | undefined,
+ actual: GhostManifest,
+): boolean {
+ if (!reviewed) return false;
+ return manualSummaryKey(reviewed) !== manualSummaryKey(actual);
+}
+
+function manualSummaryKey(manifest: GhostManifest): string {
+ const items = (manifest.manual?.items ?? []).map((item) => ({
+ name: item.name,
+ dir: item.dir,
+ description: item.description,
+ }));
+ items.sort((left, right) => {
+ if (left.name !== right.name) return left.name < right.name ? -1 : 1;
+ if (left.dir !== right.dir) return left.dir < right.dir ? -1 : 1;
+ return 0;
+ });
+ return JSON.stringify(items);
+}
+
+function oauthIdentityKey(secret: GhostSecretDecl): string | null {
+ if (secret.source !== 'oauth' || !secret.oauth) return null;
+ if (secret.oauth.tokenBroker) return `broker:${secret.oauth.tokenBroker}`;
+ return `direct:${secret.oauth.clientId?.trim() || ''}`;
+}
+
+function oauthIdentitiesChanged(
+ previousManifest: GhostManifest,
+ actual: GhostManifest,
+ options: { emptyDirectToConcreteCounts: boolean },
+): boolean {
+ if (previousManifest.id !== actual.id) return false;
+ const previousByKey = new Map(
+ (previousManifest.network?.secrets ?? []).map((secret) => [secret.key, secret]),
+ );
+ for (const current of actual.network?.secrets ?? []) {
+ const currentIdentity = oauthIdentityKey(current);
+ if (!currentIdentity) continue;
+ const previous = previousByKey.get(current.key);
+ if (!previous) continue;
+ const previousIdentity = oauthIdentityKey(previous);
+ if (!previousIdentity || previousIdentity === currentIdentity) continue;
+ if (
+ !options.emptyDirectToConcreteCounts &&
+ previousIdentity === 'direct:' &&
+ currentIdentity.startsWith('direct:')
+ ) {
+ continue;
+ }
+ return true;
+ }
+ return false;
+}
diff --git a/apps/desktop/src/main/plugin-market/__tests__/packagePermissionReviewBridge.test.ts b/apps/desktop/src/main/plugin-market/__tests__/packagePermissionReviewBridge.test.ts
index e3995a0c17..8d0caa424b 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/packagePermissionReviewBridge.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/packagePermissionReviewBridge.test.ts
@@ -18,6 +18,7 @@ const facts: PluginMarketPackageReviewFacts = {
packageSha256: 'a'.repeat(64),
installedBaseline: null,
sourceType: 'server',
+ builtinOauthClientChanged: false,
};
const ownerStamp = { dataOwnerId: 'owner-a', ownerGeneration: 7 };
diff --git a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
index 2eaac04185..af28813734 100644
--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts
@@ -230,6 +230,7 @@ function detail(
function reviewedInstallOptions(item: VisiblePluginSummary, allowSourceReplacement = false) {
return {
expectedReleaseId: item.currentRelease.id,
+ expectedManifest: manifest(item.ghostId, item.currentRelease.version),
allowSourceReplacement,
};
}
@@ -1070,11 +1071,15 @@ describe('PluginMarketService migration and defaultInstall', () => {
const { ghost } = await h.service.install(item.id, reviewedInstallOptions(item));
- expect(runtime.install).toHaveBeenCalledWith(expect.stringMatching(/\.cindy$/), {
- ghostId: 'cindy-test',
- version: '1.0.0',
- permissionPolicy: { mode: 'manual', sourceType: 'server' },
- });
+ expect(runtime.install).toHaveBeenCalledWith(
+ expect.stringMatching(/\.cindy$/),
+ expect.objectContaining({
+ ghostId: 'cindy-test',
+ version: '1.0.0',
+ permissionPolicy: { mode: 'manual', sourceType: 'server' },
+ reviewedManifest: expect.objectContaining({ id: 'cindy-test' }),
+ }),
+ );
// 安装入口用目录 summary 做 detail 身份绑定(防止把 A 的确认导向 B 的内容),
// 因此手动安装也会先取一次目录,但不做任何 listAll 之外的多余请求。
expect(h.api.listAll).toHaveBeenCalledTimes(1);
@@ -1155,11 +1160,14 @@ describe('PluginMarketService migration and defaultInstall', () => {
});
const ordinaryHarness = harness([ordinary]);
await ordinaryHarness.service.install(ordinary.id, reviewedInstallOptions(ordinary));
- expect(runtime.install.mock.calls[0]?.[1]).toEqual({
- ghostId: 'cindy-test',
- version: '1.0.0',
- permissionPolicy: { mode: 'manual', sourceType: 'server' },
- });
+ expect(runtime.install.mock.calls[0]?.[1]).toEqual(
+ expect.objectContaining({
+ ghostId: 'cindy-test',
+ version: '1.0.0',
+ permissionPolicy: { mode: 'manual', sourceType: 'server' },
+ reviewedManifest: expect.objectContaining({ id: 'cindy-test' }),
+ }),
+ );
});
it('旧 source:market + manifestDigest 安装会回填 cindy-github 官方 trust', async () => {
@@ -1414,6 +1422,7 @@ describe('PluginMarketService migration and defaultInstall', () => {
expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({
permissionPolicy: { mode: 'manual', sourceType: 'server' },
+ reviewedManifest: expect.objectContaining({ id: item.ghostId }),
});
expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('permissionBaselineManifest');
});
diff --git a/apps/desktop/src/main/plugin-market/install.ts b/apps/desktop/src/main/plugin-market/install.ts
index 9443a6c7f7..e5d14cd445 100644
--- a/apps/desktop/src/main/plugin-market/install.ts
+++ b/apps/desktop/src/main/plugin-market/install.ts
@@ -209,6 +209,7 @@ export async function installCustomMarketPlugin(input: {
...(input.permissionBaselineManifest
? { permissionBaselineManifest: input.permissionBaselineManifest }
: {}),
+ ...(input.expected ? { reviewedManifest: input.expected } : {}),
...(input.expectedInstalledApproval
? { expectedInstalledApproval: input.expectedInstalledApproval }
: {}),
diff --git a/apps/desktop/src/main/plugin-market/packagePermissionReviewBridge.ts b/apps/desktop/src/main/plugin-market/packagePermissionReviewBridge.ts
index 9ed54041b5..126ce60947 100644
--- a/apps/desktop/src/main/plugin-market/packagePermissionReviewBridge.ts
+++ b/apps/desktop/src/main/plugin-market/packagePermissionReviewBridge.ts
@@ -40,6 +40,7 @@ export class PluginMarketPackagePermissionReviewBridge {
permissionDiff: facts.permissionDiff,
isUpdate: facts.isUpdate,
sourceType: facts.sourceType,
+ builtinOauthClientChanged: facts.builtinOauthClientChanged,
});
} finally {
if (!delivered) this.settle(requestId, false);
diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.ts
index b9f2979cb4..975d5c131c 100644
--- a/apps/desktop/src/main/plugin-market/service.ts
+++ b/apps/desktop/src/main/plugin-market/service.ts
@@ -1015,6 +1015,7 @@ export class PluginMarketService {
// 用户从没见过,不能当作"已审阅"递进安装。与自定义来源路径
// install.ts:184-191 的打包前比对同向(但此处比对的是预览清单而非
// 实际打包字节,名字/版本/作者差异不在此处检测)。
+ let reviewedManifest: GhostManifest | undefined;
if (options.expectedManifest !== undefined) {
const reviewed = validateNormalizedGhostManifest(options.expectedManifest);
// 畸形 payload 会造成 ghostPermissionBaselineKey crash(slots.includes
@@ -1029,6 +1030,9 @@ export class PluginMarketService {
) {
throwIpcError('PRECONDITION_FAILED', 'Plugin manifest changed after permission review');
}
+ // 用户实际点过确认的那份清单才是已审上限。同 release 下服务端把
+ // OAuth clientId 换掉时,权限投影不变,不能把重新拉取的清单当成已审。
+ reviewedManifest = reviewed.manifest;
}
const existing = getGhostManager()
.list()
@@ -1037,7 +1041,7 @@ export class PluginMarketService {
plugin,
{
expectedInstalled: Boolean(existing),
- reviewedManifest: compatible.manifest,
+ ...(reviewedManifest ? { reviewedManifest } : {}),
...(options.expectedInstalledApproval !== undefined
? { expectedInstalledApproval: options.expectedInstalledApproval }
: {}),
@@ -1958,6 +1962,7 @@ export class PluginMarketService {
? {
permissionPolicy: options.permissionPolicy,
...(permissionBaselineManifest ? { permissionBaselineManifest } : {}),
+ ...(options.reviewedManifest ? { reviewedManifest: options.reviewedManifest } : {}),
}
: {}),
...(options.approvedPackageSha256 !== undefined
diff --git a/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx b/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx
index aab6ff57e5..5e4b5fdc8e 100644
--- a/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx
@@ -267,6 +267,26 @@ export function GhostTrustSummary({ trust }: { trust: GhostTrustInfo }) {
);
}
+export function GhostOauthClientChangedAlert({ className }: { className?: string }) {
+ const { t } = useTranslation();
+ return (
+ <div
+ role="alert"
+ className={cn(
+ 'flex items-start gap-2 rounded-lg bg-[var(--warning-bg-soft)] px-3 py-2 text-13 leading-5 text-[var(--text-secondary)]',
+ className,
+ )}
+ >
+ <ShieldAlert
+ size={16}
+ className="mt-0.5 shrink-0 text-[var(--warning-fg)]"
+ aria-hidden="true"
+ />
+ <span>{t('settings.ghosts.updateConfirm.oauthClientChanged')}</span>
+ </div>
+ );
+}
+
export function GhostManualSummary({ count }: { count: number }) {
const { t } = useTranslation();
if (count <= 0) return null;
@@ -434,25 +454,11 @@ export function GhostUpdateReview({
diff: GhostPermissionDiff;
manualCount?: number;
}) {
- const { t } = useTranslation();
return (
<div>
{trust && <GhostTrustSummary trust={trust} />}
{diff.builtinOauthClientChanged ? (
- <div
- role="alert"
- className={cn(
- trust && 'mt-3',
- 'flex items-start gap-2 rounded-lg bg-[var(--warning-bg-soft)] px-3 py-2 text-13 leading-5 text-[var(--text-secondary)]',
- )}
- >
- <ShieldAlert
- size={16}
- className="mt-0.5 shrink-0 text-[var(--warning-fg)]"
- aria-hidden="true"
- />
- <span>{t('settings.ghosts.updateConfirm.oauthClientChanged')}</span>
- </div>
+ <GhostOauthClientChangedAlert className={trust ? 'mt-3' : undefined} />
) : null}
<GhostManualSummary count={manualCount} />
<div
diff --git a/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx b/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx
index e4e273de01..4e1b09cc34 100644
--- a/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx
+++ b/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx
@@ -228,6 +228,8 @@ export function ConfirmDialog({
<button
ref={confirmBtnRef}
disabled={loading || confirmDisabled}
+ aria-busy={loading || undefined}
+ aria-label={resolvedConfirmText}
onClick={() => onConfirm?.({ dontShowAgain })}
className={cn(
'inline-flex min-w-[96px] items-center justify-center rounded-full px-6 py-2.5 text-13 font-medium',
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
index 4afb81c87e..e71f359d0d 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
@@ -58,6 +58,7 @@ import {
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { Switch } from '@/components/ui/switch';
import { toast } from '@/lib/toast';
+import { Spinner } from '@/components/ui/spinner';
import { cn } from '@/lib/utils';
import {
isOfficialGhostId,
@@ -289,6 +290,12 @@ export function GhostPluginDetailView({
type="button"
onClick={onUpdate}
disabled={updateBusy}
+ aria-label={
+ updateVersion === detail.version
+ ? t('settings.ghosts.market.update')
+ : t('settings.ghosts.market.updateTo', { version: updateVersion })
+ }
+ aria-busy={updateBusy || undefined}
className={cn(
'inline-flex h-10 items-center justify-center gap-1.5 rounded-full px-5 text-13 font-medium',
'bg-[var(--accent-cta-bg)] text-[var(--accent-pure-cta-fg)]',
@@ -297,10 +304,16 @@ export function GhostPluginDetailView({
'disabled:cursor-wait disabled:opacity-60 disabled:active:scale-100',
)}
>
- <ArrowUp size={14} aria-hidden="true" />
- {updateVersion === detail.version
- ? t('settings.ghosts.market.update')
- : t('settings.ghosts.market.updateTo', { version: updateVersion })}
+ {updateBusy ? (
+ <Spinner size={14} />
+ ) : (
+ <>
+ <ArrowUp size={14} aria-hidden="true" />
+ {updateVersion === detail.version
+ ? t('settings.ghosts.market.update')
+ : t('settings.ghosts.market.updateTo', { version: updateVersion })}
+ </>
+ )}
</button>
) : null}
{primaryAction !== 'manage' ? (
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
index 2a2e88fdb6..63c6a5f076 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
@@ -61,7 +61,12 @@ import {
pickAndUpdateGhost,
reapproveInstalledGhost,
} from '@/cindy-brain/installFlow';
-import { GhostPermissionList, GhostUpdateReview } from '@/cindy-brain/GhostPermissionList';
+import {
+ GhostManualSummary,
+ GhostPermissionList,
+ GhostUpdateReview,
+} from '@/cindy-brain/GhostPermissionList';
+import { Spinner } from '@/components/ui/spinner';
import { cn } from '@/lib/utils';
import { AttentionDot } from '@/components/sidebar/AttentionDot';
import {
@@ -285,6 +290,15 @@ export function marketUpdateAllowsPermissionExpansion(
return installed.approval.state !== 'approved' || addedPermissionCount > 0;
}
+/**
+ * 市场装入成功后是否打开已装详情(同时收起市场详情)。
+ * 首装:装完即开(2026-07-26)。更新/替换:留在当前页——列表就留列表,
+ * 市场详情就刷新详情,方便连续更新,也不把替换用户从原详情踢回列表。
+ */
+export function shouldOpenInstalledDetailAfterMarketSuccess(isUpdate: boolean): boolean {
+ return !isUpdate;
+}
+
/** 读「忽略本轮更新」的持久值(键按数据归属分桶,见 ignoredRoundStorageKey)。 */
function readIgnoredRound(storageKey: string): string {
try {
@@ -814,7 +828,7 @@ export function GhostPluginPage({
[t],
);
- /** 真实包的唯一权限确认由窗口级 Host 在这一次 install IPC 事务内完成。 */
+ /** 下载真实包;权限卡已在页面确认,Host 只在真实包超出已审清单时再弹。 */
const installReviewedMarketPackage = useCallback(
async (input: {
pluginId: string;
@@ -826,12 +840,11 @@ export function GhostPluginPage({
[],
);
- // 市场更新流程由列表卡片和详情页共用:先取目标 release 的完整 manifest 做
- // 权限 diff,经用户确认后才安装,不做静默升级。
+ // 市场更新流程由列表卡片和详情页共用:先按市场清单立刻弹出确认,下载发生在
+ // 用户点确认之后。真实包若没有超出已确认的权限,窗口级 Host 不再复弹。
//
// 同版本的 `installed` 也走这里:缺少批准状态的存量安装靠"用市场包重装同一
// release"恢复,此时权限 diff 会把目标包的全部权限当新增项逐条列出。
- // 所有来源先展示详情清单;官方包下载后仍以真实包清单兜底发现额外权限。
// 原位更新不切换来源(#2043):点击后详情若已不再是 update-available 则如实
// 提示状态变化,install 一律 allowSourceReplacement: false。
const handleMarketUpdate = useCallback(
@@ -865,18 +878,6 @@ export function GhostPluginPage({
return;
}
const diff = diffMarketUpdatePermissionItems(installedGhost, next.manifest);
- const approved = await confirm({
- title: t('settings.ghosts.updateConfirm.title', { name: next.name }),
- description: t('settings.ghosts.updateConfirm.body', {
- from: installedGhost?.manifest.version ?? next.version,
- to: next.version,
- }),
- content: <GhostUpdateReview diff={diff} />,
- maxWidth: 520,
- confirmText: t('settings.ghosts.updateConfirm.confirm'),
- cancelText: t('settings.ghosts.updateConfirm.cancel'),
- });
- if (!approved || !isMarketBusyLeaseActive(marketBusyLease)) return;
const options: PluginMarketInstallOptions = {
expectedReleaseId: next.releaseId,
expectedManifest: next.manifest,
@@ -891,18 +892,35 @@ export function GhostPluginPage({
// 原位更新不切换来源(#2043):只有冲突替换显式走 runMarketInstallFlow。
allowSourceReplacement: false,
};
+ const approved = await confirm({
+ title: t('settings.ghosts.updateConfirm.title', { name: next.name }),
+ description: t('settings.ghosts.updateConfirm.body', {
+ from: installedGhost?.manifest.version ?? next.version,
+ to: next.version,
+ }),
+ content: (
+ <GhostUpdateReview
+ diff={diff}
+ manualCount={next.manifest.manual?.items.length ?? 0}
+ />
+ ),
+ maxWidth: 520,
+ confirmText: t('settings.ghosts.updateConfirm.confirm'),
+ cancelText: t('settings.ghosts.updateConfirm.cancel'),
+ });
+ if (!approved || !isMarketBusyLeaseActive(marketBusyLease)) return;
const ghost = await installReviewedMarketPackage({
pluginId: next.pluginId,
options,
});
- if (!ghost) return;
- if (!isMarketBusyLeaseActive(marketBusyLease)) return;
+ if (!ghost || !isMarketBusyLeaseActive(marketBusyLease)) return;
toast.success(
t('settings.ghosts.toast.updated', {
name: ghost.manifest.name,
version: ghost.manifest.version,
}),
);
+ // 列表/详情共用此路径:成功后不切页面,方便连续点其它插件的更新。
await refreshMarket();
} catch (error) {
if (isMarketBusyLeaseActive(marketBusyLease)) {
@@ -1249,6 +1267,25 @@ export function GhostPluginPage({
const diff = isUpdate
? diffMarketUpdatePermissionItems(installedGhost!, marketDetail.manifest)
: null;
+ const options: PluginMarketInstallOptions = {
+ expectedReleaseId: marketDetail.releaseId,
+ expectedManifest: marketDetail.manifest,
+ ...(isUpdate && installedGhost
+ ? { expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval) }
+ : {}),
+ ...(isUpdate &&
+ (diff!.added.length > 0 ||
+ installedGhost?.approval.state !== 'approved')
+ ? {
+ allowPermissionExpansion: true,
+ ...(installedGhost
+ ? { reviewedBaseline: ghostPermissionBaselineKey(installedGhost.manifest) }
+ : {}),
+ }
+ : {}),
+ // 来源隔离(#2043):仅用户显式选择的冲突替换允许切换来源;更新与原位安装不切换。
+ allowSourceReplacement: marketDetail.installState === 'conflict',
+ };
const confirmed = await confirm({
title: isUpdate
? t('settings.ghosts.updateConfirm.title', { name: marketDetail.name })
@@ -1263,9 +1300,15 @@ export function GhostPluginPage({
: 'settings.ghosts.market.customInstallConfirmDescription',
),
content: isUpdate ? (
- <GhostUpdateReview diff={diff!} />
+ <GhostUpdateReview
+ diff={diff!}
+ manualCount={marketDetail.manifest.manual?.items.length ?? 0}
+ />
) : (
- <GhostPermissionList items={ghostPermissionItems(marketDetail.manifest)} />
+ <div>
+ <GhostManualSummary count={marketDetail.manifest.manual?.items.length ?? 0} />
+ <GhostPermissionList items={ghostPermissionItems(marketDetail.manifest)} />
+ </div>
),
maxWidth: 520,
confirmText: isUpdate
@@ -1277,31 +1320,13 @@ export function GhostPluginPage({
autoFocusConfirm: true,
});
if (!confirmed || !isMarketBusyLeaseActive(marketBusyLease)) return;
- const options: PluginMarketInstallOptions = {
- expectedReleaseId: marketDetail.releaseId,
- expectedManifest: marketDetail.manifest,
- ...(isUpdate && installedGhost
- ? { expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval) }
- : {}),
- ...(isUpdate && (diff!.added.length > 0 || installedGhost?.approval.state !== 'approved')
- ? {
- allowPermissionExpansion: true,
- ...(installedGhost
- ? { reviewedBaseline: ghostPermissionBaselineKey(installedGhost.manifest) }
- : {}),
- }
- : {}),
- // 来源隔离(#2043):仅用户显式选择的冲突替换允许切换来源;更新与原位安装不切换。
- allowSourceReplacement: marketDetail.installState === 'conflict',
- };
const ghost = await installReviewedMarketPackage({
pluginId: marketDetail.pluginId,
options,
});
- if (!ghost) return;
- if (!isMarketBusyLeaseActive(marketBusyLease)) return;
+ if (!ghost || !isMarketBusyLeaseActive(marketBusyLease)) return;
// 市场首装装完即开(2026-07-26 定案),toast 用"已安装";更新路径如实
- // 用"已更新"(生效状态未被改变)。
+ // 用"已更新"(生效状态未被改变),并留在当前页方便连续更新多个插件。
toast.success(
isUpdate
? t('settings.ghosts.toast.updated', {
@@ -1312,10 +1337,14 @@ export function GhostPluginPage({
name: ghost.manifest.name,
}),
);
- setMarketDetail((current) =>
- current?.pluginId === marketDetail.pluginId ? null : current,
- );
- setSelectedId(ghost.manifest.id);
+ if (shouldOpenInstalledDetailAfterMarketSuccess(isUpdate)) {
+ setMarketDetail((current) =>
+ current?.pluginId === marketDetail.pluginId ? null : current,
+ );
+ setSelectedId(ghost.manifest.id);
+ } else {
+ await refreshVisibleMarketDetail(marketDetail.pluginId).catch(() => undefined);
+ }
await refreshMarket();
} catch (error) {
if (isMarketBusyLeaseActive(marketBusyLease)) {
@@ -1331,6 +1360,7 @@ export function GhostPluginPage({
isMarketBusyLeaseActive,
installReviewedMarketPackage,
refreshMarket,
+ refreshVisibleMarketDetail,
releaseMarketBusy,
t,
],
@@ -1568,6 +1598,7 @@ export function GhostPluginPage({
updateBusy={
(item.marketUpdate !== null && marketBusyId !== null) || batchRunning
}
+ updatePending={item.marketUpdate?.pluginId === marketBusyId}
onUpdate={
item.marketUpdate ? () => void handleMarketUpdate(item.id) : undefined
}
@@ -1596,6 +1627,7 @@ export function GhostPluginPage({
updateBusy={
(item.marketUpdate !== null && marketBusyId !== null) || batchRunning
}
+ updatePending={item.marketUpdate?.pluginId === marketBusyId}
onUpdate={
item.marketUpdate ? () => void handleMarketUpdate(item.id) : undefined
}
@@ -1727,6 +1759,7 @@ export function GhostPluginPage({
key={item.pluginId}
item={item}
busy={marketBusyId !== null}
+ pending={marketBusyId === item.pluginId}
onSelect={() => void handleSelectMarket(item.pluginId)}
onInstall={
canOfferMarketInstall(mode, item.ghostId)
@@ -1747,6 +1780,7 @@ export function GhostPluginPage({
key={item.pluginId}
item={item}
busy={marketBusyId !== null}
+ pending={marketBusyId === item.pluginId}
onSelect={() => void handleSelectMarket(item.pluginId)}
onInstall={
canOfferMarketInstall(mode, item.ghostId)
@@ -1841,12 +1875,15 @@ export function LegacyGhostRecoveryNotice({
export function MarketPluginCard({
item,
busy,
+ pending = false,
onSelect,
onInstall,
onIconLoadError,
}: {
item: PluginMarketItem;
busy: boolean;
+ /** 本卡正在安装:主按钮换成 Spinner。 */
+ pending?: boolean;
onSelect: () => void;
/** 卡片直接安装;卡片正文、右侧空白与右上角箭头都进入详情。 */
onInstall?: () => void;
@@ -1949,6 +1986,7 @@ export function MarketPluginCard({
onInstall();
}}
disabled={unavailable}
+ aria-busy={pending || undefined}
aria-label={
item.installState === 'conflict'
? t('settings.ghosts.market.replaceAria', { name: item.name })
@@ -1956,15 +1994,19 @@ export function MarketPluginCard({
}
aria-describedby={replacementDescription ? replacementDescriptionId : undefined}
className={cn(
- 'relative z-[1] inline-flex h-8 shrink-0 items-center rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-3.5 text-12 font-medium text-[var(--text-primary)]',
+ 'relative z-[1] inline-flex h-8 min-w-[72px] shrink-0 items-center justify-center rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-3.5 text-12 font-medium text-[var(--text-primary)]',
'transition-[background-color,border-color,transform,opacity] duration-150 hover:bg-[var(--surface-hover-soft)] active:scale-[0.98]',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)] disabled:cursor-not-allowed disabled:opacity-40',
)}
>
- {t(
- item.installState === 'conflict'
- ? 'settings.ghosts.market.replace'
- : 'settings.ghosts.market.install',
+ {pending ? (
+ <Spinner size={14} />
+ ) : (
+ t(
+ item.installState === 'conflict'
+ ? 'settings.ghosts.market.replace'
+ : 'settings.ghosts.market.install',
+ )
)}
</button>
) : null}
@@ -2072,6 +2114,7 @@ export function GhostPluginCard({
sourceLabel,
updateVersion,
updateBusy = false,
+ updatePending = false,
onUpdate,
effectiveEnabled,
onPrimary,
@@ -2083,6 +2126,8 @@ export function GhostPluginCard({
/** 市场存在新版本时的目标版本;与 onUpdate 同时提供。 */
updateVersion?: string;
updateBusy?: boolean;
+ /** 本卡正在更新:更新胶囊换成 Spinner。 */
+ updatePending?: boolean;
onUpdate?: () => void;
effectiveEnabled?: boolean;
onPrimary: () => void;
@@ -2199,19 +2244,26 @@ export function GhostPluginCard({
type="button"
onClick={stopAnd(onUpdate)}
disabled={updateBusy}
+ aria-busy={updatePending || undefined}
aria-label={t('settings.ghosts.page.updateAria', {
name: item.name,
version: updateVersion,
})}
className={cn(
- 'inline-flex h-7 items-center gap-1 rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-2.5 text-11 font-medium text-[var(--text-primary)]',
+ 'inline-flex h-7 min-w-[72px] items-center justify-center gap-1 rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-2.5 text-11 font-medium text-[var(--text-primary)]',
'transition-colors duration-150 hover:bg-[var(--surface-hover-soft)]',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',
'disabled:cursor-wait disabled:opacity-40',
)}
>
- <ArrowUp size={11} className="text-[var(--text-secondary)]" aria-hidden="true" />
- {t('settings.ghosts.page.updateTo', { version: updateVersion })}
+ {updatePending ? (
+ <Spinner size={12} />
+ ) : (
+ <>
+ <ArrowUp size={11} className="text-[var(--text-secondary)]" aria-hidden="true" />
+ {t('settings.ghosts.page.updateTo', { version: updateVersion })}
+ </>
+ )}
</button>
) : null}
<button
diff --git a/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx
index bda85cae91..9d2b2e3b20 100644
--- a/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx
+++ b/apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx
@@ -2,6 +2,7 @@ import { useId } from 'react';
import { Download, ShieldCheck } from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import { Spinner } from '@/components/ui/spinner';
import { cn } from '@/lib/utils';
import { ghostPermissionItems } from '../../../shared/ghost';
import type { PluginMarketDetail } from '../../../shared/pluginMarket';
@@ -89,7 +90,11 @@ export function MarketPluginDetailView({
type="button"
onClick={onInstall}
disabled={actionDisabled}
- aria-describedby={replacementDescription ? replacementDescriptionId : undefined}
+ aria-label={t(actionKey)}
+ aria-busy={busy || undefined}
+ aria-describedby={
+ replacementDescription ? replacementDescriptionId : undefined
+ }
className={cn(
'plugin-detail-primary-action inline-flex h-10 min-w-[104px] items-center justify-center gap-2 whitespace-nowrap rounded-full px-4 text-13 font-medium',
'bg-[var(--accent-cta-bg)] text-[var(--accent-pure-cta-fg)]',
@@ -98,8 +103,14 @@ export function MarketPluginDetailView({
'disabled:cursor-not-allowed disabled:opacity-40 disabled:active:scale-100',
)}
>
- <Download size={15} aria-hidden="true" />
- {t(actionKey)}
+ {busy ? (
+ <Spinner size={14} />
+ ) : (
+ <>
+ <Download size={15} aria-hidden="true" />
+ {t(actionKey)}
+ </>
+ )}
</button>
) : null}
</div>
diff --git a/apps/desktop/src/renderer/features/plugin/PluginMarketPermissionReviewHost.tsx b/apps/desktop/src/renderer/features/plugin/PluginMarketPermissionReviewHost.tsx
index 58277f4e24..acc3522e57 100644
--- a/apps/desktop/src/renderer/features/plugin/PluginMarketPermissionReviewHost.tsx
+++ b/apps/desktop/src/renderer/features/plugin/PluginMarketPermissionReviewHost.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
import {
GhostManualSummary,
+ GhostOauthClientChangedAlert,
GhostPermissionList,
GhostUpdateReview,
} from '@/cindy-brain/GhostPermissionList';
@@ -60,11 +61,19 @@ export function PluginMarketPermissionReviewHost() {
),
content: review.permissionDiff ? (
<GhostUpdateReview
- diff={review.permissionDiff}
+ diff={{
+ ...review.permissionDiff,
+ builtinOauthClientChanged:
+ review.permissionDiff.builtinOauthClientChanged ||
+ review.builtinOauthClientChanged === true,
+ }}
manualCount={review.manifest.manual?.items.length ?? 0}
/>
) : (
<div>
+ {review.builtinOauthClientChanged === true ? (
+ <GhostOauthClientChangedAlert />
+ ) : null}
<GhostManualSummary count={review.manifest.manual?.items.length ?? 0} />
<GhostPermissionList items={ghostPermissionItems(review.manifest)} />
</div>
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 50b5ceb5c7..9500c35a32 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginCard.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginCard.test.tsx
@@ -1,7 +1,8 @@
/**
* Regression coverage for installed Plugin card actions (redesigned card:
* whole-card opens detail, kind-specific primary button, manage entry),
- * market card actions, and the legacy recovery notice.
+ * market card actions, the legacy recovery notice, and market success navigation
+ * (first install opens detail; update stays put).
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
* @vitest-environment jsdom
*/
@@ -33,6 +34,7 @@ import {
LegacyGhostRecoveryNotice,
marketUpdateAllowsPermissionExpansion,
MarketPluginCard,
+ shouldOpenInstalledDetailAfterMarketSuccess,
} from '../GhostPluginPage';
import {
__ingestGhostBadgeForTest,
@@ -102,6 +104,16 @@ describe('marketUpdateAllowsPermissionExpansion', () => {
});
});
+describe('shouldOpenInstalledDetailAfterMarketSuccess', () => {
+ it('opens the installed detail after a first-time market install', () => {
+ expect(shouldOpenInstalledDetailAfterMarketSuccess(false)).toBe(true);
+ });
+
+ it('stays on the current page after an update or replacement', () => {
+ expect(shouldOpenInstalledDetailAfterMarketSuccess(true)).toBe(false);
+ });
+});
+
const commandPlugin: GhostPluginListItem = {
id: 'filo-google',
name: 'Filo Google',
@@ -306,6 +318,27 @@ describe('GhostPluginCard', () => {
).toBe(true);
});
+ it('replaces the update pill with a spinner while this card is pending', () => {
+ render(
+ <GhostPluginCard
+ item={commandPlugin}
+ updateVersion="1.1.0"
+ updateBusy
+ updatePending
+ onPrimary={vi.fn()}
+ onManage={vi.fn()}
+ onUpdate={vi.fn()}
+ />,
+ );
+
+ const update = screen.getByRole('button', {
+ name: 'settings.ghosts.page.updateAria',
+ });
+ expect(update.getAttribute('aria-busy')).toBe('true');
+ expect(update.querySelector('.animate-spin')).toBeTruthy();
+ expect(update.textContent).toBe('');
+ });
+
it('sends a tool-only plugin to manage and renders no primary button', () => {
const onPrimary = vi.fn();
const onManage = vi.fn();
@@ -604,6 +637,26 @@ describe('MarketPluginCard', () => {
expect(busyCardBody.className).toContain('cursor-wait');
expect(busyCardBody.className).not.toContain('cursor-not-allowed');
});
+
+ it('replaces the install label with a spinner while this card is pending', () => {
+ render(
+ <MarketPluginCard
+ item={marketPlugin}
+ busy
+ pending
+ onSelect={vi.fn()}
+ onInstall={vi.fn()}
+ onIconLoadError={vi.fn()}
+ />,
+ );
+
+ const install = screen.getByRole('button', {
+ name: 'settings.ghosts.page.installAria',
+ });
+ expect(install.getAttribute('aria-busy')).toBe('true');
+ expect(install.querySelector('.animate-spin')).toBeTruthy();
+ expect(install.textContent).toBe('');
+ });
});
describe('installed Plugin disclosure', () => {
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/MarketPluginDetailView.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/MarketPluginDetailView.test.tsx
index cf26991cef..591ae914d8 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/MarketPluginDetailView.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/MarketPluginDetailView.test.tsx
@@ -105,4 +105,23 @@ describe('MarketPluginDetailView', () => {
);
expect(screen.queryByRole('button', { name: /settings\.ghosts\.market\.install/ })).toBeNull();
});
+
+ it('replaces the install action with a spinner while busy', () => {
+ render(
+ <MarketPluginDetailView
+ detail={detail}
+ busy
+ onBack={vi.fn()}
+ onInstall={vi.fn()}
+ onIconLoadError={vi.fn()}
+ />,
+ );
+
+ const action = screen.getByRole('button', {
+ name: /settings\.ghosts\.market\.install/,
+ });
+ expect(action.getAttribute('aria-busy')).toBe('true');
+ expect(action.querySelector('.animate-spin')).toBeTruthy();
+ expect(action.textContent).toBe('');
+ });
});
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/PluginMarketPermissionReviewHost.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/PluginMarketPermissionReviewHost.test.tsx
index cc8706c740..71eb5c3483 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/PluginMarketPermissionReviewHost.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/PluginMarketPermissionReviewHost.test.tsx
@@ -69,6 +69,7 @@ describe('PluginMarketPermissionReviewHost', () => {
reviewListener?.({
requestId: 'review-a',
ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 1 },
+ builtinOauthClientChanged: false,
manifest: {
schemaVersion: 2,
id: 'private-plugin',
@@ -119,6 +120,7 @@ describe('PluginMarketPermissionReviewHost', () => {
reviewListener?.({
requestId: 'stale-review',
ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 1 },
+ builtinOauthClientChanged: false,
manifest: {
schemaVersion: 2,
id: 'private-plugin',
@@ -169,10 +171,44 @@ describe('PluginMarketPermissionReviewHost', () => {
permissionDiff: { added: [], removed: [], unchanged: [], builtinOauthClientChanged: false },
isUpdate: true,
sourceType: 'server',
+ builtinOauthClientChanged: false,
});
});
expect(await screen.findByText('settings.ghosts.installConfirm.manualCount:2')).toBeTruthy();
expect(screen.getByText('settings.ghosts.updateConfirm.title')).toBeTruthy();
});
+
+ it('shows the OAuth identity warning on a first-install full permission card', async () => {
+ render(
+ <ConfirmDialogProvider>
+ <PluginMarketPermissionReviewHost />
+ </ConfirmDialogProvider>,
+ );
+
+ act(() => {
+ reviewListener?.({
+ requestId: 'first-install-oauth',
+ ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 1 },
+ builtinOauthClientChanged: true,
+ manifest: {
+ schemaVersion: 2,
+ id: 'oauth-plugin',
+ name: 'OAuth Plugin',
+ version: '1.0.0',
+ kind: 'chip',
+ entry: 'main.js',
+ slots: ['network'],
+ },
+ permissionDiff: null,
+ isUpdate: false,
+ sourceType: 'server',
+ });
+ });
+
+ expect(
+ await screen.findByText('settings.ghosts.updateConfirm.oauthClientChanged'),
+ ).toBeTruthy();
+ expect(screen.getByText('settings.ghosts.market.installConfirmTitle')).toBeTruthy();
+ });
});
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/marketInstallConfirmation.test.ts b/apps/desktop/src/renderer/features/plugin/__tests__/marketInstallConfirmation.test.ts
new file mode 100644
index 0000000000..e8ccce858c
--- /dev/null
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/marketInstallConfirmation.test.ts
@@ -0,0 +1,34 @@
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+
+import { describe, expect, it } from 'vitest';
+
+/**
+ * Clicking install/update must open the catalog permission card immediately.
+ * The post-download Host card is only for permissions the preview missed.
+ */
+describe('market install confirmation', () => {
+ const pageSource = readFileSync(
+ resolve(__dirname, '../GhostPluginPage.tsx'),
+ 'utf8',
+ ).replace(/\r\n/g, '\n');
+
+ it('shows an immediate catalog permission card before download', () => {
+ expect(pageSource).toContain('<GhostUpdateReview');
+ expect(pageSource).toContain('manualCount={next.manifest.manual?.items.length ?? 0}');
+ expect(pageSource).toContain(
+ 'manualCount={marketDetail.manifest.manual?.items.length ?? 0}',
+ );
+ expect(pageSource).toContain('<GhostManualSummary');
+ expect(pageSource).toContain('<GhostPermissionList');
+ expect(pageSource).toContain(
+ '下载真实包;权限卡已在页面确认,Host 只在真实包超出已审清单时再弹',
+ );
+ });
+
+ it('refreshes the current market detail after an update instead of closing it', () => {
+ expect(pageSource).toContain(
+ 'await refreshVisibleMarketDetail(marketDetail.pluginId).catch(() => undefined);',
+ );
+ });
+});
diff --git a/apps/desktop/src/shared/pluginMarket.ts b/apps/desktop/src/shared/pluginMarket.ts
index e7711c22db..459d9cc2ba 100644
--- a/apps/desktop/src/shared/pluginMarket.ts
+++ b/apps/desktop/src/shared/pluginMarket.ts
@@ -123,6 +123,8 @@ export interface PluginMarketPackageReviewFacts {
installedBaseline: string | null;
/** 只用于让确认卡如实说明包来自官方还是用户添加的市场。 */
sourceType: PluginMarketItemSource;
+ /** 与 permissionDiff 独立:完整权限卡也要能展示 OAuth 身份变化。 */
+ builtinOauthClientChanged?: boolean;
}
/** Main 在安装事务内请求当前窗口立即确认真实包权限;不暴露内部批准绑定。 */
@@ -134,6 +136,8 @@ export interface PluginMarketPackageReviewRequest {
permissionDiff: GhostPermissionDiff | null;
isUpdate: boolean;
sourceType: PluginMarketItemSource;
+ /** 与 permissionDiff 独立:完整权限卡也要能展示 OAuth 身份变化。 */
+ builtinOauthClientChanged?: boolean;
}
export interface PluginMarketInstallOptions {