Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): stop treating market manifest as package cap
liugaoweia6ed0e50237d
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex 52533e0fb9..be16eeb161 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -5650,10 +5650,6 @@ export async function installOrUpdateMarketGhostPackage(version: string;/** receipt 模型并发护栏:更新分支比对 receipt 派生 token(与 main 硬化叠加,决策 A)。 */expectedInstalledApproval?: string;- /**- * 市场发现层已经公开的 Manifest。真实包可以缩小能力,但不能携带发现层- * 没有声明的 Host 能力;超出时按包内容不一致拒绝,不转成用户授权弹窗。- *//*** Organization server-market packages pass this Host-built fact because the* ledger row is written after install/update. Official-prefix ids never@@ -5662,6 +5658,7 @@ export async function installOrUpdateMarketGhostPackage(* defaultInstall, and source replacement.*/pendingMarketRecord?: GhostFirstPartyPendingMarketRecord;+ /** 自定义 Git/本地市场在打包前读取的 Manifest,用于防止打包窗口内能力扩张。 */manifestCap?: GhostManifest;beforeCommitInLock?: () => void;/** 新包已经原子换位;后续异常不能再按落位失败回滚来源路由。 */@@ -5717,8 +5714,9 @@ async function installOrUpdateMarketGhostPackageLocked(? 'cindy-official': undefined;requireGhostAvailableForActiveSession(expected.ghostId);- // 市场投影只作为真实包的能力上限,避免分发内容与目录声明漂移;- // 安装动作本身不承担能力授权,也不会因此追加权限确认弹窗。+ // 自定义 Git/本地市场的活目录可能在发现后、打包前变化;它们传入发现时的+ // Manifest 作为 TOCTOU 上限。官方市场由服务端 Release SHA 绑定真实包,目录+ // Manifest 只用于展示,不参与这里的安装准入。const installed = manager.list().find((ghost) => ghost.manifest.id === expected.ghostId);if (expected.manifestCap) {const undeclaredCapabilities = unreviewedGhostPermissionItems(@@ -5739,7 +5737,7 @@ async function installOrUpdateMarketGhostPackageLocked(!ghostToolParametersWithinCap(expected.manifestCap, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(expected.manifestCap, inspected.canonicalManifest)) {- log.warn('market package exceeds catalog manifest capabilities', {+ log.warn('custom market package exceeds discovered manifest capabilities', {ghostId: expected.ghostId,keys: undeclaredCapabilities.map((item) => item.key),});@@ -5762,7 +5760,7 @@ async function installOrUpdateMarketGhostPackageLocked();// Manifest 能力只用于 Host 注册、校验和运行时守门。用户点击安装后不再- // 经过插件级权限确认;真实包仍必须通过上面的市场声明上限与 Host 校验。+ // 经过插件级权限确认;自定义活目录还必须通过上面的打包窗口一致性校验。// Hold the owner-stability lease only for the actual Ghost filesystem// mutation.releaseMutation = beginGhostMutation(mutationOwner);diff --git a/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.tsindex 0c19c0b38e..1880f0b477 100644--- a/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/service-custom-sources.test.ts@@ -2185,9 +2185,7 @@ describe('PluginMarketService 自定义市场 detail/install', () => {allowSourceReplacement: true,}),).resolves.toMatchObject({ ghost: { manifest: { id: 'server-plugin' } } });- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: ghostManifest('server-plugin'),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');expect(h.ledger.installationForGhost('server-plugin')).toMatchObject({pluginId: item.id,source: 'market',diff --git a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service.test.tsindex bf851e229d..619df9ff49 100644--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts@@ -1016,7 +1016,6 @@ describe('PluginMarketService migration and defaultInstall', () => {expect.objectContaining({ghostId: 'cindy-test',version: '1.0.0',- manifestCap: manifest(),beforeCommitInLock: expect.any(Function),}),);@@ -1031,7 +1030,7 @@ describe('PluginMarketService migration and defaultInstall', () => {});});- it('installs a default package whose manifest cap contains normalized setup requirements', async () => {+ it('installs a default package whose detail manifest contains normalized setup requirements', async () => {const item = summary({ defaultInstall: true });const rawManifest = setupKvManifest();const approvedManifest = normalizedManifest(rawManifest);@@ -1054,12 +1053,7 @@ describe('PluginMarketService migration and defaultInstall', () => {await expect(h.service.snapshot()).resolves.toMatchObject({items: [{ installState: 'installed', enabled: true }],});- expect(runtime.install).toHaveBeenCalledWith(- expect.stringMatching(/\.cindy$/),- expect.objectContaining({- manifestCap: approvedManifest,- }),- );+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('returns a Renderer snapshot before a default install download finishes', async () => {@@ -1094,25 +1088,27 @@ describe('PluginMarketService migration and defaultInstall', () => {await vi.waitFor(() => expect(runtime.install).toHaveBeenCalledOnce());});- it('does not auto-install a package rejected for exceeding its catalog manifest', async () => {+ it('auto-installs the verified package when its capabilities exceed stale catalog metadata', async () => {const item = summary({ defaultInstall: true });- runtime.install.mockRejectedValueOnce(- Object.assign(new Error('package capabilities exceed market manifest'), {- code: 'GHOST_FILE_INVALID',- }),- );const h = harness([item]);+ const actualManifest = manifest(item.ghostId, item.currentRelease.version, ['notify', 'fs']);+ runtime.inspectedManifest = actualManifest;+ runtime.install.mockImplementationOnce(async () => {+ const ghost = {+ manifest: actualManifest,+ dir: '/userData/cindy-brain/cindy-test',+ enabled: true,+ };+ runtime.ghosts = [ghost];+ return ghost;+ });const snapshot = await h.service.snapshot();- expect(runtime.install).toHaveBeenCalledWith(- expect.stringMatching(/\.cindy$/),- expect.objectContaining({- manifestCap: manifest(),- }),- );- expect(snapshot.items[0]?.installState).toBe('not-installed');- expect(h.ledger.installationForGhost(item.ghostId)).toBeNull();+ expect(runtime.install).toHaveBeenCalledOnce();+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');+ expect(snapshot.items[0]?.installState).toBe('installed');+ expect(h.ledger.installationForGhost(item.ghostId)).toMatchObject({ installed: true });});it('does not infer historical provenance from the server manifest', async () => {@@ -1182,7 +1178,6 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(runtime.install).toHaveBeenCalledWith(expect.stringMatching(/\.cindy$/), {ghostId: 'cindy-test',version: '1.0.0',- manifestCap: incompatibleManifest,afterCommitInLock: expect.any(Function),});});@@ -1214,7 +1209,7 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(runtime.install).toHaveBeenCalledTimes(1);});- it('rejects downloaded tool parameter schemas that drift from the catalog manifest', async () => {+ it('installs the verified package when tool schemas drift from stale catalog metadata', async () => {const item = summary();const reviewedManifest = normalizedManifest({...manifest(),@@ -1253,14 +1248,19 @@ describe('PluginMarketService migration and defaultInstall', () => {currentRelease: { ...item.currentRelease, manifest: reviewedManifest },} as unknown as VisiblePluginDetail);runtime.inspectedManifest = actualManifest;+ runtime.install.mockResolvedValue({+ manifest: actualManifest,+ dir: '/userData/cindy-brain/cindy-test',+ enabled: true,+ });await expect(h.service.install(item.id, {expectedReleaseId: item.currentRelease.id,expectedManifest: reviewedManifest,}),- ).rejects.toMatchObject({ code: 'GHOST_FILE_INVALID' });- expect(runtime.install).not.toHaveBeenCalled();+ ).resolves.toMatchObject({ ghost: { manifest: actualManifest } });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('keeps a no-port broker release visible in detail but rejects market installation before download', async () => {@@ -1304,7 +1304,6 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(runtime.install).toHaveBeenCalledWith(expect.stringMatching(/\.cindy$/), {ghostId: 'cindy-test',version: '1.0.0',- manifestCap: manifest(),afterCommitInLock: expect.any(Function),});// 安装入口用目录 summary 做 detail 身份绑定(防止把 A 的确认导向 B 的内容),@@ -1404,10 +1403,7 @@ describe('PluginMarketService migration and defaultInstall', () => {},},});- expect(runtime.install).toHaveBeenCalledWith(- expect.stringMatching(/\.cindy$/),- expect.objectContaining({ manifestCap: reviewedManifest }),- );+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('installs the explicitly selected official entry when another entry shares its ghostId', async () => {@@ -1456,7 +1452,6 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(runtime.install.mock.calls[0]?.[1]).toEqual({ghostId: 'cindy-test',version: '1.0.0',- manifestCap: manifest(),afterCommitInLock: expect.any(Function),});});@@ -1798,7 +1793,7 @@ describe('PluginMarketService migration and defaultInstall', () => {});});- it('passes the selected server manifest as the downloaded package capability cap', async () => {+ it('does not treat the server manifest as a downloaded package capability cap', async () => {const item = summary();runtime.install.mockResolvedValue({manifest: manifest(),@@ -1809,12 +1804,10 @@ describe('PluginMarketService migration and defaultInstall', () => {await h.service.install(item.id, reviewedInstallOptions(item));- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: manifest(),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});- it('uses the selected release manifest as the update package capability cap', async () => {+ it('does not treat the selected release manifest as an update package capability cap', async () => {const item = summary({currentRelease: { ...summary().currentRelease, id: 'release-2', version: '2.0.0' },});@@ -1855,9 +1848,7 @@ describe('PluginMarketService migration and defaultInstall', () => {expectedInstalledApproval: APPROVED_INSTALL_TOKEN,});- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: manifest(item.ghostId, '2.0.0'),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('keeps a stale official record out of automatic updates but allows explicit replacement', async () => {@@ -1922,9 +1913,7 @@ describe('PluginMarketService migration and defaultInstall', () => {).resolves.toMatchObject({ghost: { manifest: { version: '2.0.0' } },});- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: manifest(item.ghostId, '2.0.0'),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');expect(h.ledger.installationForGhost(item.ghostId)).toMatchObject({pluginId: item.id,source: 'market',@@ -1933,7 +1922,7 @@ describe('PluginMarketService migration and defaultInstall', () => {});});- it('uses the selected release manifest as the cap for a legacy-record update', async () => {+ it('updates a legacy record without treating server metadata as a package cap', async () => {const item = summary({currentRelease: { ...summary().currentRelease, id: 'release-2', version: '2.0.0' },});@@ -1960,9 +1949,7 @@ describe('PluginMarketService migration and defaultInstall', () => {expectedInstalledApproval: APPROVED_INSTALL_TOKEN,});- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: manifest(item.ghostId, '2.0.0'),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('installs and enables a public defaultInstall package in local mode', async () => {@@ -1990,7 +1977,6 @@ describe('PluginMarketService migration and defaultInstall', () => {expect.objectContaining({ghostId: item.ghostId,version: item.currentRelease.version,- manifestCap: manifest(),beforeCommitInLock: expect.any(Function),}),);@@ -2078,13 +2064,12 @@ describe('PluginMarketService migration and defaultInstall', () => {expect.objectContaining({ghostId: item.ghostId,version: '2.0.0',- manifestCap: upgraded,}),);expect(snapshot.items[0]).toMatchObject({ installState: 'installed', enabled: false });});- it('silently upgrades a default package whose manifest cap contains normalized setup', async () => {+ it('silently upgrades a default package whose detail manifest contains normalized setup', async () => {const item = summary({scope: 'organization',organizationId: 'org-1',@@ -2123,12 +2108,7 @@ describe('PluginMarketService migration and defaultInstall', () => {await expect(h.service.snapshot()).resolves.toMatchObject({items: [{ installState: 'installed', version: '2.0.0' }],});- expect(runtime.install).toHaveBeenCalledWith(- expect.stringMatching(/\.cindy$/),- expect.objectContaining({- manifestCap: upgradedManifest,- }),- );+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('integration: snapshot upgrades an organization defaultInstall release', async () => {@@ -3153,9 +3133,7 @@ describe('PluginMarketService migration and defaultInstall', () => {).resolves.toMatchObject({ghost: { manifest: { id: item.ghostId } },});- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: manifest(),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');expect(h.ledger.installationForGhost(item.ghostId)).toMatchObject({pluginId: item.id,source: 'market',@@ -3189,7 +3167,7 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(h.ledger.installationForGhost(item.ghostId)).toBeNull();});- it('keeps the selected release manifest as the cap when the installed snapshot changes', async () => {+ it('keeps the selected release identity when the installed snapshot changes', async () => {const item = summary({currentRelease: { ...summary().currentRelease, id: 'release-2', version: '2.0.0' },});@@ -3219,7 +3197,7 @@ describe('PluginMarketService migration and defaultInstall', () => {version: '1.0.0',});// 下载窗口期目标包相对“当前实际已装”多出 fs;安装事务仍以选中 release 的- // manifest 为能力上限,不再为能力变化增加另一层用户审批。+ // id/version/SHA 为身份边界,不再把市场的展示 Manifest 当成包能力上限。await expect(h.service.install(item.id, {...reviewedInstallOptions(item),@@ -3228,9 +3206,7 @@ describe('PluginMarketService migration and defaultInstall', () => {).resolves.toMatchObject({ghost: { manifest: { version: '2.0.0' } },});- expect(runtime.install.mock.calls[0]?.[1]).toMatchObject({- manifestCap: manifest('cindy-test', '2.0.0'),- });+ expect(runtime.install.mock.calls[0]?.[1]).not.toHaveProperty('manifestCap');});it('rejects an update when the installed target disappears during download', async () => {diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.tsindex 384cda3726..3f21d6c658 100644--- a/apps/desktop/src/main/plugin-market/service.ts+++ b/apps/desktop/src/main/plugin-market/service.ts@@ -13,19 +13,11 @@ import { app, dialog } from 'electron';import {GHOST_ICON_MAX_BYTES,- ghostNetworkAuthorizationWithinCap,- ghostNodeSecretAuthorizationWithinCap,- ghostSetupAuthorizationWithinCap,- ghostSettingsUiWithinCap,- ghostSubscribeAuthorizationWithinCap,- ghostToolParametersWithinCap,- ghostUnknownV3FieldsWithinCap,ghostInstallApprovalToken,ghostIconMimeType,isSafeGhostRelativePath,isOfficialGhostId,isValidGhostId,- unreviewedGhostPermissionItems,validateGhostManifest,type GhostManifest,type InstalledGhost,@@ -1070,10 +1062,6 @@ export class PluginMarketService {if (plugin.currentRelease.id !== options.expectedReleaseId) {throwIpcError('PRECONDITION_FAILED', 'Plugin release changed after selection');}- const compatible = validateGhostManifest(plugin.currentRelease.manifest);- if (!compatible.ok) {- throwIpcError('GHOST_FILE_INVALID', 'This Plugin manifest is not supported');- }const existing = getGhostManager().list().find((ghost) => ghost.manifest.id === plugin.ghostId);@@ -1084,7 +1072,6 @@ export class PluginMarketService {...(options.expectedInstalledApproval !== undefined? { expectedInstalledApproval: options.expectedInstalledApproval }: {}),- manifestCap: compatible.manifest,allowSourceReplacement: options.allowSourceReplacement === true,},owner,@@ -1696,8 +1683,6 @@ export class PluginMarketService {options: {/** receipt 模型的并发护栏:比对 receipt 派生 token,状态变更即拒(与 main 硬化叠加)。 */expectedInstalledApproval?: string;- /** 市场目录公开 Manifest 是真实下载包允许的 Host 能力上限。 */- manifestCap?: GhostManifest;/** 用户明确点击安装时,允许所选市场包原地替换其它来源的同 id 插件。 */allowSourceReplacement?: boolean;beforeCommitInLock?: () => void;@@ -1743,10 +1728,6 @@ export class PluginMarketService {}}- // manifestCap 只来自上游同一条安装链路已经通过 validateGhostManifest 的- // 规范化结果。v2 的内部模型会移除 slots,再把它当原始 ghost.json 二次校验- // 会误判为非法;这里直接把已验证的能力上限交给真实包一致性校验。- const manifestCap = options.manifestCap ?? null;const download = await this.api.download(plugin.id, plugin.currentRelease.id);requireSameMarketOwner(owner);if (@@ -1775,28 +1756,6 @@ export class PluginMarketService {) {throwIpcError('GHOST_FILE_INVALID', 'Downloaded Plugin package identity changed');}- if (manifestCap) {- const extraCapabilities = unreviewedGhostPermissionItems(- manifestCap,- undefined,- inspected.canonicalManifest,- );- if (- extraCapabilities.length > 0 ||- !ghostNetworkAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||- !ghostNodeSecretAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||- !ghostSetupAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||- !ghostSettingsUiWithinCap(manifestCap, inspected.canonicalManifest) ||- !ghostSubscribeAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||- !ghostToolParametersWithinCap(manifestCap, inspected.canonicalManifest) ||- !ghostUnknownV3FieldsWithinCap(manifestCap, inspected.canonicalManifest)- ) {- throwIpcError(- 'GHOST_FILE_INVALID',- 'Downloaded Plugin package capabilities exceed the market manifest',- );- }- }}const ghost = await this.commitDownloadedPackage(tempPath,@@ -1806,7 +1765,6 @@ export class PluginMarketService {...(options.expectedInstalledApproval !== undefined? { expectedInstalledApproval: options.expectedInstalledApproval }: {}),- ...(manifestCap ? { manifestCap } : {}),allowSourceReplacement: options.allowSourceReplacement,beforeCommitInLock: options.beforeCommitInLock,},@@ -1825,7 +1783,6 @@ export class PluginMarketService {plugin: VisiblePluginSummary | VisiblePluginDetail,options: {expectedInstalledApproval?: string;- manifestCap?: GhostManifest;allowSourceReplacement?: boolean;beforeCommitInLock?: () => void;expectedInstalled: boolean;@@ -1908,7 +1865,6 @@ export class PluginMarketService {...(options.expectedInstalledApproval !== undefined? { expectedInstalledApproval: options.expectedInstalledApproval }: {}),- ...(options.manifestCap ? { manifestCap: options.manifestCap } : {}),...(options.beforeCommitInLock || replacingSource? { beforeCommitInLock: detachPreviousRoute }: {}),@@ -2360,17 +2316,11 @@ export class PluginMarketService {const detail = await this.api.detail(summary.id);requireSameMarketOwner(owner);assertDetailMatchesSummary(summary, detail);- const manifestCap = validateGhostManifest(detail.currentRelease.manifest);- if (!manifestCap.ok) {- throwIpcError('GHOST_FILE_INVALID', 'This Plugin manifest is not supported');- }// 装完即开语义已收敛进市场安装入口本身,这里无需再显式声明。await this.installDetail(detail,{expectedInstalled: false,- // 目录 Manifest 是真实包允许的能力上限;超出时按包内容不一致拒绝。- manifestCap: manifestCap.manifest,// 下载期间用户可能从本地插件页完成显式卸载。最终落位前在// ghostId 锁内重读卸载意图,不能让旧 snapshot 把插件装回来。beforeCommitInLock: () => {@@ -2464,16 +2414,11 @@ export class PluginMarketService {const detail = await this.api.detail(summary.id);requireSameMarketOwner(owner);assertDetailMatchesSummary(summary, detail);- const manifestCap = validateGhostManifest(detail.currentRelease.manifest);- if (!manifestCap.ok) {- throwIpcError('GHOST_FILE_INVALID', 'This Plugin manifest is not supported');- }await this.installDetail(detail,{expectedInstalled: true,expectedInstalledApproval: ghostInstallApprovalToken(freshInstalled.approval),- manifestCap: manifestCap.manifest,beforeCommitInLock: () => {if (isGhostBusy(summary.ghostId)) {throw new SilentUpgradeBusyError('Plugin is busy');