Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(cindy-brain): 本地装的 mivo-canvas 也能用组织登录态拿身份票 (#3456)
Praiseff1a36190731
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.tsindex 5df12ada24..85422a1996 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts@@ -191,6 +191,261 @@ describe('installed Plugin Connection audience resolver', () => {}});+ it('resolves a named local mivo-canvas install without a market record', () => {+ const localManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ network: {+ hosts: ['mivo-canvas.dsworks.cn'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['mivo-canvas.dsworks.cn'],+ },+ },+ ],+ },+ };+ const resolver = loadConnectionAudienceResolver({+ ...resolverOptions(localManifest, null),+ readInstallOrigin: () => 'manual',+ });+ expect(resolver.resolve('mivo-canvas', identity)).toEqual({+ membershipId: 'membership-1',+ audience: 'org-example:mivo-canvas',+ pluginSlug: 'mivo-canvas',+ allowedHosts: ['mivo-canvas.dsworks.cn'],+ });+ expect(+ loadConnectionAudienceResolver({+ ...resolverOptions(localManifest, null),+ readMarketInstallation: () => ({ kind: 'absent' }),+ readInstallOrigin: () => 'manual',+ }).resolve('mivo-canvas', identity),+ ).toEqual({+ membershipId: 'membership-1',+ audience: 'org-example:mivo-canvas',+ pluginSlug: 'mivo-canvas',+ allowedHosts: ['mivo-canvas.dsworks.cn'],+ });+ });++ it('does not extend the local mivo-canvas exception past an exact id and org membership', () => {+ const localManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ network: {+ hosts: ['mivo-canvas.dsworks.cn'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['mivo-canvas.dsworks.cn'],+ },+ },+ ],+ },+ };+ const resolver = loadConnectionAudienceResolver({+ ...resolverOptions(localManifest, null),+ readInstallOrigin: () => 'manual',+ });+ expect(resolver.resolve('plugin-a', identity)).toBeNull();+ expect(resolver.resolve('mivo-canvas-x', identity)).toBeNull();+ expect(resolver.resolve('Mivo-Canvas', identity)).toBeNull();+ expect(+ resolver.resolve('mivo-canvas', {+ membershipId: 'membership-1',+ membershipKind: 'personal',+ orgId: null,+ orgSlug: null,+ }),+ ).toBeNull();+ });++ it('rejects a local mivo-canvas install whose exact oidc host is not the allowlisted host', () => {+ const forgedManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ network: {+ hosts: ['attacker.example.com'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['attacker.example.com'],+ },+ },+ ],+ },+ };+ const resolver = loadConnectionAudienceResolver({+ ...resolverOptions(forgedManifest, null),+ readInstallOrigin: () => 'manual',+ });+ expect(resolver.resolve('mivo-canvas', identity)).toBeNull();+ });++ it('rejects a local mivo-canvas install that declares an extra exact oidc host', () => {+ const extraHostManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ network: {+ hosts: ['mivo-canvas.dsworks.cn', 'attacker.example.com'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['mivo-canvas.dsworks.cn', 'attacker.example.com'],+ },+ },+ ],+ },+ };+ const resolver = loadConnectionAudienceResolver({+ ...resolverOptions(extraHostManifest, null),+ readInstallOrigin: () => 'manual',+ });+ expect(resolver.resolve('mivo-canvas', identity)).toBeNull();+ });++ it('rejects a local mivo-canvas install whose oidc host is only a wildcard', () => {+ const wildcardManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ network: {+ hosts: ['*.x.test'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['*.x.test'],+ },+ },+ ],+ },+ };+ const resolver = loadConnectionAudienceResolver({+ ...resolverOptions(wildcardManifest, null),+ readInstallOrigin: () => 'manual',+ });+ expect(resolver.resolve('mivo-canvas', identity)).toBeNull();+ });++ it('still requires digest match when mivo-canvas has an organization market record', () => {+ const localManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ version: '2.0.0',+ network: {+ hosts: ['mivo-canvas.dsworks.cn'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['mivo-canvas.dsworks.cn'],+ },+ },+ ],+ },+ };+ const marketRecord: PluginMarketInstallationRecord = {+ ...marketInstallation,+ ghostId: 'mivo-canvas',+ manifestDigest: ghostManifestDigest({ ...localManifest, version: '1.0.0' }),+ };+ const resolver = loadConnectionAudienceResolver(+ resolverOptions(localManifest, marketRecord),+ );+ expect(resolver.resolve('mivo-canvas', identity)).toBeNull();+ });++ it('does not take the local exception when the market ledger is invalid', () => {+ const localManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ network: {+ hosts: ['mivo-canvas.dsworks.cn'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['mivo-canvas.dsworks.cn'],+ },+ },+ ],+ },+ };+ const resolver = loadConnectionAudienceResolver({+ ...resolverOptions(localManifest, null),+ readMarketInstallation: () => ({ kind: 'invalid' }),+ readInstallOrigin: () => 'manual',+ });+ expect(resolver.resolve('mivo-canvas', identity)).toBeNull();+ });++ it('does not skip digest when a mivo-canvas market record is marked uninstalled', () => {+ const localManifest: GhostManifest = {+ ...manifest,+ id: 'mivo-canvas',+ version: '2.0.0',+ network: {+ hosts: ['mivo-canvas.dsworks.cn'],+ secrets: [+ {+ key: 'cindy_identity',+ label: 'Cindy organization identity',+ source: 'oidc-token' as const,+ inject: {+ header: 'Authorization',+ format: 'Bearer {value}',+ hosts: ['mivo-canvas.dsworks.cn'],+ },+ },+ ],+ },+ };+ const marketRecord: PluginMarketInstallationRecord = {+ ...marketInstallation,+ ghostId: 'mivo-canvas',+ installed: false,+ manifestDigest: ghostManifestDigest({ ...localManifest, version: '1.0.0' }),+ };+ const resolver = loadConnectionAudienceResolver(+ resolverOptions(localManifest, marketRecord),+ );+ expect(resolver.resolve('mivo-canvas', identity)).toBeNull();+ });+it('requires the managed secret target to match a declared exact host', () => {const resolver = loadConnectionAudienceResolver({...resolverOptions(),diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.connection.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.connection.test.tsindex f00003fe1d..8fce157cce 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.connection.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.connection.test.ts@@ -19,7 +19,9 @@ describe('FORGE_GUIDE · Cindy Connection 凭证章节', () => {'POST / PUT / PATCH / DELETE','显式调用 `ghost_forge_install` 安装','要求用户手输相同 id',- '手动导入不签发',+ '个人身份与手动导入默认不签发',+ '仅 `ghostId` 精确等于 `mivo-canvas` 且精确 oidc-token host 仅为 `mivo-canvas.dsworks.cn` 的组织成员本地安装可解析 audience',+ '市场账本损坏、schema 不认或该 ghostId 记录校验失败时 fail-closed',]) {expect(FORGE_GUIDE).toContain(marker);}diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.tsindex 4b593fc84b..5f6630d136 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts@@ -1508,6 +1508,9 @@ describe('FORGE_GUIDE', () => {expect(FORGE_GUIDE).toContain('不要因为 scaffold 或 pack 成功就自动调用本工具');expect(FORGE_GUIDE).toContain('同版本也可覆盖');expect(FORGE_GUIDE).toContain('个人身份下的 Forge 安装和手动导入都不会取得这项资格');+ expect(FORGE_GUIDE).toContain(+ '仅 `ghostId` 精确等于 `mivo-canvas` 且精确 oidc-token host 仅为 `mivo-canvas.dsworks.cn` 的组织成员本地安装可解析 audience',+ );});it('开场白要求读完沙箱红线与打包测试两章', () => {diff --git a/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts b/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.tsindex 26551afc4a..7f5f860d00 100644--- a/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts+++ b/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts@@ -1,7 +1,13 @@/*** Host-owned Connection audience resolution. Explicit Forge installs for the* current organization and intact organization-market installs are the two- * dynamic bases. The Host derives the audience from current identity + plugin id.+ * dynamic bases. A named local-install exception exists only for ghostId+ * `mivo-canvas`: organization members may resolve after the org gate when the+ * installed manifest's exact oidc-token host is only `mivo-canvas.dsworks.cn`.+ * An intact organization market record, including installed:false, still takes+ * the digest path and must not skip via this exception. A present but invalid+ * market ledger is a hard failure, not an absent record. The Host derives the+ * audience from current identity + plugin id.*/import { isValidGhostId, isValidGhostNetworkHostPattern } from '../../shared/ghost.js';import type { GhostManifest } from '../../shared/ghost.js';@@ -32,6 +38,10 @@ export interface ConnectionAudienceResolver {const ORG_SLUG_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;const PLUGIN_SLUG_RE = /^[a-z][a-z0-9-]{0,31}$/;+/** Named local-install Connection exception. Must stay an exact id, not a prefix. */+const LOCAL_OIDC_ALLOWLIST_GHOST_ID = 'mivo-canvas';+/** Local exception may inject the org JWT only to this exact BFF host. */+const LOCAL_OIDC_ALLOWLIST_HOST = 'mivo-canvas.dsworks.cn';/*** Host-owned Connection audiences that plugins must never mint.@@ -67,10 +77,17 @@ export function declaredOidcTokenHosts(manifest: GhostManifest): string[] {];}+export type MarketInstallationLookup =+ | { kind: 'absent' }+ | { kind: 'found'; record: PluginMarketInstallationRecord }+ | { kind: 'invalid' };+export interface LoadConnectionAudienceResolverOptions {readInstalledManifest(ghostId: string): GhostManifest | null;readInstalledManifestDigest(ghostId: string): string | null;- readMarketInstallation(ghostId: string): PluginMarketInstallationRecord | null;+ readMarketInstallation(+ ghostId: string,+ ): PluginMarketInstallationRecord | MarketInstallationLookup | null;readApprovedPackageSha256?(ghostId: string): string | null;readInstallOrigin?(ghostId: string): 'manual' | 'agent-forge';lookupOrganizationPrefix?(@@ -153,13 +170,40 @@ export function loadConnectionAudienceResolver(let installation: PluginMarketInstallationRecord | null = null;try {- installation = options.readMarketInstallation(ghostId);+ const lookup = options.readMarketInstallation(ghostId);+ if (+ lookup &&+ typeof lookup === 'object' &&+ 'kind' in lookup &&+ (lookup.kind === 'absent' || lookup.kind === 'found' || lookup.kind === 'invalid')+ ) {+ if (lookup.kind === 'invalid') return reject('market-installation-invalid');+ if (lookup.kind === 'found') installation = lookup.record;+ } else {+ installation = lookup;+ }} catch {return reject('market-installation-read-failed');}- if (!installation || !installation.installed) {+ if (!installation) {+ // Named exception after the org gate and before market-missing reject.+ // Any persisted market row, including installed:false, still takes digest.+ if (ghostId === LOCAL_OIDC_ALLOWLIST_GHOST_ID) {+ const allowlisted = readManifest();+ if (!allowlisted) return reject('plugin-not-installed');+ if (allowlisted.id !== ghostId) return reject('plugin-id-mismatch');+ const allowlistedHosts = declaredOidcTokenHosts(allowlisted);+ if (+ allowlistedHosts.length !== 1 ||+ allowlistedHosts[0] !== LOCAL_OIDC_ALLOWLIST_HOST+ ) {+ return reject('oidc-host-not-allowlisted');+ }+ return finish(allowlisted);+ }return reject('market-installation-missing');}+ if (!installation.installed) return reject('market-installation-missing');if (installation.source !== 'market') return reject('market-installation-untrusted');if (installation.scope !== 'organization') {return reject('market-installation-not-organization');diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.tsindex 161bab3542..e4a7253b8b 100644--- a/apps/desktop/src/main/cindy-brain/forge.ts+++ b/apps/desktop/src/main/cindy-brain/forge.ts@@ -2981,7 +2981,9 @@ Auth 的企业服务。主机只在当前登录账号属于组织 Membership,保有本次包的完整 sha256。两路都要求清单声明目标服务域名。audience 与组织身份由主机推导,插件清单和运行时代码都不能选择、读取或保存audience/token;audience 固定为 \`\${orgSlug}:\${ghostId}\`,总长不得超过 64 字符。-个人身份与手动导入不签发;企业身份的 Forge 安装前会展示插件名、id 与精确域名,并要求手输相同 id+个人身份与手动导入默认不签发。点名例外:\`ghostId\` 精确等于 \`mivo-canvas\` 的组织成员本地安装,+在已装清单声明的精确 oidc-token host 仅为 \`mivo-canvas.dsworks.cn\` 时可解析 audience;其它本地插件、其它精确 host 仍不签发。已有市场+organization 记录(含 installed:false)时必须仍走 digest,不得借例外跳过。市场账本损坏、schema 不认或该 ghostId 记录校验失败时 fail-closed,不得当成无记录。企业身份的 Forge 安装前会展示插件名、id 与精确域名,并要求手输相同 id确认。市场与 Forge 两条组织基座都只给 Broker 与 oidc-token、不给宿主原语。该凭证必须固定声明\`"inject": { "header": "Authorization", "format": "Bearer {value}", "hosts": [...] }\`,@@ -4382,7 +4384,8 @@ const opened = await cindy.iosSimulator.request({数据与面板位置,同版本也可覆盖。不要因为 scaffold 或 pack 成功就自动调用本工具。企业身份下若清单声明 \`source:"oidc-token"\`,提交安装前会展示插件名、id 与精确请求域名,并要求用户手输相同 id;取消不会安装。只有确认后的企业作者自测才会取得 Forge- 作者资格并可签发 Connection JWT;个人身份下的 Forge 安装和手动导入都不会取得这项资格;+ 作者资格并可签发 Connection JWT;个人身份下的 Forge 安装和手动导入都不会取得这项资格。+ 本地安装另有一条点名例外,见 §4.7:仅 \`ghostId\` 精确等于 \`mivo-canvas\` 且精确 oidc-token host 仅为 \`mivo-canvas.dsworks.cn\` 的组织成员本地安装可解析 audience;4. 安装后再让用户 \`$<command> <内容>\` 试一单,看聊天图卡/面板是否符合预期。企业组织成员需要发布时,调用 \`ghost_forge_pack({ dir: '<绝对路径>', intent: 'publish' })\`。diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex 210b914669..bb3bdc05db 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -2577,7 +2577,8 @@ function getConnectionAudienceResolver(): ConnectionAudienceResolver {.list().find((candidate) => candidate.manifest.id === ghostId)?.manifest ?? null,readInstalledManifestDigest: readInstalledGhostManifestDigest,- readMarketInstallation: (ghostId) => getPluginMarketLedger().installationForGhost(ghostId),+ readMarketInstallation: (ghostId) =>+ getPluginMarketLedger().lookupInstallationForOidc(ghostId),readApprovedPackageSha256: (ghostId) =>getGhostManager().approvedInstallEvidence(ghostId)?.packageSha256 ?? null,readInstallOrigin: (ghostId) => getGhostManager().readEffectiveInstallOrigin(ghostId),diff --git a/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts b/apps/desktop/src/main/plugin-market/__tests__/ledger.test.tsindex 1e8fae35b5..2e2604bc37 100644--- a/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/ledger.test.ts@@ -50,6 +50,11 @@ describe('PluginMarketLedger', () => {installed: true,source: 'market',});+ expect(ledger.lookupInstallationForOidc('cindy-test')).toMatchObject({+ kind: 'found',+ record: { ghostId: 'cindy-test', installed: true },+ });+ expect(ledger.lookupInstallationForOidc('missing')).toEqual({ kind: 'absent' });expect(fs.existsSync(filePath)).toBe(true);expect(fs.readdirSync(path.dirname(filePath)).filter((name) => name.endsWith('.tmp')),@@ -127,6 +132,7 @@ describe('PluginMarketLedger', () => {installations: {},defaultInstallOptOuts: {},});+ expect(ledger.lookupInstallationForOidc('cindy-test')).toEqual({ kind: 'invalid' });});it('filters a schema-v1 installation record with required fields missing', () => {@@ -149,6 +155,46 @@ describe('PluginMarketLedger', () => {);expect(ledger.installationForGhost('cindy-test')).toBeNull();+ expect(ledger.lookupInstallationForOidc('cindy-test')).toEqual({ kind: 'invalid' });+ });++ it('treats malformed ledger JSON as invalid for OIDC lookup', () => {+ const { filePath, ledger } = harness();+ fs.mkdirSync(path.dirname(filePath), { recursive: true });+ fs.writeFileSync(filePath, '{not-json');++ expect(ledger.installationForGhost('cindy-test')).toBeNull();+ expect(ledger.lookupInstallationForOidc('cindy-test')).toEqual({ kind: 'invalid' });+ });++ it('treats a missing or non-object installations field as invalid for OIDC lookup', () => {+ const { filePath, ledger } = harness();+ fs.mkdirSync(path.dirname(filePath), { recursive: true });+ fs.writeFileSync(filePath, JSON.stringify({ schemaVersion: 1, installations: null }));++ expect(ledger.installationForGhost('cindy-test')).toBeNull();+ expect(ledger.lookupInstallationForOidc('cindy-test')).toEqual({ kind: 'invalid' });+ });++ it('treats a mistyped ghostId key as invalid for OIDC lookup', () => {+ const { filePath, ledger } = harness();+ fs.mkdirSync(path.dirname(filePath), { recursive: true });+ fs.writeFileSync(+ filePath,+ JSON.stringify({+ schemaVersion: 1,+ installations: {+ other: {+ ...record(),+ ghostId: 'mivo-canvas',+ },+ },+ defaultInstallOptOuts: {},+ }),+ );++ expect(ledger.installationForGhost('mivo-canvas')).toBeNull();+ expect(ledger.lookupInstallationForOidc('mivo-canvas')).toEqual({ kind: 'invalid' });});it('resolves the owner-scoped path for every operation', () => {diff --git a/apps/desktop/src/main/plugin-market/ledger.ts b/apps/desktop/src/main/plugin-market/ledger.tsindex 790072c07f..9997da8b82 100644--- a/apps/desktop/src/main/plugin-market/ledger.ts+++ b/apps/desktop/src/main/plugin-market/ledger.ts@@ -119,33 +119,61 @@ function validRecord(value: unknown): value is PluginMarketInstallationRecord {);}+type InstallationsFileRead = {+ kind: 'absent' | 'ok' | 'invalid';+ installations: Record<string, PluginMarketInstallationRecord>;+ raw: Record<string, unknown> | null;+};+/** 读取并解析一个账本 JSON 文件的 installations 段;文件不存在返回空。 */-function readInstallationsFile(- filePath: string,-): { installations: Record<string, PluginMarketInstallationRecord>; raw: Record<string, unknown> | null } {+function readInstallationsFile(filePath: string): InstallationsFileRead {// 读失败与解析失败分开处理:文件不存在(ENOENT)才是空;文件在但读不到(文件锁/// 权限/瞬时 I/O)或备份救不回来时由 readAtomicFileSync **上抛**——降级成空会让// 紧接着的写入把真实记录覆盖掉。只有"内容确实不是合法 JSON"才按空重建。const text = readAtomicFileSync(filePath);- if (text === null) return { installations: {}, raw: null };+ if (text === null) return { kind: 'absent', installations: {}, raw: null };let parsed: unknown;try {parsed = JSON.parse(text);} catch {- return { installations: {}, raw: null };+ return { kind: 'invalid', installations: {}, raw: null };}if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {- return { installations: {}, raw: null };+ return { kind: 'invalid', installations: {}, raw: null };}const value = parsed as Record<string, unknown>;- if (value.schemaVersion !== LEDGER_SCHEMA_VERSION) return { installations: {}, raw: null };+ if (value.schemaVersion !== LEDGER_SCHEMA_VERSION) {+ return { kind: 'invalid', installations: {}, raw: null };+ }+ const rawInstallations = value.installations;+ if (+ rawInstallations === undefined ||+ rawInstallations === null ||+ typeof rawInstallations !== 'object' ||+ Array.isArray(rawInstallations)+ ) {+ return { kind: 'invalid', installations: {}, raw: value };+ }const installations: Record<string, PluginMarketInstallationRecord> = {};- if (value.installations && typeof value.installations === 'object') {- for (const [ghostId, record] of Object.entries(value.installations)) {- if (validRecord(record) && record.ghostId === ghostId) installations[ghostId] = record;- }+ for (const [ghostId, record] of Object.entries(rawInstallations)) {+ if (validRecord(record) && record.ghostId === ghostId) installations[ghostId] = record;}- return { installations, raw: value };+ return { kind: 'ok', installations, raw: value };+}++function rawMentionsGhost(file: InstallationsFileRead, ghostId: string): boolean {+ const installations = file.raw?.installations;+ if (!installations || typeof installations !== 'object' || Array.isArray(installations)) {+ return false;+ }+ if (Object.prototype.hasOwnProperty.call(installations, ghostId)) return true;+ return Object.values(installations).some(+ (record) =>+ record &&+ typeof record === 'object' &&+ !Array.isArray(record) &&+ (record as { ghostId?: unknown }).ghostId === ghostId,+ );}/**@@ -188,10 +216,17 @@ export class PluginMarketLedger {return path.join(path.dirname(this.filePath()), CUSTOM_LEDGER_FILE);}- read(): PluginMarketLedgerData {- const main = readInstallationsFile(this.filePath());- const custom = readInstallationsFile(this.customFilePath());+ private readFiles(): { main: InstallationsFileRead; custom: InstallationsFileRead } {+ return {+ main: readInstallationsFile(this.filePath()),+ custom: readInstallationsFile(this.customFilePath()),+ };+ }+ private mergeInstallations(+ main: InstallationsFileRead,+ custom: InstallationsFileRead,+ ): PluginMarketLedgerData {const installations: Record<string, PluginMarketInstallationRecord> = {};for (const [ghostId, record] of Object.entries(main.installations)) {// 主账本里的自定义记录是早期开发版写入的存量,一并纳入(下次写入时归位)。@@ -222,10 +257,33 @@ export class PluginMarketLedger {return { schemaVersion: LEDGER_SCHEMA_VERSION, installations, defaultInstallOptOuts };}+ read(): PluginMarketLedgerData {+ const { main, custom } = this.readFiles();+ return this.mergeInstallations(main, custom);+ }+installationForGhost(ghostId: string): PluginMarketInstallationRecord | null {return this.read().installations[ghostId] ?? null;}+ /**+ * Connection OIDC lookup. Missing files are absent; a present but unreadable+ * or schema-invalid ledger is a hard failure so callers cannot treat+ * corruption as "no market record".+ */+ lookupInstallationForOidc(+ ghostId: string,+ ): { kind: 'absent' } | { kind: 'found'; record: PluginMarketInstallationRecord } | { kind: 'invalid' } {+ const { main, custom } = this.readFiles();+ if (main.kind === 'invalid' || custom.kind === 'invalid') return { kind: 'invalid' };+ const record = this.mergeInstallations(main, custom).installations[ghostId];+ if (record) return { kind: 'found', record };+ if (rawMentionsGhost(main, ghostId) || rawMentionsGhost(custom, ghostId)) {+ return { kind: 'invalid' };+ }+ return { kind: 'absent' };+ }+upsertInstallation(record: PluginMarketInstallationRecord): void {const data = this.read();data.installations[record.ghostId] = record;diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex 2cf92ef995..a0628b9001 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -867,7 +867,9 @@ export const GHOST_OAUTH_BOUNCE_PATH_RE = /^\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)* 只在 networkSlot 请求 GitHub API 时注入,不进入插件、Renderer、KV 或日志。* - 'oidc-token':值 = Cindy 为当前企业 Membership 签发的短时 Connection* JWT。当前组织的可信市场安装,或企业作者通过 ghost_forge_install 明确安装且- * id 命中本组织登记前缀时可签发;手动导入不取得该资格。+ * id 命中本组织登记前缀时可签发;手动导入默认不取得该资格。点名例外:+ * ghostId 精确等于 mivo-canvas 的组织成员本地安装,在已装清单声明的精确+ * oidc-token host 仅为 mivo-canvas.dsworks.cn 时可签发;其它本地插件、其它精确 host 仍不签发,已有市场记录(含 installed:false)仍走 digest。市场账本损坏不得当成无记录。* Host 根据当前组织和插件 id 推导 audience,插件不能声明或读取。* 令牌只在 networkSlot 发请求时注入,且永不进入 Node Worker。*diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.mdindex 7b7848214b..27655e793c 100644--- a/docs/dev-rules/plugin-security-and-authoring.md+++ b/docs/dev-rules/plugin-security-and-authoring.md@@ -229,10 +229,13 @@Worker。设置页只能读取 `hostAvailable` 布尔与备用 PAT 的 `saved/tail` 状态。该来源不允许 `exchange` 或 `setup.requires` 引用,第三方插件不得声明。- `source: "oidc-token"` 是 Host 托管的短时 Cindy Connection JWT:只对当前企业- Membership 生效。资格有两条:当前组织的 Plugin Market organization 安装记录仍有效、+ Membership 生效。资格有两条默认基座:当前组织的 Plugin Market organization 安装记录仍有效、且安装目录 manifest digest 与记录一致;或企业作者显式使用 `ghost_forge_install`安装、在提交前核对插件 id 与精确注入域名,且插件 id 命中当前组织前缀。手动导入不取得- Forge 作者资格。Host 根据当前组织和插件 id 推导 audience。+ Forge 作者资格。另有一条点名例外:`ghostId` 精确等于 `mivo-canvas` 的组织成员本地安装,+ 在已装 manifest 声明的精确 `oidc-token` host 仅为 `mivo-canvas.dsworks.cn` 时可解析 audience;其它本地插件、个人账号、+ 通配 host、其它精确 host 仍不签发。若该插件已有市场 organization 记录(含 `installed:false` 的卸载残留),不得走白名单捷径,必须仍走+ digest 校验。市场账本损坏、schema 不认或该 ghostId 记录校验失败时 fail-closed,不得当成「无记录」走例外。Host 根据当前组织和插件 id 推导 audience。插件和 Node Worker 都不能读取或保存令牌。声明必须固定使用`Authorization: Bearer {value}` 并显式列出非空 `inject.hosts`;其中只允许精确域名,不允许通配。实际目标必须精确命中这份可信 manifest 声明的服务域名才会签发和注入。它没有用户输入、`url`、`exchange` 或