Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): keep model catalog reads snapshot-only
Dasheda26ca9824b
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex 462672f9cb..dcc0cf0477 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -6651,7 +6651,7 @@ export function registerGhostIpc(): void {if (!findAvailableGhost(ghostId)?.enabled) {return { ok: false, errorCode: 'NOT_AVAILABLE', message: 'Plugin unavailable' };}- const views = await getDesktopProviderService({ allowSideEffects: false }).listProviders({ allowSideEffects: false });+ const views = await getDesktopProviderService({ allowSideEffects: false }).listProviders({ allowSideEffects: false, snapshotOnly: true });if (owner !== activeOwnerScopeKey() || !findAvailableGhost(ghostId)?.enabled) {return { ok: false, errorCode: 'NOT_AVAILABLE', message: 'Plugin unavailable' };}diff --git a/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts b/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.tsindex 94a5c8e49e..821e72dd77 100644--- a/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts@@ -28,6 +28,8 @@ const h = vi.hoisted(() => ({loadAnthropicDiskCache: vi.fn(async () => {}),codexLoginWithSideEffects: vi.fn(async () => false),codexLoginReadOnly: vi.fn(() => false),+ readClaudeStatus: vi.fn(),+ readNativeLogin: vi.fn(),}));vi.mock('electron', () => ({@@ -55,13 +57,18 @@ vi.mock('../claude-native-auth.js', () => ({hasClaudeNativeLogin: () => h.claudeCredentialPresent && isBoundToCurrentOwner('anthropic'),}));vi.mock('../claude-native-connection.js', () => ({- readClaudeNativeLogin: async () =>- h.claudeCredentialPresent && isBoundToCurrentOwner('anthropic')+ readClaudeNativeLogin: async () => {+ h.readNativeLogin();+ return h.claudeCredentialPresent && isBoundToCurrentOwner('anthropic')? { loggedIn: true, email: '[email protected]' }- : null,+ : null;+ },}));vi.mock('../claude-native-cli.js', () => ({- readClaudeCliLoginStatus: async () => ({ loggedIn: h.claudeCredentialPresent }),+ readClaudeCliLoginStatus: async () => {+ h.readClaudeStatus();+ return { loggedIn: h.claudeCredentialPresent };+ },}));vi.mock('../grok-oauth-login.js', () => ({grokAccountIdentity: () => '[email protected]',@@ -172,6 +179,8 @@ beforeEach(() => {h.loadAnthropicDiskCache.mockClear();h.codexLoginWithSideEffects.mockClear();h.codexLoginReadOnly.mockClear();+ h.readClaudeStatus.mockClear();+ h.readNativeLogin.mockClear();});afterEach(() => {@@ -179,6 +188,22 @@ afterEach(() => {});describe('native provider connection claim on read', () => {+ it('snapshot reads never probe CLI or account identity, while normal reads still refresh', async () => {+ const service = getDesktopProviderService({ allowSideEffects: false });+ for (const present of [false, true]) {+ h.claudeCredentialPresent = present;+ bindNativeProviderAuth('anthropic', { sharedSystem: true });+ const views = await service.listProviders({ allowSideEffects: false, snapshotOnly: true });+ expect(views.find(p => p.id === 'anthropic')?.connected).toBe(present);+ expect(views.find(p => p.id === 'anthropic')?.subscriptionAccount).toBeUndefined();+ }+ expect(h.readClaudeStatus).not.toHaveBeenCalled();+ expect(h.readNativeLogin).not.toHaveBeenCalled();+ expect(h.codexLoginWithSideEffects).not.toHaveBeenCalled();+ await service.listProviders({ allowSideEffects: false });+ expect(h.readClaudeStatus).toHaveBeenCalledTimes(1);+ expect(h.readNativeLogin).toHaveBeenCalledTimes(1);+ });it('read-only service acquisition skips legacy migration even for eligible cloud owners', async () => {h.legacyCloudOwner = true;await listProviders(false);diff --git a/apps/desktop/src/main/maker-host/__tests__/providerService.test.ts b/apps/desktop/src/main/maker-host/__tests__/providerService.test.tsindex b6798127ec..63d96ab105 100644--- a/apps/desktop/src/main/maker-host/__tests__/providerService.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/providerService.test.ts@@ -3,12 +3,30 @@ import { describe, it, expect, vi } from 'vitest';import { BUNDLED_CATALOG, buildUserProvider, connectedProvidersForAgent, providerMediaField } from '@cindy/model-providers';import { checkModelRoute } from '../model-route-guard.js';-import { createProviderService } from '../provider-service.js';+import { createProviderService, type ConnectionReadOptions } from '../provider-service.js';/** 注入内置 bundled 目录作为「当前生效目录」(桌面端真实注入的是 active-catalog 的 getActiveCatalog)。 */const bundledCatalog = () => BUNDLED_CATALOG;describe('createProviderService', () => {+ it('snapshot mode suppresses side effects and skips both account presentation readers', async () => {+ const read = vi.fn((_options: ConnectionReadOptions) => true);+ const account = vi.fn(async () => ({ source: 'unknown' as const }));+ const svc = createProviderService({+ getCatalog: bundledCatalog,+ connection: { xd: read, anthropic: read, openai: read, xai: read },+ openAiAccountInfo: account,+ subscriptionAccountInfo: account,+ });+ await svc.listProviders({ allowSideEffects: true, snapshotOnly: true });+ expect(read).toHaveBeenCalledTimes(4);+ for (const [options] of read.mock.calls) {+ expect(options).toMatchObject({ allowSideEffects: false, snapshotOnly: true });+ }+ expect(account).not.toHaveBeenCalled();+ await svc.listProviders();+ expect(account).toHaveBeenCalled();+ });it('uses managed provider configuration names instead of stale presentation overrides', async () => {const provider = buildUserProvider({id: 'cindy-local-ollama', name: 'Ollama', auth: { method: 'none' },diff --git a/apps/desktop/src/main/maker-host/createDesktopProviderService.ts b/apps/desktop/src/main/maker-host/createDesktopProviderService.tsindex 98f731e583..829484183a 100644--- a/apps/desktop/src/main/maker-host/createDesktopProviderService.ts+++ b/apps/desktop/src/main/maker-host/createDesktopProviderService.ts@@ -997,7 +997,8 @@ export function getDesktopProviderService(options: { allowSideEffects?: booleanxd: () => getAppCapabilities().canUseCindyGateway && readClaudeApiKey() != null,// Claude/Codex 是原生 Harness,可继承本机 CLI 凭证;xAI 是下游 provider,// 只能读取已经由 Cindy OAuth 明确绑定的 token,禁止在连接态读取时自动认领。- anthropic: async ({ allowSideEffects, waitForDiscovery }) => {+ anthropic: async ({ allowSideEffects, waitForDiscovery, snapshotOnly }) => {+ if (snapshotOnly) return hasClaudeNativeLogin();// 自愈会写绑定文件、读凭证作用域缓存并发起带凭证的上游请求。listProviders 这条通道// 同时服务 device-link 与可能不受信的渲染上下文,所以副作用只在本机主页面发起时// 才放行,其余降级为纯读(PR #548 review)。diff --git a/apps/desktop/src/main/maker-host/provider-service.ts b/apps/desktop/src/main/maker-host/provider-service.tsindex a9f2508a33..c6a61f487d 100644--- a/apps/desktop/src/main/maker-host/provider-service.ts+++ b/apps/desktop/src/main/maker-host/provider-service.ts@@ -38,6 +38,8 @@ const log = createLogger('provider-service');*/export interface ConnectionReadOptions {allowSideEffects: boolean;+ /** Host-only snapshot read: never refresh CLI status or load account presentation. */+ snapshotOnly?: boolean;/*** Wait for post-claim model discovery before materializing this snapshot.* This is an internal readiness hint for routing callers; ordinary provider reads@@ -140,7 +142,8 @@ export interface ProviderService {export function createProviderService(deps: ProviderServiceDeps): ProviderService {async function listProviders(opts?: Partial<ProviderListOptions>): Promise<ProviderView[]> {const readOpts: ConnectionReadOptions = {- allowSideEffects: opts?.allowSideEffects === true,+ allowSideEffects: opts?.allowSideEffects === true && opts?.snapshotOnly !== true,+ snapshotOnly: opts?.snapshotOnly === true,waitForDiscovery: opts?.waitForDiscovery === true,};const [xd, anthropic, openai, xai] = await Promise.all([@@ -196,13 +199,13 @@ export function createProviderService(deps: ProviderServiceDeps): ProviderServic);}const accountInfo = new Map<string, ProviderView['openAiAccount']>();- if (deps.openAiAccountInfo) {+ if (!readOpts.snapshotOnly && deps.openAiAccountInfo) {await Promise.all(catalog.providers.filter((p) => p.id === 'openai' || p.auth.native === 'codex').map(async (p) => {accountInfo.set(p.id, await deps.openAiAccountInfo!(p.id));}));}const subscriptionInfo = new Map<string, ProviderView['subscriptionAccount']>();- if (deps.subscriptionAccountInfo) await Promise.all(catalog.providers+ if (!readOpts.snapshotOnly && deps.subscriptionAccountInfo) await Promise.all(catalog.providers.filter(p => p.id === 'anthropic' || p.id === 'xai' || p.auth.native === 'claude' || p.auth.native === 'xai').map(async p => subscriptionInfo.set(p.id, await deps.subscriptionAccountInfo!(p.id))));return buildRegistry(catalog, connected, discoveryFailures, deps.getModelAccess?.()).map((provider) => ({