Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 冷启动同步默认插件 (#1563)
GaoWei Liucfd47de355b1
diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.tsindex 0772c20a22..e773504d5c 100644--- a/apps/desktop/src/main/bootstrap-electron.ts+++ b/apps/desktop/src/main/bootstrap-electron.ts@@ -656,7 +656,10 @@ import { listActiveClaudeBackgroundActivitySessions } from './maker-host/claude-import { registerRelaunchBusyActivityIpc } from './relaunchBusyActivityIpc.js';import { getGhostSetupChangeBus } from './cindy-brain/ghostSetupChangeBus.js';import { getGhostSetupInteractionBridge } from './cindy-brain/ghostSetupInteractionBridge.js';-import { registerPluginMarketIpc } from './plugin-market/registerIpc.js';+import {+ registerPluginMarketIpc,+ syncDefaultMarketPlugins,+} from './plugin-market/registerIpc.js';import { findCindyFileInArgv } from './cindy-brain/argv.js';import { handleIncomingCindyFile } from './cindy-brain/openFileInstall.js';import { registerCindyFileAssociation } from './cindy-brain/fileAssociation.js';@@ -2574,6 +2577,20 @@ const createWindow = () => {let disposeSkillhubAutoSyncAuthListener: (() => void) | null = null;let disposeProviderAccessAuthListener: (() => void) | null = null;+let disposePluginMarketAuthListener: (() => void) | null = null;+let defaultPluginSyncInFlightScope: string | null = null;++/** Run the existing market reconciliation once for each stable app owner. */+function syncDefaultPluginsForActiveOwner(): void {+ const session = getActiveAppSession();+ if (!session.dataOwnerId || isAppSessionBoundaryPending()) return;+ const scope = activeOwnerScopeKey();+ if (scope === defaultPluginSyncInFlightScope) return;+ defaultPluginSyncInFlightScope = scope;+ void syncDefaultMarketPlugins().finally(() => {+ if (defaultPluginSyncInFlightScope === scope) defaultPluginSyncInFlightScope = null;+ });+}const registerIpcHandlers = () => {// Find the primary app window, skipping transient utility BrowserWindows like@@ -4572,6 +4589,13 @@ const registerIpcHandlers = () => {disposeProviderAccessAuthListener = authManager.onAuthStateChange(() => {refreshProviderAccessAfterAuthChange();});+ // 默认插件同步不能依赖用户先打开插件页。启动时本地 owner 已经稳定则立刻+ // 复用市场快照;云端登录/切号的通知可能早于 owner boundary 释放,因此+ // 延迟到当前调用栈结束后再按已提交的新 owner 补跑一次。+ disposePluginMarketAuthListener = authManager.onAuthStateChange(() => {+ queueMicrotask(syncDefaultPluginsForActiveOwner);+ });+ syncDefaultPluginsForActiveOwner();// ── Dialog: 目录选择器(v0.6 新增,与旧 show-open-directory-dialog 并存) ──ipcMain.handle(@@ -6361,6 +6385,14 @@ onQuit(},'sync',);+onQuit(+ 'plugin-market-auth-listener',+ () => {+ disposePluginMarketAuthListener?.();+ disposePluginMarketAuthListener = null;+ },+ 'sync',+);// Async 阶段: 并发跑, 6s 超时兜底。// - shutdown-maker: Layer 1 关 sessions → Layer 2 dispose agents (Codexdiff --git a/apps/desktop/src/main/plugin-market/__tests__/ipcErrorBoundary.test.ts b/apps/desktop/src/main/plugin-market/__tests__/ipcErrorBoundary.test.tsindex 1c2a7f8476..d1464c6e99 100644--- a/apps/desktop/src/main/plugin-market/__tests__/ipcErrorBoundary.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/ipcErrorBoundary.test.ts@@ -17,6 +17,10 @@ describe('Plugin Market IPC error boundary', () => {resolve(process.cwd(), 'src/main/plugin-market/service.ts'),'utf8',).replace(/\r\n/g, '\n');+ const bootstrapSource = readFileSync(+ resolve(process.cwd(), 'src/main/bootstrap-electron.ts'),+ 'utf8',+ ).replace(/\r\n/g, '\n');it('preserves structured errors and normalizes unexpected failures', () => {const start = registerSource.indexOf('async function invokePluginMarket');@@ -43,4 +47,38 @@ describe('Plugin Market IPC error boundary', () => {expect(serviceSource).toContain("throwIpcError('PRECONDITION_FAILED'");expect(serviceSource).toContain("throwIpcError('PERMISSION_DENIED'");});++ it('runs default plugin reconciliation on cold start and stable owner changes', () => {+ const syncStart = registerSource.indexOf(+ 'export async function syncDefaultMarketPlugins(): Promise<void>',+ );+ const syncEnd = registerSource.indexOf('\n}\n\n/**\n * Preserve stable IPC errors', syncStart);+ const syncBody = registerSource.slice(syncStart, syncEnd);+ expect(syncBody).toContain('await service().snapshot();');+ expect(syncBody).toContain("log.warn('default plugin startup sync failed'");++ const ownerSyncStart = bootstrapSource.indexOf(+ 'function syncDefaultPluginsForActiveOwner(): void',+ );+ const ownerSyncEnd = bootstrapSource.indexOf('\n}\n\nconst registerIpcHandlers', ownerSyncStart);+ const ownerSyncBody = bootstrapSource.slice(ownerSyncStart, ownerSyncEnd);+ expect(ownerSyncBody).toContain(+ 'if (!session.dataOwnerId || isAppSessionBoundaryPending()) return;',+ );+ expect(ownerSyncBody).toContain('if (scope === defaultPluginSyncInFlightScope) return;');+ expect(ownerSyncBody).toContain('void syncDefaultMarketPlugins().finally(() => {');+ expect(ownerSyncBody).toContain('defaultPluginSyncInFlightScope = null;');++ const listenerStart = bootstrapSource.indexOf(+ 'disposePluginMarketAuthListener = authManager.onAuthStateChange',+ );+ expect(listenerStart).toBeGreaterThan(-1);+ expect(+ bootstrapSource.indexOf(+ 'queueMicrotask(syncDefaultPluginsForActiveOwner);',+ listenerStart,+ ),+ ).toBeGreaterThan(listenerStart);+ expect(bootstrapSource).toContain("'plugin-market-auth-listener'");+ });});diff --git a/apps/desktop/src/main/plugin-market/registerIpc.ts b/apps/desktop/src/main/plugin-market/registerIpc.tsindex fe041fb6d0..2e4b4b5903 100644--- a/apps/desktop/src/main/plugin-market/registerIpc.ts+++ b/apps/desktop/src/main/plugin-market/registerIpc.ts@@ -20,6 +20,21 @@ function service(): PluginMarketService {return serviceSingleton;}+/**+ * Reuse the market snapshot reconciliation outside the Plugins page so+ * default-install plugins are provisioned as soon as an app owner is ready.+ * The Plugins page keeps the same call as a later retry path.+ */+export async function syncDefaultMarketPlugins(): Promise<void> {+ try {+ await service().snapshot();+ } catch (error) {+ log.warn('default plugin startup sync failed', {+ error: error instanceof Error ? error.message : String(error),+ });+ }+}+/*** Preserve stable IPC errors and hide internal/network messages from the* renderer. Detailed failures stay in main logs; the renderer localizes by