Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 修复 setup.kv 批准凭据校验
davidb4327b5ce983
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.tsindex 1635951286..4c91d9d73b 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts@@ -72,6 +72,16 @@ function goodManifest(id = 'hello'): Record<string, unknown> {};}+function setupKvManifest(id = 'hello'): Record<string, unknown> {+ return {+ ...goodManifest(id),+ settingsHtml: 'settings.html',+ setup: {+ requires: [{ anyOf: [{ kv: 'repoDir', label: '本机 cindy 项目目录' }] }],+ },+ };+}+function atResourceManifest(id = 'hello'): Record<string, unknown> {return {...goodManifest(id),@@ -263,6 +273,27 @@ describe('GhostManager · 存量插件一次性迁移(§5 升级无感)', () =>expect(fs.existsSync(migrationLedgerPath())).toBe(true);});+ it('带 setup.kv 的旧安装无感迁移并保留标准化就绪声明', async () => {+ await writeLegacyInstall('hello', setupKvManifest(), {+ files: { 'settings.html': '<!doctype html>' },+ });++ const outcome = await manager.migrateLegacyApprovalsOnce();++ expect(outcome.migrated).toEqual(['hello']);+ expect(manager.list()[0]).toMatchObject({+ enabled: true,+ approval: { state: 'approved' },+ manifest: {+ setup: {+ requires: [+ { anyOf: [{ kind: 'kv', key: 'repoDir', label: '本机 cindy 项目目录' }] },+ ],+ },+ },+ });+ });+it('未批准或 receipt 损坏的插件不展示可变 trust 镜像', async () => {const forgedTrust = {level: 'cindy-official' as const,@@ -921,6 +952,34 @@ describe('GhostManager · 从已装目录重新确认(本地包第三条恢复expect(fs.existsSync(path.join(rootDir, 'hello', '.disabled'))).toBe(false);});+ it('带 setup.kv 的旧安装可从已装目录重新确认并恢复可用', async () => {+ await writeLegacyInstall('hello', setupKvManifest(), {+ files: { 'settings.html': '<!doctype html>' },+ });+ const inspected = await manager.inspectInstalledReapproval('hello');+ if ('rejection' in inspected) throw new Error(JSON.stringify(inspected.rejection));++ const result = await manager.reapproveInstalled('hello', {+ enable: true,+ expectedManifestSha256: inspected.manifestSha256,+ expectedApprovalProjectionSha256: inspected.approvalProjectionSha256,+ expectedInstalledApproval: 'legacy-unapproved',+ });++ if ('rejection' in result) throw new Error(JSON.stringify(result.rejection));+ expect(manager.list()[0]).toMatchObject({+ enabled: true,+ approval: { state: 'approved' },+ manifest: {+ setup: {+ requires: [+ { anyOf: [{ kind: 'kv', key: 'repoDir', label: '本机 cindy 项目目录' }] },+ ],+ },+ },+ });+ });+it('重新确认要求立即启用时,删除停用镜像失败必须拒绝且不提交批准', async () => {await writeLegacyInstall('hello', goodManifest(), { disabled: true });const inspected = await manager.inspectInstalledReapproval('hello');diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.tsindex 079fd1e0e3..b4bafb846c 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallReceipt.test.ts@@ -4,6 +4,8 @@ import path from 'node:path';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { validateGhostManifest } from '../../../shared/ghost';+import {createGhostInstallReceipt,GhostInstallReceiptStore,@@ -116,6 +118,52 @@ describe('GhostInstallReceiptStore cleanup', () => {expect(fs.existsSync(path.join(stateRoot, 'hello.json'))).toBe(false);});+ it('writes and reads a receipt containing a normalized setup kv requirement', async () => {+ const parsed = validateGhostManifest({+ schemaVersion: 2,+ id: 'hello',+ name: 'Hello',+ version: '1.0.0',+ kind: 'chip',+ entry: 'main.js',+ settingsHtml: 'settings.html',+ slots: ['tool'],+ tools: [{ name: 'do_thing', description: 'Do something' }],+ setup: {+ requires: [{ anyOf: [{ kv: 'repoDir', label: '本机 cindy 项目目录' }] }],+ },+ });+ expect(parsed.ok).toBe(true);+ if (!parsed.ok) return;++ const receipt = createGhostInstallReceipt({+ manifest: parsed.manifest,+ localeResources: {},+ enabled: true,+ trust: {+ level: 'unverified',+ publisherSigned: false,+ publisherVerified: false,+ reviewed: false,+ },+ skillContentSha256: {},+ });++ await store.write(receipt);+ expect(store.read('hello')).toMatchObject({+ state: 'approved',+ receipt: {+ manifest: {+ setup: {+ requires: [+ { anyOf: [{ kind: 'kv', key: 'repoDir', label: '本机 cindy 项目目录' }] },+ ],+ },+ },+ },+ });+ });+it('treats only a missing migration marker as absent', () => {expect(store.hasMigrationMarker('hello')).toBe(false);});diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.tsindex 260ba81c2f..239a8120d8 100644--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts@@ -7,8 +7,8 @@ import {GHOST_LOCALE_MAX_BYTES,GHOST_SKILL_MD_MAX_BYTES,isValidGhostId,- validateGhostManifest,validateGhostManifestLocaleResource,+ validateNormalizedGhostManifest,type GhostManifest,type GhostManifestLocaleResource,type GhostTrustInfo,@@ -1079,7 +1079,7 @@ function validateReceipt(if (typeof value.revision !== 'string' || !isRevision(value.revision)) {return { ok: false, reason: 'receipt revision 不合法' };}- const manifestResult = validateGhostManifest(value.manifest);+ const manifestResult = validateNormalizedGhostManifest(value.manifest);if (!manifestResult.ok || manifestResult.manifest.id !== expectedId) {return {ok: false,diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.tsindex 254ba2e023..0e05b2f279 100644--- a/apps/desktop/src/shared/__tests__/ghost.test.ts+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts@@ -32,6 +32,7 @@ import {resolveGhostManifestLocale,validateGhostManifest,validateGhostManifestLocaleResource,+ validateNormalizedGhostManifest,withGhostResolvedLocale,type GhostManifest,} from '../ghost';@@ -2496,6 +2497,26 @@ describe('ghost · setup 就绪声明校验(使用前置检查,2026-07-21)', ()});});+ it('Host 标准化清单可重复校验,但作者入口仍拒绝内部 setup 格式', () => {+ const parsed = validateGhostManifest({+ ...setupBase(),+ setup: {+ requires: [+ { anyOf: ['secret:api_key_a'] },+ { anyOf: ['connection:inst_conn', { kv: 'default_repo', label: '默认仓库' }] },+ ],+ },+ });+ expect(parsed.ok).toBe(true);+ if (!parsed.ok) return;++ expect(validateGhostManifest(parsed.manifest).ok).toBe(false);+ const repeated = validateNormalizedGhostManifest(parsed.manifest);+ expect(repeated.ok).toBe(true);+ if (!repeated.ok) return;+ expect(repeated.manifest).toEqual(parsed.manifest);+ });+it('不声明 setup 时清单不带该字段(缺省走宿主启发式)', () => {const result = validateGhostManifest(setupBase());expect(result.ok).toBe(true);diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex 1ab8f311a8..7ee880c1db 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -5312,6 +5312,49 @@ export function validateGhostManifest(raw: unknown): ManifestValidation {};}+/**+ * 校验 Host 已归一化的 GhostManifest 快照(例如批准 receipt 中的 manifest)。+ *+ * ghost.json 的作者格式与运行期格式只在 setup 条目上不同:作者写字符串引用或+ * `{ kv, label }`,Host 归一化后统一保存 `{ kind, key, label? }`。这里仅把已归一化+ * setup 还原为作者格式,再复用同一套完整清单校验;原始 ghost.json 仍必须走+ * validateGhostManifest,因此作者直接写内部格式仍会被拒绝。+ */+export function validateNormalizedGhostManifest(raw: unknown): ManifestValidation {+ if (!isPlainObject(raw) || raw.setup === undefined) return validateGhostManifest(raw);+ if (!isPlainObject(raw.setup) || !Array.isArray(raw.setup.requires)) {+ return { ok: false, reason: '标准化清单 setup 必须是带 requires 数组的对象' };+ }++ const requires: Array<{ anyOf: Array<string | { kv: unknown; label: unknown }> }> = [];+ for (const group of raw.setup.requires) {+ if (!isPlainObject(group) || !Array.isArray(group.anyOf)) {+ return { ok: false, reason: '标准化清单 setup.requires 每组必须是带 anyOf 数组的对象' };+ }+ const anyOf: Array<string | { kv: unknown; label: unknown }> = [];+ for (const requirement of group.anyOf) {+ if (!isPlainObject(requirement)) {+ return { ok: false, reason: '标准化清单 setup 条目必须是 { kind, key } 对象' };+ }+ if (requirement.kind === 'secret' || requirement.kind === 'connection') {+ if (typeof requirement.key !== 'string') {+ return { ok: false, reason: '标准化清单 setup 条目的 key 必须是字符串' };+ }+ anyOf.push(`${requirement.kind}:${requirement.key}`);+ continue;+ }+ if (requirement.kind === 'kv') {+ anyOf.push({ kv: requirement.key, label: requirement.label });+ continue;+ }+ return { ok: false, reason: '标准化清单 setup 条目的 kind 不受支持' };+ }+ requires.push({ anyOf });+ }++ return validateGhostManifest({ ...raw, setup: { requires } });+}+/*** ── 管子(脑机接口)消息协议(docs/dev-rules/plugin-security-and-authoring.md)──*