Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
merge: integrate latest main plugin changes
Yuewei-LLe590d7cd533d
diff --cc apps/desktop/src/main/__tests__/codexProjectlessMigration.test.tsindex 348f8b3dd2,348f8b3dd2..fa6ece4027--- a/apps/desktop/src/main/__tests__/codexProjectlessMigration.test.ts+++ b/apps/desktop/src/main/__tests__/codexProjectlessMigration.test.ts@@@ -3,10 -3,10 +3,10 @@@ import os from 'node:os'import path from 'node:path';import { afterEach, beforeEach, describe, expect, it } from 'vitest';--// Migration runner loads drizzle scripts through CommonJS require.--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration = require('../../../drizzle/scripts/0025_reclassify_codex_projectless_dialogues.ts') as {-- run: (db: unknown, options?: { codexHomes?: string[] }) => void;++// Production keeps migration helpers CommonJS; Vitest loads the TS helper through++// its transformer and consumes the CommonJS default export.++const { default: migration } = (await import('../../../drizzle/scripts/0025_reclassify_codex_projectless_dialogues')) as {++ default: { run: (db: unknown, options?: { codexHomes?: string[] }) => void };};let codexHome: string;diff --cc apps/desktop/src/main/__tests__/sessionWorkspaceKindMigration.test.tsindex cd4fa04187,cd4fa04187..f4a90ec0d0--- a/apps/desktop/src/main/__tests__/sessionWorkspaceKindMigration.test.ts+++ b/apps/desktop/src/main/__tests__/sessionWorkspaceKindMigration.test.ts@@@ -1,10 -1,10 +1,10 @@@import Database from 'better-sqlite3';import { describe, expect, it } from 'vitest';--// Migration runner loads drizzle scripts through CommonJS require.--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration = require('../../../drizzle/scripts/0024_ensure_session_workspace_kind.ts') as {-- run: (db: Database.Database) => void;++// Production keeps migration helpers CommonJS; Vitest loads the TS helper through++// its transformer and consumes the CommonJS default export.++const { default: migration } = (await import('../../../drizzle/scripts/0024_ensure_session_workspace_kind')) as {++ default: { run: (db: Database.Database) => void };};function columnNames(db: Database.Database): string[] {diff --cc apps/desktop/src/main/__tests__/slimMessagesFtsMigration.test.tsindex 781828dff5,781828dff5..77d2151658--- a/apps/desktop/src/main/__tests__/slimMessagesFtsMigration.test.ts+++ b/apps/desktop/src/main/__tests__/slimMessagesFtsMigration.test.ts@@@ -1,10 -1,10 +1,10 @@@import Database from 'better-sqlite3';import { describe, expect, it } from 'vitest';--// Migration runner loads drizzle scripts through CommonJS require.--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration = require('../../../drizzle/scripts/0066_slim_messages_fts.ts') as {-- run: (db: Database.Database) => void;++// Production keeps migration helpers CommonJS; Vitest loads the TS helper through++// its transformer and consumes the CommonJS default export.++const { default: migration } = (await import('../../../drizzle/scripts/0066_slim_messages_fts')) as {++ default: { run: (db: Database.Database) => void };};/** 0017 形态的最小 messages 表 + 旧版全量 FTS(insert 触发器无 role 过滤)。 */diff --cc apps/desktop/src/main/cindy-media/__tests__/attachmentGrantGate.test.tsindex 96fb405f06,96fb405f06..225614f965--- a/apps/desktop/src/main/cindy-media/__tests__/attachmentGrantGate.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/attachmentGrantGate.test.ts@@@ -23,9 -23,9 +23,8 @@@ const ledger = await import('../ledger'const { chatAttachmentOrigin } = await import('../attachmentGrantGate');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};const HASH = 'a'.repeat(64);diff --cc apps/desktop/src/main/cindy-media/__tests__/chatAttachments.test.tsindex 3090c1e671,3090c1e671..d95941e5e2--- a/apps/desktop/src/main/cindy-media/__tests__/chatAttachments.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/chatAttachments.test.ts@@@ -25,9 -25,9 +25,8 @@@ const schema = await import('../../locaconst chatAttachments = await import('../chatAttachments');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};const PNG_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 42]);diff --cc apps/desktop/src/main/cindy-media/__tests__/generatedMedia.test.tsindex 90bbeea768,90bbeea768..c31eff5a8a--- a/apps/desktop/src/main/cindy-media/__tests__/generatedMedia.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/generatedMedia.test.ts@@@ -25,9 -25,9 +25,8 @@@ const schema = await import('../../locaconst generatedMedia = await import('../generatedMedia');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};const PNG_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 9]);diff --cc apps/desktop/src/main/cindy-media/__tests__/ingest.test.tsindex ea2e8648de,ea2e8648de..03d1da9af6--- a/apps/desktop/src/main/cindy-media/__tests__/ingest.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/ingest.test.ts@@@ -25,9 -25,9 +25,8 @@@ const schema = await import('../../locaconst ingest = await import('../ingest');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};const PNG_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 7, 7]);diff --cc apps/desktop/src/main/cindy-media/__tests__/integrationCache.test.tsindex 995f71f93a,995f71f93a..a4e40e321a--- a/apps/desktop/src/main/cindy-media/__tests__/integrationCache.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/integrationCache.test.ts@@@ -24,9 -24,9 +24,8 @@@ const schema = await import('../../locaconst integrationCache = await import('../integrationCache');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};const BYTES_A = Buffer.from('feishu-image-bytes-a');diff --cc apps/desktop/src/main/cindy-media/__tests__/ledger.test.tsindex 0804850d66,0804850d66..4bad9aa094--- a/apps/desktop/src/main/cindy-media/__tests__/ledger.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/ledger.test.ts@@@ -21,10 -21,10 +21,9 @@@ const schema = await import('../../locaconst ledger = await import('../ledger');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// 0071 的加列在配套脚本里(SQL 是占位),与生产同源经 CommonJS require 加载。--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++// 0071 的加列在配套脚本里(SQL 是占位),与生产同源;通过 Vitest 转换 TS helper。++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};const HASH_A = 'a'.repeat(64);diff --cc apps/desktop/src/main/cindy-media/__tests__/recycler.test.tsindex e3a830edd8,e3a830edd8..085a8e18a0--- a/apps/desktop/src/main/cindy-media/__tests__/recycler.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/recycler.test.ts@@@ -28,9 -28,9 +28,8 @@@ const blobStore = await import('../blobconst recycler = await import('../recycler');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};function freshDb(): LedgerDb {diff --cc apps/desktop/src/main/cindy-media/__tests__/storageIpc.test.tsindex a94926afb0,a94926afb0..3d27b53dbc--- a/apps/desktop/src/main/cindy-media/__tests__/storageIpc.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/storageIpc.test.ts@@@ -25,9 -25,9 +25,8 @@@ const blobStore = await import('../blobconst { createStorageIpcHandlers } = await import('../storageIpc');const MIGRATION_0070 = path.resolve(__dirname, '../../../../drizzle/0070_woozy_harpoon.sql');--// eslint-disable-next-line @typescript-eslint/no-require-imports--const migration0071 = require('../../../../drizzle/scripts/0071_bright_ultron.ts') as {-- run: (db: Database.Database) => void;++const { default: migration0071 } = (await import('../../../../drizzle/scripts/0071_bright_ultron')) as {++ default: { run: (db: Database.Database) => void };};function freshDb(): LedgerDb {diff --cc apps/desktop/src/main/localDb/__tests__/legacyMigrationLineageBridge.test.tsindex 3ce6404f33,3ce6404f33..3fd6b3e7c5--- a/apps/desktop/src/main/localDb/__tests__/legacyMigrationLineageBridge.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/legacyMigrationLineageBridge.test.ts@@@ -1,10 -1,10 +1,9 @@@import Database from 'better-sqlite3';import { describe, expect, it } from 'vitest';--const migration0074 =-- require('../../../../drizzle/scripts/0074_bridge_legacy_migration_lineage.ts') as {-- run(db: Database.Database): void;-- };++const { default: migration0074 } = (await import(++ '../../../../drizzle/scripts/0074_bridge_legacy_migration_lineage'++)) as { default: { run(db: Database.Database): void } };const LEGACY_LINEAGE = [[diff --cc apps/desktop/src/main/localDb/__tests__/legacySessionFallbackMigration.test.tsindex 6189eadce4,6189eadce4..badc0e9bff--- a/apps/desktop/src/main/localDb/__tests__/legacySessionFallbackMigration.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/legacySessionFallbackMigration.test.ts@@@ -2,11 -2,11 +2,9 @@@ import Database from 'better-sqlite3'import { describe, expect, it } from 'vitest';// Migration companion scripts intentionally use CommonJS so the runtime loader can replay them.--const migration0079 =-- // eslint-disable-next-line @typescript-eslint/no-require-imports-- require('../../../../drizzle/scripts/0079_futuristic_hercules.ts') as {-- run(db: Database.Database): void;-- };++const { default: migration0079 } = (await import(++ '../../../../drizzle/scripts/0079_futuristic_hercules'++)) as { default: { run(db: Database.Database): void } };describe('0079 legacy scheduler session fallback boundary', () => {it('marks existing schedules compatible while new schedules keep the isolated default', () => {diff --cc apps/desktop/src/main/localDb/__tests__/preserveGatewayCurrencyMigration.test.tsindex 85c86b8079,85c86b8079..341d4ff26d--- a/apps/desktop/src/main/localDb/__tests__/preserveGatewayCurrencyMigration.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/preserveGatewayCurrencyMigration.test.ts@@@ -2,11 -2,11 +2,9 @@@ import Database from 'better-sqlite3'import { describe, expect, it } from 'vitest';// Migration companion scripts intentionally use CommonJS so the runtime loader can replay them.--const migration0081 =-- // eslint-disable-next-line @typescript-eslint/no-require-imports-- require('../../../../drizzle/scripts/0081_preserve_gateway_currency.ts') as {-- run(db: Database.Database): void;-- };++const { default: migration0081 } = (await import(++ '../../../../drizzle/scripts/0081_preserve_gateway_currency'++)) as { default: { run(db: Database.Database): void } };const RATE = 6.7;diff --cc apps/desktop/src/main/localDb/__tests__/rebuildDailySpendMigration.test.tsindex 3d3902ebf8,3d3902ebf8..9bcf1d897c--- a/apps/desktop/src/main/localDb/__tests__/rebuildDailySpendMigration.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/rebuildDailySpendMigration.test.ts@@@ -2,11 -2,11 +2,9 @@@ import Database from 'better-sqlite3'import { describe, expect, it } from 'vitest';// Migration companion scripts intentionally use CommonJS so the runtime loader can replay them.--const migration0085 =-- // eslint-disable-next-line @typescript-eslint/no-require-imports-- require('../../../../drizzle/scripts/0085_skinny_iron_man.ts') as {-- run(db: Database.Database): void;-- };++const { default: migration0085 } = (await import(++ '../../../../drizzle/scripts/0085_skinny_iron_man'++)) as { default: { run(db: Database.Database): void } };function setupDb(): Database.Database {const db = new Database(':memory:');diff --cc apps/desktop/src/main/plugin-market/__tests__/service.test.tsindex 7364e6b761,1aa3191e28..d499ca05a3--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts@@@ -1307,30 -1519,9 +1607,31 @@@ function recordForTestsha256: item.currentRelease.sha256,scope: item.scope,organizationId: item.organizationId,- source: 'market' as const,+ source: 'market',installed: true,updatedAt: '2026-07-23T00:00:00.000Z',+ ...overrides,};}++describe('market detail 响应身份绑定', () => {+ it('detail 自报的 id/ghostId 与请求不一致 → 拒,不把 A 的确认导向 B 的内容', async () => {+ const item = summary();+ const h = harness([item]);+ // 服务端异常/恶意响应:返回另一个插件的 detail(id 与 ghostId 都换了)。+ h.api.detail.mockImplementation(async () =>+ detail({ ...item, id: 'plg_other', ghostId: 'cindy-other' }),+ );+ await expect(+ h.service.install(item.id, { expectedReleaseId: item.currentRelease.id }),+ ).rejects.toThrow('[GHOST_FILE_INVALID]');+ // 只换 ghostId、id 相同也要拒:可见性与 ghostId 冲突判定都基于目录 summary。+ h.api.detail.mockImplementation(async () => detail({ ...item, ghostId: 'cindy-other' }));+ await expect(+ h.service.install(item.id, { expectedReleaseId: item.currentRelease.id }),+ ).rejects.toThrow('[GHOST_FILE_INVALID]');+ await expect(h.service.detail(item.id)).resolves.toBeTruthy(); // detail() 只绑 id+ h.api.detail.mockImplementation(async () => detail({ ...item, id: 'plg_other' }));+ await expect(h.service.detail(item.id)).rejects.toThrow('[GHOST_FILE_INVALID]');+ });+});diff --cc apps/desktop/src/main/plugin-market/registerIpc.tsindex 95dbb4ead1,8462cad98f..9500183ebf--- a/apps/desktop/src/main/plugin-market/registerIpc.ts+++ b/apps/desktop/src/main/plugin-market/registerIpc.ts@@@ -3,8 -3,11 +3,11 @@@ import os from 'node:os'import { ipcMain } from 'electron';import { isIpcError } from '../../shared/ipc-errors.js';-import type { GhostManifest } from '../../shared/ghost.js';+import { isGhostInstallApprovalToken, type GhostManifest } from '../../shared/ghost.js';- import { setGhostUninstallLedgerPreparer } from '../cindy-brain/index.js';+ import {+ sendToTrustedAppWindows,+ setGhostUninstallLedgerPreparer,+ } from '../cindy-brain/index.js';import { createLogger } from '../logger.js';import { assertTrustedAppRendererEvent } from '../security/trustedAppRenderer.js';import { requireObject, requireString, throwIpcError } from '../utils/ipcValidate.js';diff --cc apps/desktop/src/main/plugin-market/service.tsindex d3a0cd82fc,8411396351..46234b53c8--- a/apps/desktop/src/main/plugin-market/service.ts+++ b/apps/desktop/src/main/plugin-market/service.ts@@@ -385,23 -399,23 +400,40 @@@ export class PluginMarketService};}+ /**+ * detail 响应必须与请求身份一致:后续下载、安装、ledger 全都信 detail 的自报+ * 字段,不绑定的话异常/恶意服务端响应可以把 A 的确认导向 B 的内容,并绕过+ * 调用方基于目录 summary 做过的可见性与 ghostId 冲突判断。+ */+ private requireDetailIdentity(+ detail: { id: string; ghostId: string },+ expected: { pluginId: string; ghostId?: string },+ ): void {+ if (+ detail.id !== expected.pluginId ||+ (expected.ghostId !== undefined && detail.ghostId !== expected.ghostId)+ ) {+ throwIpcError('GHOST_FILE_INVALID', 'Market detail response does not match the requested Plugin');+ }+ }++ /** 按当前 owner 消费一次清理汇总,避免组织插件名跨账号泄露。 */+ consumeRemovalNotice(): PluginRemovalUserNotice | null {+ const key = removalNoticeKey(captureMarketOwner());+ const notice = this.pendingRemovalNotices.get(key) ?? null;+ if (notice) this.pendingRemovalNotices.delete(key);+ return notice;+ }++ hasPendingRemovalNotice(): boolean {+ if (this.pendingRemovalNotices.size === 0) return false;+ try {+ return this.pendingRemovalNotices.has(removalNoticeKey(captureMarketOwner()));+ } catch {+ return false;+ }+ }+async detail(pluginId: string): Promise<PluginMarketDetail> {// 自定义市场插件走本地发现,不要求服务端可用,也不受 CUID 形状约束。const customRef = parseCustomMarketPluginId(pluginId);diff --cc apps/desktop/src/main/scheduler-host/__tests__/scriptCapabilityBroker.test.tsindex 7eed4512f2,ffa0abd54a..e924b61083--- a/apps/desktop/src/main/scheduler-host/__tests__/scriptCapabilityBroker.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/scriptCapabilityBroker.test.ts@@@ -320,3 -795,50 +795,51 @@@ describe('SchedulerScriptCapabilityBrok// Compile-time fixture: legacy schedules may omit executionMode.const _legacySchedule: Partial<Schedule> = { prompt: 'legacy' };void _legacySchedule;++ /** 端到端用例的已装意识(fixture):声明 fs 槽(fs 槽资格审)+ jira_issues 工具+ * (pipeDispatcher 资格审)。 */+ function makeInstalledGhost(id: string): InstalledGhost {+ return {+ manifest: {+ schemaVersion: 2,+ id,+ name: id,+ version: '1.0.0',+ kind: 'chip',+ entry: 'main.js',+ slots: ['fs'],+ tools: [{ name: 'jira_issues', description: 'jira' }],+ } as InstalledGhost['manifest'],+ dir: '/tmp/fake-install-dir',+ enabled: true,++ approval: { state: 'approved', revision: '00000000-0000-4000-8000-000000000001' },+ };+ }++ /**+ * 端到端 harness:真实 GhostCardService + 真实 GhostFsSlot,把 broker 的+ * mock 边界(register/finalize)接到真实账本——用例只需替换意识行为+ * (callGhostToolMock 的实现),其余链路全真。+ */+ function wireRealChannel(tmp: string): { cardService: GhostCardService; fsSlot: GhostFsSlot } {+ const cardService = new GhostCardService({+ hasCardSlot: () => false,+ sanitize: (html: string) => ({ ok: true, html }),+ persist: async () => {},+ broadcast: () => {},+ });+ const fsSlot = new GhostFsSlot({+ getGhost: (id) => (id === 'xd-atlassian' ? makeInstalledGhost(id) : null),+ dataRootDir: () => path.join(tmp, 'ghost-fs'),+ callInfo: (callId) => cardService.callInfoOf(callId),+ inFlightCallInfo: (callId) => cardService.inFlightCallInfoOf(callId),+ getSessionSnapshot: async () => null,+ requestWriteConfirm: async () => ({ confirmed: false, reason: 'cancelled' as const }),+ writeSaveDeposit: async () => null,+ });+ registerCallMock.mockImplementation((callId: string, info: never) =>+ cardService.registerCall(callId, info),+ );+ finalizeCallMock.mockImplementation((callId: string) => cardService.finalizeCall(callId));+ return { cardService, fsSlot };+ }diff --cc apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsxindex 4281a921e3,62338ca7a7..d200b4fac7--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx@@@ -66,8 -67,7 +71,9 @@@ import { getLastWorkingDir, subscribeToimport { findSplitChildByPanelKind } from '../../../shared/layoutTree';import { resolveSystemLocale } from '../../../shared/locale';import {+ diffGhostPermissionItems,+ diffInstalledGhostPermissionItems,+ ghostInstallApprovalToken,ghostPanelKind,ghostPermissionBaselineKey,ghostPermissionItems,@@@ -1088,142 -1154,138 +1201,143 @@@ export function GhostPluginPage()refreshVisibleMarketIcons,);- const runMarketInstallFlow = useCallback(async (marketDetailArg: PluginMarketDetail) => {- const marketDetail = marketDetailArg;- // 确认框等待期间也持有 lease。账号/模式切换会清除当前 lease,- // 旧确认回调恢复后必须先验权,不能在新会话里继续安装。- const marketBusyLease = acquireMarketBusy(marketDetail.pluginId);- if (!marketBusyLease) return;- // 详情页按钮在 update-available 态复用本入口,后端走原位更新并保留- // 生效状态 —— 文案必须分支,不能对更新路径承诺"装完即开"(review P1)。- const isUpdate = marketDetail.installState === 'update-available';- // 装完即开意味着"确认安装"就是运行授权,确认框里必须如实展示权限清单- // (与本地装入确认框同一信息量,review P1):首装展示完整清单,更新展示- // 与已装版本的权限 diff,并据此决定 allowPermissionExpansion(否则扩权- // 更新从本入口必被 main 的 PRECONDITION_FAILED 拦下)。更新详情来自 Main- // 的现查事实,renderer 的 ghosts 推送缓存可能短暂滞后;仅在 update 态且缓存- // 缺目标时,用既有 listSync 向 Main 现查一次。仍缺失说明状态已经变化,- // 让后端按原有校验拒绝,绝不能拿新清单和自己做 diff 吞掉新增权限。- let installedGhost =- ghosts.find((ghost) => ghost.manifest.id === marketDetail.ghostId) ?? null;- if (isUpdate && !installedGhost) {- try {- installedGhost =- window.electronAPI.ghosts- .listSync()- .ghosts.find((ghost) => ghost.manifest.id === marketDetail.ghostId) ?? null;- } catch {- // bridge 不可用/状态切换时保持 null;下面不展示伪造的空 diff,- // 安装调用也不放开 permission expansion,Main 会按真实状态 fail closed。+ const runMarketInstallFlow = useCallback(+ async (marketDetailArg: PluginMarketDetail) => {+ const marketDetail = marketDetailArg;+ // 确认框等待期间也持有 lease。账号/模式切换会清除当前 lease,+ // 旧确认回调恢复后必须先验权,不能在新会话里继续安装。+ const marketBusyLease = acquireMarketBusy(marketDetail.pluginId);+ if (!marketBusyLease) return;+ // 详情页按钮在 update-available 态复用本入口,后端走原位更新并保留+ // 生效状态 —— 文案必须分支,不能对更新路径承诺"装完即开"(review P1)。+ const isUpdate = marketDetail.installState === 'update-available';+ // 装完即开意味着"确认安装"就是运行授权,确认框里必须如实展示权限清单+ // (与本地装入确认框同一信息量,review P1):首装展示完整清单,更新展示+ // 与已装版本的权限 diff,并据此决定 allowPermissionExpansion(否则扩权+ // 更新从本入口必被 main 的 PRECONDITION_FAILED 拦下)。更新详情来自 Main+ // 的现查事实,renderer 的 ghosts 推送缓存可能短暂滞后;仅在 update 态且缓存+ // 缺目标时,用既有 listSync 向 Main 现查一次。仍缺失说明状态已经变化,+ // 让后端按原有校验拒绝,绝不能拿新清单和自己做 diff 吞掉新增权限。+ let installedGhost =+ ghosts.find((ghost) => ghost.manifest.id === marketDetail.ghostId) ?? null;+ if (isUpdate && !installedGhost) {+ try {+ installedGhost =+ window.electronAPI.ghosts+ .listSync()+ .ghosts.find((ghost) => ghost.manifest.id === marketDetail.ghostId) ?? null;+ } catch {+ // bridge 不可用/状态切换时保持 null;下面不展示伪造的空 diff,+ // 安装调用也不放开 permission expansion,Main 会按真实状态 fail closed。+ }}- }- if (isUpdate && !installedGhost) {- // detail 仍说可更新、Main 的实时已装清单却没有目标:这是明确的状态- // 变化,不要展示伪造的空 diff 后让用户确认一次必失败的更新。- if (isMarketBusyLeaseActive(marketBusyLease)) {- toast.error(t('settings.ghosts.market.errors.stateChanged'));+ if (isUpdate && !installedGhost) {+ // detail 仍说可更新、Main 的实时已装清单却没有目标:这是明确的状态+ // 变化,不要展示伪造的空 diff 后让用户确认一次必失败的更新。+ if (isMarketBusyLeaseActive(marketBusyLease)) {+ toast.error(t('settings.ghosts.market.errors.stateChanged'));+ }+ releaseMarketBusy(marketBusyLease);+ await refreshMarket();+ return;}- releaseMarketBusy(marketBusyLease);- await refreshMarket();- return;- }- const diff = isUpdate- ? diffInstalledGhostPermissionItems(installedGhost!, marketDetail.manifest)- : null;- try {- const confirmed = await confirm({- title: isUpdate- ? t('settings.ghosts.updateConfirm.title', { name: marketDetail.name })- : t('settings.ghosts.market.installConfirmTitle', {- name: marketDetail.name,- }),- description: isUpdate- ? t('settings.ghosts.market.updateConfirmDescription')- : // 自定义市场未经服务端完整性校验,确认文案必须如实区分。- marketDetail.sourceType !== 'server'- ? t('settings.ghosts.market.customInstallConfirmDescription')- : t('settings.ghosts.market.installConfirmDescription'),- // 限高与滚动交给共享 ConfirmDialog(max-h-[85vh] + 内部滚动区 + 打开时- // 闪一下滚动条),这里不再自套一层 min(56vh,520px) —— 两层限高会让- // "到底了没有"取决于内外层谁先触底(2026-07-27 收口)。- content: isUpdate ? (- <GhostUpdateReview diff={diff!} />- ) : (- <GhostPermissionList items={ghostPermissionItems(marketDetail.manifest)} />- ),- maxWidth: 520,- confirmText: isUpdate- ? t('settings.ghosts.updateConfirm.confirm')- : t('settings.ghosts.market.install'),- cancelText: isUpdate- ? t('settings.ghosts.updateConfirm.cancel')- : t('settings.ghosts.installConfirm.cancel'),- autoFocusConfirm: true,- });- if (!confirmed || !isMarketBusyLeaseActive(marketBusyLease)) return;- const ghost = await installReviewedMarketPackage({- detail: marketDetail,- lease: marketBusyLease,- options: {- expectedReleaseId: marketDetail.releaseId,- // 受体模型:同版本重装(恢复缺失批准)与升级都属 isUpdate,必须带旧- // 批准令牌,Main 在安装锁内核对当前受体后才放行。- ...(isUpdate && installedGhost- ? {- expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval),- }- : {}),- ...(marketDetail.sourceType !== 'server'- ? { expectedManifest: marketDetail.manifest }- : {}),- ...(isUpdate && diff!.added.length > 0- ? {- allowPermissionExpansion: true,- // 确认框展示期间已装 manifest 可能被换掉;基线交由 Main 在- // 安装锁内复核,不一致就拒绝这次批准而不是沿用旧同意。- ...(installedGhost- ? { reviewedBaseline: ghostPermissionBaselineKey(installedGhost.manifest) }- : {}),- }- : {}),- },- });- if (!ghost) return;- if (!isMarketBusyLeaseActive(marketBusyLease)) return;- // 市场首装装完即开(2026-07-26 定案),toast 用"已安装";更新路径如实- // 用"已更新"(生效状态未被改变)。- toast.success(- isUpdate- ? t('settings.ghosts.toast.updated', {- name: ghost.manifest.name,- version: ghost.manifest.version,- })- : t('settings.ghosts.toast.installed', {- name: ghost.manifest.name,- }),- );- setMarketDetail((current) =>- current?.pluginId === marketDetail.pluginId ? null : current,- );- setSelectedId(ghost.manifest.id);- await refreshMarket();- } catch (error) {- if (isMarketBusyLeaseActive(marketBusyLease)) {- toast.error(t(pluginMarketErrorKey(error)));+ const diff = isUpdate+ ? diffGhostPermissionItems(installedGhost!.manifest, marketDetail.manifest)+ : null;+ try {+ const confirmed = await confirm({+ title: isUpdate+ ? t('settings.ghosts.updateConfirm.title', { name: marketDetail.name })+ : t('settings.ghosts.market.installConfirmTitle', {+ name: marketDetail.name,+ }),+ description: isUpdate+ ? t('settings.ghosts.market.updateConfirmDescription')+ : // 自定义市场未经服务端完整性校验,确认文案必须如实区分。+ marketDetail.sourceType !== 'server'+ ? t('settings.ghosts.market.customInstallConfirmDescription')+ : t('settings.ghosts.market.installConfirmDescription'),+ // 限高与滚动交给共享 ConfirmDialog(max-h-[85vh] + 内部滚动区 + 打开时+ // 闪一下滚动条),这里不再自套一层 min(56vh,520px) —— 两层限高会让+ // "到底了没有"取决于内外层谁先触底(2026-07-27 收口)。+ content: isUpdate ? (+ <GhostUpdateReview diff={diff!} />+ ) : (+ <GhostPermissionList items={ghostPermissionItems(marketDetail.manifest)} />+ ),+ maxWidth: 520,+ confirmText: isUpdate+ ? t('settings.ghosts.updateConfirm.confirm')+ : t('settings.ghosts.market.install'),+ cancelText: isUpdate+ ? t('settings.ghosts.updateConfirm.cancel')+ : t('settings.ghosts.installConfirm.cancel'),+ autoFocusConfirm: true,+ });+ if (!confirmed || !isMarketBusyLeaseActive(marketBusyLease)) return;+ const ghost = await installReviewedMarketPackage({+ detail: marketDetail,+ lease: marketBusyLease,+ options: {+ expectedReleaseId: marketDetail.releaseId,++ // 更新/同版本恢复必须绑定确认时看到的 receipt,防止确认框等待期间++ // 已装插件被替换后仍把旧批准套到新字节上。++ ...(isUpdate && installedGhost++ ? { expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval) }++ : {}),+ ...(marketDetail.sourceType !== 'server'+ ? { expectedManifest: marketDetail.manifest }+ : {}),+ ...(isUpdate && diff!.added.length > 0+ ? {+ allowPermissionExpansion: true,+ // 确认框展示期间已装 manifest 可能被换掉;基线交由 Main 在+ // 安装锁内复核,不一致就拒绝这次批准而不是沿用旧同意。+ ...(installedGhost+ ? { reviewedBaseline: ghostPermissionBaselineKey(installedGhost.manifest) }+ : {}),+ }+ : {}),+ },+ });+ if (!ghost) return;+ if (!isMarketBusyLeaseActive(marketBusyLease)) return;+ // 市场首装装完即开(2026-07-26 定案),toast 用"已安装";更新路径如实+ // 用"已更新"(生效状态未被改变)。+ toast.success(+ isUpdate+ ? t('settings.ghosts.toast.updated', {+ name: ghost.manifest.name,+ version: ghost.manifest.version,+ })+ : t('settings.ghosts.toast.installed', {+ name: ghost.manifest.name,+ }),+ );+ setMarketDetail((current) =>+ current?.pluginId === marketDetail.pluginId ? null : current,+ );+ setSelectedId(ghost.manifest.id);+ await refreshMarket();+ } catch (error) {+ if (isMarketBusyLeaseActive(marketBusyLease)) {+ toast.error(t(pluginMarketErrorKey(error)));+ }+ } finally {+ releaseMarketBusy(marketBusyLease);}- } finally {- releaseMarketBusy(marketBusyLease);- }- }, [- acquireMarketBusy,- confirm,- ghosts,- isMarketBusyLeaseActive,- installReviewedMarketPackage,- refreshMarket,- releaseMarketBusy,- t,- ]);+ },+ [+ acquireMarketBusy,+ confirm,+ ghosts,+ isMarketBusyLeaseActive,+ installReviewedMarketPackage,+ refreshMarket,+ releaseMarketBusy,+ t,+ ],+ );const handleInstallFromMarket = useCallback(async () => {if (!marketDetail) return;await runMarketInstallFlow(marketDetail);@@@ -1301,13 -1363,8 +1415,11 @@@onUse={handleUse}onUpdate={() => void handleUpdate()}onUpdateFromFile={() => void handleUpdateFromFile()}+ // 受体模型的 §5 恢复入口:缺批准的安装在详情页重新确认(市场包重装 /+ // 本地包读目录权限确认),详情视图据 needsReapproval 门控运行按钮。+ onReapprove={() => void handleReapprove(selectedDetail.id)}updateVersion={selectedMarketUpdate?.version}- updateBusy={- (selectedMarketUpdate !== null && marketBusyId !== null) || batchRunning- }+ updateBusy={(selectedMarketUpdate !== null && marketBusyId !== null) || batchRunning}onUninstall={() => void handleUninstall()}// 官方保留前缀(cindy-/filo-/xd-)的插件走本地装入会被拒,// 导出产物无法重装,不提供导出项。diff --cc apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.tsindex f3bf806e55,f3bf806e55..70dacc76f4--- a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts+++ b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts@@@ -11,7 -11,7 +11,10 @@@ import { beforeEach, describe, expect,vi.mock('@/i18n', () => ({ i18n: { t: (key: string) => key } }));vi.mock('@/lib/toast', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));--let installedGhosts: Array<{ manifest: GhostManifest }> = [];++let installedGhosts: Array<{++ manifest: GhostManifest;++ approval?: { state: 'approved'; revision: string };++}> = [];vi.mock('@/cindy-brain/useInstalledGhosts', () => ({readInstalledGhostsSnapshot: () => installedGhosts,}));@@@ -114,6 -114,6 +117,25 @@@ describe('updateAllController', () =>expect(installMock).not.toHaveBeenCalled();});++ it('binds an automatic update to the installed receipt approval revision', async () => {++ const revision = '11111111-1111-4111-8111-111111111111';++ installedGhosts = [++ {++ manifest: manifest({ version: '1.0.0' }),++ approval: { state: 'approved', revision },++ },++ ];++ stubDetail({ manifest: manifest({}), sourceType: 'server' });++++ startUpdateAllBatch([marketItem({})]);++ await waitForSettledBatch();++++ expect(installMock).toHaveBeenCalledWith('plugin-a', {++ expectedReleaseId: 'release-2',++ expectedInstalledApproval: `approved:${revision}`,++ });++ });++it('holds actual package permissions for approval', async () => {stubDetail({ manifest: manifest({}), sourceType: 'server' });const review = {@@@ -166,6 -166,6 +188,7 @@@await approveUpdateExpansion('plugin-a');expect(installMock).toHaveBeenLastCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',});expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');});@@@ -184,6 -184,6 +207,7 @@@await approveUpdateExpansion('plugin-a');expect(installMock).toHaveBeenCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',expectedManifest: nextManifest,allowPermissionExpansion: true,reviewedBaseline: expect.any(String),@@@ -192,6 -192,6 +216,13 @@@});it('omits expectedManifest when approving a server-source expansion', async () => {++ const revision = '22222222-2222-4222-8222-222222222222';++ installedGhosts = [++ {++ manifest: manifest({ version: '1.0.0' }),++ approval: { state: 'approved', revision },++ },++ ];stubDetail({manifest: manifest({ network: { hosts: ['api.example.com'] } }),sourceType: 'server',@@@ -203,6 -203,6 +234,7 @@@expect(installMock).toHaveBeenCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: `approved:${revision}`,allowPermissionExpansion: true,reviewedBaseline: expect.any(String),});@@@ -236,7 -236,7 +268,13 @@@// 「从文件更新」把插件装成了第三个版本,且它已自带原先要审的 network 权限:// 审阅过的 diff 与 allowPermissionExpansion 都不再对应现实。installedGhosts = [-- { manifest: manifest({ version: '1.0.5', network: { hosts: ['api.example.com'] } }) },++ {++ manifest: manifest({ version: '1.0.5', network: { hosts: ['api.example.com'] } }),++ approval: {++ state: 'approved',++ revision: '33333333-3333-4333-8333-333333333333',++ },++ },];reconcileUpdateAllBatch();const held = getUpdateAllBatchState().rows?.[0];@@@ -245,7 -245,7 +283,10 @@@await approveUpdateExpansion('plugin-a');// 相对当前已装 manifest 已无扩权 → 按普通更新安装,不带 allowPermissionExpansion。-- expect(installMock).toHaveBeenCalledWith('plugin-a', { expectedReleaseId: 'release-2' });++ expect(installMock).toHaveBeenCalledWith('plugin-a', {++ expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'approved:33333333-3333-4333-8333-333333333333',++ });expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');});@@@ -285,7 -285,7 +326,10 @@@];await approveUpdateExpansion('plugin-a');-- expect(installMock).toHaveBeenCalledWith('plugin-a', { expectedReleaseId: 'release-2' });++ expect(installMock).toHaveBeenCalledWith('plugin-a', {++ expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',++ });});it('invalidates the review when a same-version manifest swap widened permissions', async () => {@@@ -333,6 -333,6 +377,7 @@@await approveUpdateExpansion('plugin-a');expect(installMock).toHaveBeenCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',allowPermissionExpansion: true,reviewedBaseline: expect.any(String),});@@@ -404,6 -404,6 +449,7 @@@// 目标 release 仍未落账 → 必须真正安装,不得凭版本号收成完成。expect(installMock).toHaveBeenCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',allowPermissionExpansion: true,reviewedBaseline: expect.any(String),});@@@ -624,6 -624,6 +670,7 @@@expect(installMock).toHaveBeenLastCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',expectedManifest: expect.anything(),});expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');@@@ -753,6 -753,6 +800,7 @@@await approveUpdateExpansion('plugin-a');expect(installMock).toHaveBeenLastCalledWith('plugin-a', {expectedReleaseId: 'release-2',++ expectedInstalledApproval: 'legacy-unapproved',expectedManifest: swappedManifest,allowPermissionExpansion: true,reviewedBaseline: expect.any(String),diff --cc apps/desktop/src/renderer/features/plugin/lib/updateAllController.tsindex ca60567571,ca60567571..1cc57aec7c--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts@@@ -24,8 -24,8 +24,10 @@@ import} from '@/contexts/dataOwnerGeneration';import {diffGhostPermissionItems,++ ghostInstallApprovalToken,ghostPermissionBaselineKey,type GhostManifest,++ type InstalledGhost,} from '../../../../shared/ghost';import type {PluginMarketItem,@@@ -189,10 -189,10 +191,12 @@@ export function setUpdateAllBatchHooks(};}++function installedGhostOf(ghostId: string): InstalledGhost | null {++ return readInstalledGhostsSnapshot().find((ghost) => ghost.manifest.id === ghostId) ?? null;++}++function installedManifestOf(ghostId: string): GhostManifest | null {-- return (-- readInstalledGhostsSnapshot().find((ghost) => ghost.manifest.id === ghostId)?.manifest ?? null-- );++ return installedGhostOf(ghostId)?.manifest ?? null;}function holdPackageReview(@@@ -307,13 -307,13 +311,14 @@@ async function runQueue(generation: numpatchRow(generation, next.pluginId, { status: 'done' });continue;}-- const installedManifest = installedManifestOf(next.ghostId);-- if (!installedManifest) {++ const installedGhost = installedGhostOf(next.ghostId);++ if (!installedGhost) {// 批量期间插件已被卸载:绝不拿市场 manifest 兜底继续安装// (那会把用户刚卸载的插件重新装回来),该行按跳过收束。patchRow(generation, next.pluginId, { status: 'skipped' });continue;}++ const installedManifest = installedGhost.manifest;const diff = diffGhostPermissionItems(installedManifest, detail.manifest);if (diff.added.length > 0) {// 扩权不自动放行:停在待确认,由用户在弹窗里逐项同意或跳过。@@@ -329,6 -329,6 +334,7 @@@}const result = await window.electronAPI.pluginMarket.install(next.pluginId, {expectedReleaseId: detail.releaseId,++ expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval),...(detail.sourceType !== 'server' ? { expectedManifest: detail.manifest } : {}),});if (result.reviewRequired) {@@@ -446,7 -446,7 +452,7 @@@ async function runApprovalBody(pluginIdconst row = state.rows?.find((candidate) => candidate.pluginId === pluginId);// 排在前面的批准可能已经把本行推进过(重复点同一项),只处理仍待确认的。if (!row || row.status !== 'needs-confirm' || !row.releaseId) return;-- if (installedManifestOf(row.ghostId) === null) {++ if (installedGhostOf(row.ghostId) === null) {// 待确认期间插件被卸载:同意也不重装,按跳过收束。patchRow(generation, pluginId, { status: 'skipped' });return;@@@ -475,11 -475,11 +481,12 @@@}// **detail 之后重读已装 manifest**:这段往返里「从文件更新」等路径可能整体// 换掉它,拿 await 之前的快照判断 = 拿过期事实做安全决策。-- const installed = installedManifestOf(row.ghostId);-- if (installed === null) {++ const installedGhost = installedGhostOf(row.ghostId);++ if (installedGhost === null) {patchRow(generation, pluginId, { status: 'skipped' });return;}++ const installed = installedGhost.manifest;if (detail.installState === 'installed') {// 目标 release 已由别的路径装上:直接收束,不重复下载安装。// (return 后仍走 finally 的统一收尾——刷新市场快照 + 完成 toast。)@@@ -573,6 -573,6 +580,7 @@@if (reviewStillValid) {const didInstall = await installOrHoldForReReview({expectedReleaseId: row.releaseId,++ expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval),...(row.expectedManifest ? { expectedManifest: row.expectedManifest } : {}),allowPermissionExpansion: true,// 审阅基线随批准回传:Main 在安装锁内用当时的已装 manifest 复核,@@@ -596,6 -596,6 +604,7 @@@// 不匹配拒绝,不能把它落成终态失败。const ok = await installOrHoldForReReview({expectedReleaseId: detail.releaseId,++ expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval),...(detail.sourceType !== 'server' ? { expectedManifest: detail.manifest } : {}),});if (!ok) return;