Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): cap market setup requirements
liugaowei294db527adb8
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex b19f37b9c3..d1af0bc376 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -28,6 +28,7 @@ import {ghostInstallApprovalToken,ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSetupAuthorizationWithinCap,ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,@@ -5676,6 +5677,7 @@ async function installOrUpdateMarketGhostPackageLocked(expected.manifestCap,inspected.canonicalManifest,) ||+ !ghostSetupAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest) ||!ghostSettingsUiWithinCap(expected.manifestCap, inspected.canonicalManifest) ||!ghostSubscribeAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(expected.manifestCap, inspected.canonicalManifest)diff --git a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service.test.tsindex 38098f7b23..b4c48051bd 100644--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts@@ -1010,6 +1010,7 @@ describe('PluginMarketService migration and defaultInstall', () => {const rawManifest = setupKvManifest();const approvedManifest = normalizedManifest(rawManifest);const h = harness([item]);+ runtime.inspectedManifest = approvedManifest;h.api.detail.mockResolvedValueOnce({...item,currentRelease: { ...item.currentRelease, manifest: rawManifest },diff --git a/apps/desktop/src/main/plugin-market/install.ts b/apps/desktop/src/main/plugin-market/install.tsindex 0072e6ae62..76beeaa22a 100644--- a/apps/desktop/src/main/plugin-market/install.ts+++ b/apps/desktop/src/main/plugin-market/install.ts@@ -17,6 +17,7 @@ import { app } from 'electron';import {ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSetupAuthorizationWithinCap,ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,@@ -202,6 +203,7 @@ export async function installCustomMarketPlugin(input: {extraCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostNodeSecretAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||+ !ghostSetupAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostSettingsUiWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostSubscribeAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(validated.manifest, inspected.canonicalManifest)diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.tsindex d936572d54..3009d90058 100644--- a/apps/desktop/src/main/plugin-market/service.ts+++ b/apps/desktop/src/main/plugin-market/service.ts@@ -15,6 +15,7 @@ import {GHOST_ICON_MAX_BYTES,ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSetupAuthorizationWithinCap,ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,@@ -1778,6 +1779,7 @@ export class PluginMarketService {extraCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostNodeSecretAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||+ !ghostSetupAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostSettingsUiWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostSubscribeAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(manifestCap, inspected.canonicalManifest)diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.tsindex d5daf40277..9042535b43 100644--- a/apps/desktop/src/shared/__tests__/ghost.test.ts+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts@@ -15,6 +15,7 @@ import {ghostLocalePathFor,ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSetupAuthorizationWithinCap,ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,@@ -4518,6 +4519,7 @@ describe('ghostPermissionProjectionFingerprint', () => {const fixedHeight = (height: number) =>validateGhostManifest({...goodChipManifest(),+ slots: ['panel', 'model', 'network'],settingsHtml: 'settings.html',settingsHeight: height,});@@ -4539,6 +4541,86 @@ describe('ghostPermissionProjectionFingerprint', () => {expect(ghostSettingsUiWithinCap(autoHeight.manifest, withoutSettings.manifest)).toBe(true);});+ it('market cap only allows setup requirement groups to stay identical or be removed', () => {+ const reviewed = validateGhostManifest({+ schemaVersion: 3,+ minCindyVersion: '0.1.61',+ id: 'setup-helper',+ name: 'Setup helper',+ version: '1.0.0',+ entry: 'main.js',+ settingsHtml: 'settings.html',+ network: {+ hosts: ['api.example.com'],+ secrets: [+ {+ key: 'api_key',+ label: 'API key',+ inject: { header: 'Authorization', format: 'Bearer {value}' },+ },+ ],+ connections: [+ {+ key: 'account',+ label: 'Account',+ inject: { header: 'Authorization', format: 'Bearer {value}' },+ },+ ],+ },+ setup: {+ requires: [+ { anyOf: ['secret:api_key', 'connection:account'] },+ { anyOf: [{ kv: 'workspace', label: 'Workspace' }] },+ ],+ },+ });+ expect(reviewed.ok).toBe(true);+ if (!reviewed.ok || !reviewed.manifest.setup) return;+ const [credentials, workspace] = reviewed.manifest.setup.requires;+ const withSetup = (requires: NonNullable<GhostManifest['setup']>['requires']): GhostManifest =>+ ({ ...reviewed.manifest, setup: { requires } });+ const { setup: _setup, ...implicit } = reviewed.manifest;+ const explicitOptOut = withSetup([]);++ expect(+ ghostSetupAuthorizationWithinCap(+ reviewed.manifest,+ withSetup([+ workspace!,+ { anyOf: [...credentials!.anyOf].reverse() },+ ]),+ ),+ ).toBe(true);+ expect(ghostSetupAuthorizationWithinCap(reviewed.manifest, withSetup([credentials!]))).toBe(+ true,+ );+ expect(+ ghostSetupAuthorizationWithinCap(+ reviewed.manifest,+ withSetup([...reviewed.manifest.setup.requires, { anyOf: [workspace!.anyOf[0]!] }]),+ ),+ ).toBe(false);+ expect(+ ghostSetupAuthorizationWithinCap(+ reviewed.manifest,+ withSetup([{ anyOf: [credentials!.anyOf[0]!] }, workspace!]),+ ),+ ).toBe(false);+ expect(+ ghostSetupAuthorizationWithinCap(+ reviewed.manifest,+ withSetup([+ credentials!,+ { anyOf: [{ kind: 'kv', key: 'workspace', label: 'Account password' }] },+ ]),+ ),+ ).toBe(false);+ expect(ghostSetupAuthorizationWithinCap(implicit, implicit)).toBe(true);+ expect(ghostSetupAuthorizationWithinCap(implicit, withSetup([credentials!]))).toBe(false);+ expect(ghostSetupAuthorizationWithinCap(implicit, explicitOptOut)).toBe(true);+ expect(ghostSetupAuthorizationWithinCap(explicitOptOut, implicit)).toBe(false);+ });+it('same-key/different-labelArgs 同时作废 baseline、diff 与真实包复核', () => {const reviewed = validateGhostManifest({...goodChipManifest(),diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex deec5c7541..af78fcd02c 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -2641,6 +2641,45 @@ export function ghostSubscribeAuthorizationWithinCap();}+function ghostSetupGroupCapKey(group: GhostSetupGroup): string {+ return group.anyOf+ .map((requirement) =>+ requirement.kind === 'kv'+ ? `kv:${requirement.key}:${JSON.stringify(requirement.label)}`+ : `${requirement.kind}:${requirement.key}`,+ )+ .sort()+ .join('\0');+}++/**+ * 市场清单对真实包 setup 运行门的上限。+ *+ * 两边都未显式声明时继续采用 Host 启发式;其引用只能来自已经单独受限的+ * network/node 声明。市场未声明时,真实包只能显式 opt-out;市场已经声明时,+ * 真实包只能删除完整需求组,不能退回启发式、增加组、收紧 anyOf,或换入新的+ * 引用/kv 文案。+ */+export function ghostSetupAuthorizationWithinCap(+ reviewed: GhostManifest,+ actual: GhostManifest,+): boolean {+ if (reviewed.setup === undefined && actual.setup === undefined) return true;+ if (reviewed.setup === undefined) return actual.setup?.requires.length === 0;+ if (actual.setup === undefined) return false;++ const reviewedGroups = reviewed.setup.requires;+ const actualGroups = actual.setup.requires;+ const remainingReviewed = reviewedGroups.map(ghostSetupGroupCapKey);+ for (const group of actualGroups) {+ const key = ghostSetupGroupCapKey(group);+ const index = remainingReviewed.indexOf(key);+ if (index < 0) return false;+ remainingReviewed.splice(index, 1);+ }+ return true;+}+function canonicalGhostExtensionValue(value: unknown): string {if (Array.isArray(value)) {return `[${value.map(canonicalGhostExtensionValue).join(',')}]`;diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.mdindex a4eb767127..4142cf50f5 100644--- a/docs/dev-rules/plugin-security-and-authoring.md+++ b/docs/dev-rules/plugin-security-and-authoring.md@@ -135,7 +135,8 @@自定义市场以发现并规范化的 manifest 为能力上限。能力上限内的新版声明可静默更新,超出则按包内容不一致拒绝并留待来源修复,不转成用户审批流程。能力上限按 Host 实际消费语义比较:真实包不得从无到有增加 `settingsHtml` 设置 WebView 或扩大固定 `settingsHeight`;- OAuth `scopes` 换序或取子集属于收权,其它 OAuth、凭证标签与注入字段仍须保持在清单上限内。+ OAuth `scopes` 换序或取子集属于收权,其它 OAuth、凭证标签与注入字段仍须保持在清单上限内;+ `setup.requires` 只能保留或删除市场已有的完整需求组,不能增加组、收紧 `anyOf` 或更换引用。- 本地 `.cindy` 没有稳定来源,不自动更新;用户再次导入同 id 新包时直接原位更新,由 Main保持当前启用状态。- Host receipt 是安装事务和运行完整性的状态记录,不是一次交互式“能力授权”。合法的安装/更新