Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): preserve capability resolver across account switches
zqchris361bc2fdab92
diff --git a/apps/desktop/src/main/maker-host/__tests__/dynamicMaker.test.ts b/apps/desktop/src/main/maker-host/__tests__/dynamicMaker.test.tsindex 46c407654b..e507a605bf 100644--- a/apps/desktop/src/main/maker-host/__tests__/dynamicMaker.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/dynamicMaker.test.ts@@ -2,6 +2,8 @@ import { describe, expect, it, vi } from 'vitest';import type { Maker } from '@cindy/maker-core';import { createDynamicMaker } from '../dynamic-maker.js';+import { createBotModelRouteReconciler } from '../../maker-ipc/botModelRouteReconciler.js';+import type { BotModelRoute } from '../../../shared/botModelChain.js';describe('createDynamicMaker', () => {it('routes an already captured method to the current Maker instance', () => {@@ -28,4 +30,59 @@ describe('createDynamicMaker', () => {current = second;expect((facade.makerMemory as unknown as { owner: string }).owner).toBe('second');});++ it('keeps a capability resolver usable across account replacement without retaining route bookkeeping', async () => {+ const chain: BotModelRoute[] = [+ { harness: 'claude', model: 'primary', providerId: null, effort: '', fastMode: false },+ ];+ const first = { getSessionMeta: vi.fn(async () => ({ agentKind: 'claude-code' as const, model: 'primary' })) };+ const second = { getSessionMeta: vi.fn(async () => ({ agentKind: 'pi' as const, model: 'fallback' })) };+ let current: typeof first | typeof second = first;+ let owner = 'first';+ let boundaryPending = false;+ const facade = createDynamicMaker(() => {+ if (boundaryPending) throw new Error('Account boundary pending');+ return current as unknown as Maker;+ });+ const apply = vi.fn();+ const reconciler = createBotModelRouteReconciler({+ ownerEpoch: () => owner,+ read: async (sessionId) => {+ const meta = await facade.getSessionMeta(sessionId);+ if (!meta) return null;+ return {+ chain,+ current: { agentKind: meta.agentKind, model: meta.model, providerId: null, effort: null, fastMode: false },+ hasRuntimeOverride: true,+ };+ },+ apply,+ });+ // IPC installs this callback once; subsequent calls use the replacement Maker.+ const resolve = async () => (await reconciler.preview('canonical'))?.agentKind ?? null;+ await reconciler('canonical');+ expect(await resolve()).toBe('claude-code');+ chain[0] = { ...chain[0]!, harness: 'codex' };+ expect(await resolve()).toBe('codex');++ first.getSessionMeta.mockImplementationOnce(async () => {+ owner = 'second';+ boundaryPending = true;+ return { agentKind: 'claude-code', model: 'primary' };+ });+ await expect(resolve()).rejects.toThrow('owner changed');+ await expect(resolve()).rejects.toThrow('Account boundary pending');+ const firstOwnerReads = first.getSessionMeta.mock.calls.length;++ current = second;+ boundaryPending = false;+ // A reused ID with another owner's fallback must not inherit the first+ // owner's configured-chain history and override that fallback with Codex.+ expect(await resolve()).toBe('pi');+ await reconciler('canonical');+ expect(await resolve()).toBe('pi');+ expect(first.getSessionMeta).toHaveBeenCalledTimes(firstOwnerReads);+ expect(second.getSessionMeta).toHaveBeenCalledTimes(3);+ expect(apply).not.toHaveBeenCalled();+ });});diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.tsindex c305f825b2..363fd7bd33 100644--- a/apps/desktop/src/main/maker-host/index.ts+++ b/apps/desktop/src/main/maker-host/index.ts@@ -521,7 +521,9 @@ export function setBeforeLocalCodexSessionStartHook(hook: (() => Promise<void>)_beforeLocalCodexSessionStartHook = hook;}-// The IPC composition root owns route reconciliation; MCP factories bind before it is ready.+// Process-lifetime IPC binding: its reconciler reads the dynamic Maker facade and+// clears owner-scoped bookkeeping by epoch. Keep it across resetMaker; IPC is not+// registered again after an account switch. MCP factories bind before it is ready.let _resolveBotCapabilityAgentKind: BotCapabilityServiceDeps['resolveBotAgentKind'] | null = null;export function setBotCapabilityAgentKindResolver(resolver: BotCapabilityServiceDeps['resolveBotAgentKind'] | null,@@ -2708,7 +2710,6 @@ export function resetMaker(): void {_registerPiAgent = null;_codexAgent = null;_mcpProviders = {};- _resolveBotCapabilityAgentKind = null;// coordinator 闭包捕获了刚作废的那个 maker —— 不清掉的话,换账号窗口期内到达的 auth// 事件会拿旧实例去拉模型清单(串号)。下次 getMaker() 会带着干净记账重建它。_codexModelBackfill = null;