Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 会话换引擎一律确认,收藏按独立 uid 选中 (#3093)
Chris Zhang75a543758b2d
diff --git a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.tsindex df5052cec2..bc46de1676 100644--- a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts+++ b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts@@ -159,6 +159,15 @@ describe('ChatInput model source switching wiring', () => {* 档位集合,而意图期的回调(performAgentSwitch(intent.target, …))按目标能力校验,* 用户点的档位被静默回落。*/+ it('passes unresolved runtime identity through instead of falling back to the intent target', () => {+ const start = chatInputSource.indexOf('const sessionEngineFilter = useMemo(');+ expect(start).toBeGreaterThan(-1);+ const block = chatInputSource.slice(start, chatInputSource.indexOf('}, [', start));+ expect(block).toContain('runtimeAgent: runtimeAgentKind ?? undefined');+ expect(block).not.toContain('runtimeAgentKind ?? currentAgent');+ expect(block).not.toContain('runtimeAgentKind ?? vendorKeyToAgentKind');+ });+it('prefers the pending switch intent target as the unified panel session agent', () => {expect(chatInputSource).toContain('const intentTargetAgent = agentSwitchIntent?.target ?? null;',@@ -188,9 +197,9 @@ describe('ChatInput model source switching wiring', () => {expect(block).toContain('wireModelId: modelId,');expect(block).toContain('engine: agentKindToVendor(targetAgent),');expect(block).toContain('providerId,');- // 派生校验必须比对来源:仅来源被切走(wire id / 引擎不变)时锚点失效- // (2026-08-17 review:跨窗口 / 外部 patch 切来源后不得继续勾旧来源的收藏)。- expect(chatInputSource).toContain(+ // 勾选只认 uid(Chris 2026-08-20):不拿正在跑的来源去对副本。+ expect(chatInputSource).toContain('sessionFavoriteAnchor?.uid ?? null');+ expect(chatInputSource).not.toContain('sessionFavoriteAnchor.providerId === activeProviderId &&',);});diff --git a/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts b/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.tsindex 94927f3ab9..ea22ab3263 100644--- a/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts+++ b/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts@@ -1749,24 +1749,15 @@ describe('New Maker 草稿的 wire model id 口径', () => {expect(handler).not.toContain('rowModelId');});- it('收藏锚点按 wire id 判失效,不拿收藏条目的归一化 id 去比', () => {- // 收藏条目按**归一化行 id** 存(那是行的稳定身份),草稿里放的是 wire id ——- // 直接比 favorite.modelId 与 draftInitialModel,像 chatgpt/gpt-5.6-luna 这类两者本就- // 不相等的模型会每次都判成失配,刚点上的收藏立刻掉勾。- //- // **有意变更**(Chris 2026-08-19):锚点从组件态改成按引擎分槽持久化- // (favoriteAnchorMemory),变量名随之从 selectedFavoriteAnchor 变成 draftFavoriteAnchor,- // 「vendor 也要对得上」那一维由槽键承担(读的永远是当前引擎那一格)。**比的仍然是- // wire id**,这条锁不变。- expect(newMakerDraftRouteSource).toContain(+ it('草稿收藏选中只认 uid,不拿草稿当前模型/来源去对快照', () => {+ // 收藏是独立选中项(Chris 2026-08-20):勾选身份就是 uid。拿 wire/来源去对,点了收藏+ // 之后草稿被 coerce / seed 改走就会掉勾,焦点落到下面同名模型行。+ expect(newMakerDraftRouteSource).toContain('draftFavoriteAnchor?.uid ?? null');+ expect(newMakerDraftRouteSource).not.toContain('draftFavoriteAnchor.wireModelId === draftInitialModel',);- // 来源也是锚点身份(2026-08-19 review P1):同 wire model 跨来源不得误恢复。- expect(newMakerDraftRouteSource).toContain(- 'draftFavoriteAnchor.providerId === chatInitialProviderId',- );expect(newMakerDraftRouteSource).not.toContain('favorite.modelId !== draftInitialModel');- // 快照在选中那一刻记下本次写进草稿的 (wire id, 来源)。+ // 快照仍记下选中那一刻的 (wire id, 来源),建会话延续用,不参与勾选判定。expect(newMakerDraftRouteSource).toContain('wireModelId: selection.modelId,');expect(newMakerDraftRouteSource).toContain('providerId: selection.providerId,');});diff --git a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.tsindex cf2d1ef218..7757d9fcff 100644--- a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts+++ b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts@@ -1122,10 +1122,10 @@ describe('ChatInput 的入口门控与调用路由', () => {const start = source.indexOf('const sessionEngineFilter = useMemo(');expect(start).toBeGreaterThan(-1);const body = source.slice(start, source.indexOf('}, [', start));- // 取消确认 = false(现状,不变)。**有意变更**(Chris 2026-08-19):确认门现在收目标- // 引擎 —— 「已确认过就不再问」的判据是「已有指向**该目标**的意图」,不传目标会让确认框- // 在任何残留意图之后永久静默(见 agentSwitchConfirmation.hasSwitchIntent)。+ // 取消确认 = false(现状,不变)。**有意变更**(Chris 2026-08-20):确认只认任务真实引擎,+ // 挂着的意图不算已经确认过 —— Claude 任务点了 Pi 收藏再点另一条,仍要弹框。expect(body).toContain('if (!(await confirmAgentBrowseSwitch(targetAgent))) return false;');+ expect(body).toContain('runtimeAgent: runtimeAgentKind ?? undefined,');// 真实结果原样交出去;绝不再出现 fire-and-forget + 提前 true。expect(body).toContain('const applied = await performAgentSwitchRef.current(');expect(body).toContain('return applied;');@@ -1173,10 +1173,9 @@ describe('ChatInput 的入口门控与调用路由', () => {});/**- * Chris 2026-08-19 实测「面板原地刷新一下」的根因锁:切换事务一开始就把 disabled 拉高- * (agentSwitchInFlight),`(open || keepOpen) && !disabled` 会连保命锁一起压掉 —— 面板当场- * 收合,收尾时 setOpenWithoutAutoRefresh(true) 又把它弹回来。保命锁的意义就是「这段时间- * 别关」,disabled 不该有权否决它;in-flight 期间由 interactionDisabled 置灰即可。+ * Chris 2026-08-19「面板原地刷新」+ 2026-08-20「改思维闪关菜单」:+ * disabled 不得参与 popover 开关。`(open && !disabled) || keepOpen` 只保住确认框那条路,+ * 改思维走 performAgentSwitch 时 keepOpen 是 false,选单照关。*/it('ModelSelector 的保命锁不被 disabled 压穿(两个 popover 分支同一表达式)', () => {const selectorSource = readFileSync(@@ -1184,13 +1183,61 @@ describe('ChatInput 的入口门控与调用路由', () => {'utf8',).replace(/\r\n/g, '\n');const matches =- selectorSource.match(/open=\{\(open && !disabled\) \|\| keepOpenForAgentConfirmation\}/g) ??- [];+ selectorSource.match(/open=\{open \|\| keepOpenForAgentConfirmation\}/g) ?? [];expect(matches).toHaveLength(2);expect(selectorSource).not.toContain('(open || keepOpenForAgentConfirmation) && !disabled');+ expect(selectorSource).not.toContain('(open && !disabled) || keepOpenForAgentConfirmation');+ // 切引擎成功也不收选单:applied=true 曾经会 setOpen(false),一点胶囊窗口就没了。+ expect(selectorSource).toContain('setOpenWithoutAutoRefresh(true);');+ expect(selectorSource).not.toContain('setOpenWithoutAutoRefresh(applied === false)');+ });++ it('换引擎确认只认任务真实引擎,不认挂着的意图', () => {+ expect(source).toContain(+ 'runtimeAgentKind != null && runtimeAgentKind === targetAgent',+ );+ expect(source).not.toContain(+ 'makerChatStore.getAgentSwitchIntent(sessionId)?.target === targetAgent',+ );+ });++ it('会话收藏锚点只认 uid,不拿正在跑的模型/引擎去对副本', () => {+ expect(source).toContain('sessionFavoriteAnchor?.uid ?? null');+ expect(source).not.toContain('sessionFavoriteAnchor.wireModelId === activeModel');+ });++ it('跨引擎选中拿任务真实引擎比,不拿意图目标', () => {+ const actions = readFileSync(+ resolve(process.cwd(), 'src/renderer/components/new-chat/useUnifiedRowActions.ts'),+ 'utf8',+ );+ expect(actions).toContain('const runtimeAgent = sessionEngineFilter?.runtimeAgent;');+ expect(actions).not.toContain(+ 'const runtimeAgent = sessionEngineFilter?.runtimeAgent ?? sessionAgent;',+ );+ expect(actions).toContain('if (runtimeAgent === undefined) return true;');+ expect(actions).toContain('shouldCrossEngine(config.agent)');+ expect(actions).toContain('pendingSwitch');+ expect(actions).toContain('favoriteCopyIsLive');+ expect(actions).not.toContain('config.agent !== sessionAgent');+ });++ it('打开选单只滚动选中行,不把焦点从搜索框抢走', () => {+ const panel = readFileSync(+ resolve(process.cwd(), 'src/renderer/components/new-chat/UnifiedModelPanel.tsx'),+ 'utf8',+ );+ const ensure = panel.slice(+ panel.indexOf('const ensureSelectedVisible = useCallback'),+ panel.indexOf('}, [pickerLayout]);'),+ );+ expect(ensure).not.toContain('row.focus');+ expect(ensure).toContain('computeSelectedRowScrollTop');});});++describe('CCAgentSessionView 上下文环压缩入口按 agent 能力分流(#1927)', () => {const viewSource = readFileSync(resolve(process.cwd(), 'src/renderer/features/cc-agent/CCAgentSessionView.tsx'),diff --git a/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx b/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsxindex 5ccacc3675..edb82550ff 100644--- a/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx+++ b/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx@@ -337,7 +337,11 @@ describe('统一模型选择器面板', () => {describe('统一面板 · 会话内形态', () => {const onCrossEngineSelect = vi.fn();- const sessionEngineFilter = { currentAgent: 'codex' as const, onCrossEngineSelect };+ const sessionEngineFilter = {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ };beforeEach(() => {onCrossEngineSelect.mockClear();@@ -364,7 +368,11 @@ describe('统一面板 · 会话内形态', () => {*/it('同引擎视图不显示「候选含当前引擎、但落点在别家」的行', () => {renderPanel({- sessionEngineFilter: { currentAgent: 'claude-code' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'claude-code' as const,+ onCrossEngineSelect,+ },currentProviderId: 'anthropic',modelId: 'claude-opus-5',});@@ -496,6 +504,166 @@ describe('统一面板 · 会话内形态', () => {expect(onProviderChange).toHaveBeenCalledWith('xd', 'gpt-5.5', 'high');});+ it('挂着待切换意图时点回真实引擎行:走 onCrossEngineSelect 清意图,不走普通 onSelect', async () => {+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'pi',+ runtimeAgent: 'claude-code',+ onCrossEngineSelect,+ },+ vendorKey: 'cc',+ currentProviderId: 'anthropic',+ modelId: 'claude-opus-5',+ });+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: '全部' }));+ });+ await act(async () => {+ fireEvent.click(rowFor('Opus 5'));+ });+ expect(onProviderChange).not.toHaveBeenCalled();+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'anthropic',+ targetAgent: 'claude-code',+ }),+ );+ });++ it('真实引擎未知且挂着意图:点意图目标行仍走确认事务,不走普通 onSelect', async () => {+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ onCrossEngineSelect,+ },+ vendorKey: 'cc',+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ });+ await act(async () => {+ fireEvent.click(rowFor('GPT-5.5'));+ });+ expect(onProviderChange).not.toHaveBeenCalled();+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ targetAgent: 'codex',+ }),+ );+ });++ it('真实引擎未知且挂着意图:点另一引擎的模型行同样走确认事务', async () => {+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ onCrossEngineSelect,+ },+ vendorKey: 'cc',+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ });+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: '全部' }));+ });+ await act(async () => {+ fireEvent.click(rowFor('Opus 5'));+ });+ expect(onProviderChange).not.toHaveBeenCalled();+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'anthropic',+ targetAgent: 'claude-code',+ }),+ );+ });++ it('真实引擎未知且挂着意图:点意图目标收藏仍走确认事务', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'high',+ });+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ onCrossEngineSelect,+ },+ vendorKey: 'cc',+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ effort: 'high',+ });+ const favoriteRow = within(screen.getAllByRole('group')[0])+ .getByText('GPT-5.5')+ .closest('[data-unified-anchor]') as HTMLElement;+ await act(async () => {+ fireEvent.click(favoriteRow);+ });+ expect(onProviderChange).not.toHaveBeenCalled();+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'xd',+ targetAgent: 'codex',+ favoriteUid: uid,+ }),+ );+ });++ it('真实引擎未知且挂着意图:点引擎胶囊仍走切换事务,不直接 return', async () => {+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ onCrossEngineSelect,+ },+ vendorKey: 'cc',+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ });+ await act(async () => {+ fireEvent.pointerEnter(rowFor('GPT-5.5'));+ });+ const flyout = await screen.findByTestId('unified-model-config-flyout');+ await act(async () => {+ fireEvent.click(flyout.querySelector('[data-engine-capsule="cc"]') as HTMLElement);+ });+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'xd',+ targetAgent: 'claude-code',+ favoriteUid: null,+ }),+ );+ });++ it('挂着待切换意图时点回真实引擎胶囊:仍走切换事务,不直接 return', async () => {+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'codex',+ runtimeAgent: 'claude-code',+ onCrossEngineSelect,+ },+ vendorKey: 'cc',+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ });+ await act(async () => {+ fireEvent.pointerEnter(rowFor('GPT-5.5'));+ });+ const flyout = await screen.findByTestId('unified-model-config-flyout');+ await act(async () => {+ fireEvent.click(flyout.querySelector('[data-engine-capsule="cc"]') as HTMLElement);+ });+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'xd',+ targetAgent: 'claude-code',+ favoriteUid: null,+ }),+ );+ });+/*** 引擎口径分裂 = 跨引擎**待切换意图期**(2026-08-17 review):ChatInput 在意图登记后把* `currentAgent` 换成意图目标,而 vendorKey(→ liveAgentKind)仍是旧引擎。面板的@@ -576,7 +744,11 @@ describe('统一面板 · 恢复推荐应用到 live 配置', () => {const onEffortChange = vi.fn();const onFastModeChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -599,7 +771,11 @@ describe('统一面板 · 恢复推荐应用到 live 配置', () => {setModelEngineOverride('xd', 'gpt-5.5', 'cc');const onCrossEngineSelect = vi.fn(() => true);renderPanel({- sessionEngineFilter: { currentAgent: 'claude-code' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'claude-code' as const,+ onCrossEngineSelect,+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -630,7 +806,11 @@ describe('统一面板 · 恢复推荐应用到 live 配置', () => {const onCrossEngineSelect = vi.fn(() => false);const onFastModeChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'claude-code' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'claude-code' as const,+ onCrossEngineSelect,+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -708,7 +888,6 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {modelId: 'gpt-5.5',agent: 'cc',effort: 'low',- fast: true,});const onUnifiedSelect = vi.fn();renderPanel({@@ -717,10 +896,10 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {currentProviderId: 'xd',modelId: 'gpt-5.5',vendorKey: 'cc',- // 选中的收藏 = 草稿正在跑它的副本:live 深度/Fast 必须与副本一致,否则锚点按- // 「副本 ≠ live」回落(2026-08-19 review P2 的完整配置校验)。+ // 选中的收藏 = 草稿正在跑它的副本:live 深度/Fast 必须与**解析后的副本**一致。+ // cc 那条没有 Fast 能力,副本 Fast 恒为关 —— 不能拿收藏条目里的 fast:true 去对。effort: 'low',- fastMode: true,+ fastMode: false,});await act(async () => {fireEvent.click(favoriteStar());@@ -738,6 +917,182 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {expect(listModelFavorites()).toHaveLength(0);});+ it('选中收藏后 live 配置已改:删收藏只删记录,不把后来的选择覆盖成旧收藏默认', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'high',+ fast: true,+ });+ const onUnifiedSelect = vi.fn();+ const onEffortChange = vi.fn();+ const onFastModeChange = vi.fn();+ renderPanel({+ onUnifiedSelect,+ onEffortChange,+ onFastModeChange,+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ // 正在跑的是 Claude + low,和这条 Codex 收藏对不上。+ vendorKey: 'cc',+ effort: 'low',+ });+ await act(async () => {+ fireEvent.click(favoriteStar());+ });+ expect(listModelFavorites()).toHaveLength(0);+ expect(onUnifiedSelect).not.toHaveBeenCalled();+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onFastModeChange).not.toHaveBeenCalled();+ });++ it('选中收藏后只改了思维档:删收藏只删记录,不覆盖当前思维', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'low',+ });+ const onUnifiedSelect = vi.fn();+ const onEffortChange = vi.fn();+ const onFastModeChange = vi.fn();+ renderPanel({+ onUnifiedSelect,+ onEffortChange,+ onFastModeChange,+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ vendorKey: 'codex',+ // composer / 其它入口把思维改到 high,uid 还在。+ effort: 'high',+ });+ await act(async () => {+ fireEvent.click(favoriteStar());+ });+ expect(listModelFavorites()).toHaveLength(0);+ expect(onUnifiedSelect).not.toHaveBeenCalled();+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onFastModeChange).not.toHaveBeenCalled();+ });++ it('选中收藏后只改了 Fast:删收藏只删记录,不覆盖当前 Fast', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'low',+ });+ const onUnifiedSelect = vi.fn();+ const onEffortChange = vi.fn();+ const onFastModeChange = vi.fn();+ renderPanel({+ onUnifiedSelect,+ onEffortChange,+ onFastModeChange,+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ vendorKey: 'codex',+ effort: 'low',+ fastMode: true,+ });+ await act(async () => {+ fireEvent.click(favoriteStar());+ });+ expect(listModelFavorites()).toHaveLength(0);+ expect(onUnifiedSelect).not.toHaveBeenCalled();+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onFastModeChange).not.toHaveBeenCalled();+ });++ it('挂着待切换意图时删除回落到真实引擎的收藏:走切换事务清意图', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'cc',+ effort: 'medium',+ });+ const onCrossEngineSelect = vi.fn(() => true);+ const onEffortChange = vi.fn();+ const onFastModeChange = vi.fn();+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ vendorKey: 'codex',+ effort: 'medium',+ onEffortChange,+ onFastModeChange,+ });+ await act(async () => {+ fireEvent.click(favoriteStar());+ });+ // 默认回落 gpt 家族主场 Codex = 正在跑的引擎,但面板正挂着切到 Claude 的意图:+ // 必须走 same-engine 切换事务清意图,不能只复位深度 / Fast。+ expect(onCrossEngineSelect).toHaveBeenCalledWith({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ targetAgent: 'codex',+ effort: 'high',+ fast: false,+ favoriteUid: null,+ });+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onFastModeChange).not.toHaveBeenCalled();+ await waitFor(() => {+ expect(listModelFavorites()).toHaveLength(0);+ });+ });++ it('真实引擎未知时删除选中收藏:走切换事务,不走同引擎 live 回落', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'low',+ fast: true,+ });+ const onCrossEngineSelect = vi.fn(() => true);+ const onEffortChange = vi.fn();+ const onFastModeChange = vi.fn();+ renderPanel({+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ onCrossEngineSelect,+ },+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ effort: 'low',+ fastMode: true,+ onEffortChange,+ onFastModeChange,+ });+ await act(async () => {+ fireEvent.click(favoriteStar());+ });+ expect(onCrossEngineSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'xd',+ targetAgent: 'codex',+ favoriteUid: null,+ }),+ );+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onFastModeChange).not.toHaveBeenCalled();+ await waitFor(() => {+ expect(listModelFavorites()).toHaveLength(0);+ });+ });+it('会话内同引擎:深度 / Fast 经实时回调复位,记录同时删除', async () => {const uid = addModelFavorite({providerId: 'xd',@@ -750,7 +1105,11 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {const onEffortChange = vi.fn();const onFastModeChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -773,7 +1132,11 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {const uid = addModelFavorite({ providerId: 'xd', modelId: 'gpt-5.5', agent: 'cc' });const onCrossEngineSelect = vi.fn(() => true);renderPanel({- sessionEngineFilter: { currentAgent: 'claude-code' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'claude-code' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -804,7 +1167,11 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {const onEffortChange = vi.fn();const onFastModeChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'claude-code' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'claude-code' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -913,7 +1280,11 @@ describe('统一面板 · 同引擎实时写入成功才清存储', () => {});const onEffortChange = vi.fn(() => false);renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1090,7 +1461,11 @@ describe('统一面板 · 改模型行的实时配置后收藏不再选中', ()const onFastModeChange = vi.fn();const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1119,7 +1494,11 @@ describe('统一面板 · 改模型行的实时配置后收藏不再选中', ()});const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1145,7 +1524,11 @@ describe('统一面板 · 改模型行的实时配置后收藏不再选中', ()});const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1197,7 +1580,11 @@ describe('统一面板 · 会话内选中收藏要真正应用', () => {const onFastModeChange = vi.fn();const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -1235,7 +1622,11 @@ describe('统一面板 · 会话内选中收藏要真正应用', () => {const onEffortChange = vi.fn();const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -1256,7 +1647,11 @@ describe('统一面板 · 会话内选中收藏要真正应用', () => {addModelFavorite({ providerId: 'openai', modelId: 'gpt-5.6', agent: 'codex' });const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -1275,7 +1670,11 @@ describe('统一面板 · 会话内选中收藏要真正应用', () => {const uid = addModelFavorite({ providerId: 'openai', modelId: 'gpt-5.6', agent: 'codex' });const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },currentProviderId: 'xd',modelId: 'gpt-5.5',effort: 'low',@@ -1341,6 +1740,100 @@ describe('统一面板 · 编辑选中的收藏同步到 live', () => {});});+ it('选中收藏已不是 live 配置:改深度只更新收藏记录,不写回正在跑的配置', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'low',+ });+ const onEffortChange = vi.fn();+ const onUnifiedSelect = vi.fn();+ renderPanel({+ onUnifiedSelect,+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ vendorKey: 'cc',+ effort: 'medium',+ onEffortChange,+ });+ const flyout = await openFavoriteFlyout();+ await act(async () => {+ fireEvent.keyDown(flyout.querySelector('[role="slider"]') as HTMLElement, {+ key: 'ArrowRight',+ });+ });+ await waitFor(() => {+ expect(listModelFavorites()[0]?.effort).toBe('high');+ });+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onUnifiedSelect).not.toHaveBeenCalled();+ });++ it('选中收藏后只改了思维档:编辑深度只更新收藏记录,不写回正在跑的配置', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'low',+ });+ const onEffortChange = vi.fn();+ const onUnifiedSelect = vi.fn();+ renderPanel({+ onUnifiedSelect,+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ vendorKey: 'codex',+ effort: 'high',+ onEffortChange,+ });+ const flyout = await openFavoriteFlyout();+ await act(async () => {+ fireEvent.keyDown(flyout.querySelector('[role="slider"]') as HTMLElement, {+ key: 'ArrowRight',+ });+ });+ await waitFor(() => {+ expect(listModelFavorites()[0]?.effort).toBe('high');+ });+ expect(onEffortChange).not.toHaveBeenCalled();+ expect(onUnifiedSelect).not.toHaveBeenCalled();+ });++ it('选中收藏后只改了 Fast:编辑 Fast 只更新收藏记录,不写回正在跑的配置', async () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'low',+ });+ const onFastModeChange = vi.fn();+ const onEffortChange = vi.fn();+ const onUnifiedSelect = vi.fn();+ renderPanel({+ onUnifiedSelect,+ selectedFavoriteUid: uid,+ currentProviderId: 'xd',+ modelId: 'gpt-5.5',+ vendorKey: 'codex',+ effort: 'low',+ fastMode: true,+ onEffortChange,+ onFastModeChange,+ });+ const flyout = await openFavoriteFlyout();+ await act(async () => {+ fireEvent.click(flyout.querySelector('[data-fast-toggle]') as HTMLElement);+ });+ await waitFor(() => {+ expect(listModelFavorites()[0]?.fast).toBe(true);+ });+ expect(onFastModeChange).not.toHaveBeenCalled();+ expect(onUnifiedSelect).not.toHaveBeenCalled();+ });+it('草稿选中的收藏改 Fast:live 回调收到新值,收藏副本同步更新', async () => {const uid = addModelFavorite({ providerId: 'xd', modelId: 'gpt-5.5', agent: 'codex' });const onFastModeChange = vi.fn();@@ -1463,7 +1956,11 @@ describe('统一面板 · 编辑选中的收藏同步到 live', () => {});const onCrossEngineSelect = vi.fn(() => true);renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1500,7 +1997,11 @@ describe('统一面板 · 编辑选中的收藏同步到 live', () => {});const onCrossEngineSelect = vi.fn(() => false);renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1522,7 +2023,11 @@ describe('统一面板 · 编辑选中的收藏同步到 live', () => {// 选中的是 Opus 5,那条收藏不是当前锚点。renderPanel({onUnifiedSelect,- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },currentProviderId: 'anthropic',modelId: 'claude-opus-5',onEffortChange: vi.fn(),@@ -1687,7 +2192,11 @@ describe('统一面板 · 会话内回传收藏锚点', () => {});const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },currentProviderId: 'anthropic',modelId: 'claude-opus-5',onSessionFavoriteAnchorChange,@@ -1709,7 +2218,11 @@ describe('统一面板 · 会话内回传收藏锚点', () => {it('选中普通模型行 → 回传 null(把上一条锚点清掉)', async () => {const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect: vi.fn() },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect: vi.fn(),+ },currentProviderId: 'anthropic',modelId: 'claude-opus-5',onSessionFavoriteAnchorChange,@@ -1725,7 +2238,11 @@ describe('统一面板 · 会话内回传收藏锚点', () => {const onCrossEngineSelect = vi.fn(() => true);const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },currentProviderId: 'xd',modelId: 'gpt-5.5',onSessionFavoriteAnchorChange,@@ -1767,7 +2284,11 @@ describe('统一面板 · 会话内回传收藏锚点', () => {});const onCrossEngineSelect = vi.fn(() => true);renderPanel({- sessionEngineFilter: { currentAgent: 'claude-code' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'claude-code' as const,+ runtimeAgent: 'claude-code' as const,+ onCrossEngineSelect,+ },currentProviderId: 'anthropic',modelId: 'claude-opus-5',vendorKey: 'cc',@@ -1808,7 +2329,11 @@ describe('统一面板 · 会话内回传收藏锚点', () => {const onCrossEngineSelect = vi.fn(() => true);const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -1852,7 +2377,11 @@ describe('统一面板 · 会话内回传收藏锚点', () => {const onCrossEngineSelect = vi.fn(() => false);const onSessionFavoriteAnchorChange = vi.fn();renderPanel({- sessionEngineFilter: { currentAgent: 'codex' as const, onCrossEngineSelect },+ sessionEngineFilter: {+ currentAgent: 'codex' as const,+ runtimeAgent: 'codex' as const,+ onCrossEngineSelect,+ },selectedFavoriteUid: uid,currentProviderId: 'xd',modelId: 'gpt-5.5',@@ -2006,6 +2535,33 @@ describe('统一面板 · 新会话选中直通', () => {[...selected].every((el) => el.getAttribute('data-unified-anchor')?.startsWith('model::')),).toBe(true);});++ it('收藏是独立选中项:live 思维/引擎对不上副本,勾仍在收藏行,不落到下面同名模型', () => {+ const uid = addModelFavorite({+ providerId: 'xd',+ modelId: 'gpt-5.5',+ agent: 'codex',+ effort: 'high',+ });+ render(+ React.createElement(ModelSelectorContent, {+ modelId: 'gpt-5.5',+ vendorKey: 'cc',+ effort: 'low',+ onModelChange: vi.fn(),+ onEffortChange: vi.fn(),+ currentProviderId: 'xd',+ onProviderChange,+ unifiedPanel: true,+ selectedFavoriteUid: uid,+ }),+ );+ const selected = screen+ .getByRole('listbox')+ .querySelectorAll('[data-model-selected="true"]');+ expect(selected).toHaveLength(1);+ expect(selected[0].getAttribute('data-unified-anchor')).toBe(`fav::${uid}`);+ });});/**diff --git a/apps/desktop/src/renderer/__tests__/unifiedModelSelection.test.ts b/apps/desktop/src/renderer/__tests__/unifiedModelSelection.test.tsindex 04939df7dc..666c79119b 100644--- a/apps/desktop/src/renderer/__tests__/unifiedModelSelection.test.ts+++ b/apps/desktop/src/renderer/__tests__/unifiedModelSelection.test.ts@@ -24,7 +24,6 @@ import {computeFlyoutPlacement,computeSelectedRowScrollTop,isRecommendedFavoriteConfig,- resolveActiveFavoriteAnchorUid,resolveFavoriteRowConfig,resolveUnifiedRowConfig,} from '@/components/new-chat/unifiedModelSelection';@@ -242,163 +241,6 @@ describe('收藏 = 配置副本', () => {});});-describe('resolveActiveFavoriteAnchorUid(锚点的完整配置校验,2026-08-19 review P2)', () => {- const entry = entryOf({- capabilities: {- 'claude-code': capability('claude-code', { supportsFastMode: true }),- },- });- const base = {- favorites: [favoriteOf({ effort: 'high', fast: true })],- entries: [entry],- liveAgent: 'claude-code' as const,- agentFastModeCapable: () => true,- };-- it('副本解析结果与 live 完整配置逐维相等 → 锚点成立', () => {- expect(- resolveActiveFavoriteAnchorUid({- ...base,- selectedFavoriteUid: 'fav-1',- liveEffort: 'high',- liveFast: true,- }),- ).toBe('fav-1');- });-- it('外部只改深度(副本 high、live 已被改成 low)→ 锚点回落', () => {- // 身份三维(模型/来源/引擎)全对,此前只按身份校验会继续勾住旧副本 —— 面板抑制- // 真实模型行的勾,编辑/删除还按错误副本执行(review P2 的核心场景)。- expect(- resolveActiveFavoriteAnchorUid({- ...base,- selectedFavoriteUid: 'fav-1',- liveEffort: 'low',- liveFast: true,- }),- ).toBeNull();- });-- it('外部只改 Fast(副本开、live 已关)→ 锚点回落;反向(副本关、live 开)同样回落', () => {- expect(- resolveActiveFavoriteAnchorUid({- ...base,- selectedFavoriteUid: 'fav-1',- liveEffort: 'high',- liveFast: false,- }),- ).toBeNull();- expect(- resolveActiveFavoriteAnchorUid({- ...base,- favorites: [favoriteOf({ effort: 'high' })], // 副本 Fast 关- selectedFavoriteUid: 'fav-1',- liveEffort: 'high',- liveFast: true,- }),- ).toBeNull();- });-- it('引擎不等(副本引擎被另一窗口改走)→ 锚点回落', () => {- expect(- resolveActiveFavoriteAnchorUid({- ...base,- favorites: [favoriteOf({ agent: 'codex', effort: 'high', fast: true })],- entries: [- entryOf({- candidates: ['claude-code', 'codex'],- capabilities: {- 'claude-code': capability('claude-code', { supportsFastMode: true }),- codex: capability('codex', { supportsFastMode: true }),- },- }),- ],- selectedFavoriteUid: 'fav-1',- liveEffort: 'high',- liveFast: true,- }),- ).toBeNull();- });-- it('宽维放行:live 深度未知 / 副本不可调 / 引擎身份未加载时,对应维不参与判定', () => {- // live 深度为空(上游未就绪一帧)→ 深度维放行。- expect(- resolveActiveFavoriteAnchorUid({- ...base,- selectedFavoriteUid: 'fav-1',- liveEffort: null,- liveFast: true,- }),- ).toBe('fav-1');- // 副本解析出 null(不可调模型)→ 深度维放行。- expect(- resolveActiveFavoriteAnchorUid({- ...base,- favorites: [favoriteOf({ fast: true })],- entries: [- entryOf({- capabilities: {- 'claude-code': capability('claude-code', {- efforts: [],- defaultEffort: null,- supportsFastMode: true,- }),- },- }),- ],- selectedFavoriteUid: 'fav-1',- liveEffort: 'high',- liveFast: true,- }),- ).toBe('fav-1');- // 引擎身份未加载(liveAgent=null)→ 引擎维放行,深度/Fast 照常比。- expect(- resolveActiveFavoriteAnchorUid({- ...base,- selectedFavoriteUid: 'fav-1',- liveAgent: null,- liveEffort: 'high',- liveFast: true,- }),- ).toBe('fav-1');- });-- it('无 Fast 能力时 live Fast 不参与判定(副本与 live 同被门控为关)', () => {- // 能力不具备 → resolveFavoriteRowConfig 把副本 Fast 门控成 false,live 侧同规则:- // 比出来恒等,不因「记忆里残留 Fast」误杀。- expect(- resolveActiveFavoriteAnchorUid({- ...base,- favorites: [favoriteOf({ effort: 'high', fast: true })],- agentFastModeCapable: () => false,- selectedFavoriteUid: 'fav-1',- liveEffort: 'high',- liveFast: true,- }),- ).toBe('fav-1');- });-- it('既有兜底不回退:uid 查无此条 → null;收藏指向的行不可路由 → 维持锚点', () => {- expect(- resolveActiveFavoriteAnchorUid({- ...base,- selectedFavoriteUid: 'fav-gone',- liveEffort: 'high',- liveFast: true,- }),- ).toBeNull();- expect(- resolveActiveFavoriteAnchorUid({- ...base,- entries: [],- selectedFavoriteUid: 'fav-1',- liveEffort: 'low', // 配置对不上也不否决:行都没了,无从解析副本配置- liveFast: false,- }),- ).toBe('fav-1');- });-});-describe('buildUnifiedListSections', () => {const opus = entryOf({ group: 'anthropic', sortOrder: 1 });const gpt = entryOf({diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex f719902563..9075104909 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -6056,28 +6056,13 @@ export function ChatInput({const confirmAgentBrowseSwitch = useCallback((targetAgent: 'claude-code' | 'codex' | 'pi' | null) =>confirmAgentSwitchRisk({- // 两条「不必再问」的出口(任一成立即放行):- //- // 1. **同目标意图已存在** = 用户进入这个目标的浏览态时已经确认过;后续在同一目标里- // 改选模型 / 来源 / 深度 / Fast 都不重复弹。- // 判据必须带上目标(Chris 2026-08-19 实测):此前只判「有没有意图」,会话上挂着- // **任何**残留意图之后确认框就永久静默 —— 先切 Codex(意图挂上)再去选 Pi 的- // 模型,一声不吭就改道了另一个引擎,而那是一次全新的上下文重建风险。- //- // 2. **目标就是会话真实引擎** = 用户在撤销、要回家。这一路在 main 侧是 same-engine- // no-op(清掉 pending 意图 + 按普通 SET_MODEL 应用),不重建上下文、零风险,弹- // 「切换会重建上下文」纯属吓人。真源必须用 `runtimeAgentKind`(session / runtime- // 元数据确认的**事实**),**绝不能**用 vendorKey / composerEngineMarkVendor —— 那两个- // 在意图期会跟着意图翻到目标引擎,于是「回原引擎」反而被判成跨引擎、而「继续切到- // 意图目标」被判成同引擎,两边都反了。身份未加载(null)时不走这条出口,回落到- // 出口 1 或照常弹框。- //- // 目标解析不出来(理论上不会,防御历史 vendor 值)时按「没确认过」处理,宁可多问一次。+ // 只有「目标就是会话正在跑的真实引擎」才不必再问(回原引擎 = same-engine no-op,+ // 不重建上下文)。挂着的切换意图不算已经确认过(Chris 2026-08-20):Claude 任务里+ // 点了 Pi 收藏、意图挂上但还没发消息,再点另一条非当前引擎的模型/收藏,仍然要问。+ // 真源必须用 `runtimeAgentKind`,绝不能用 vendorKey / 意图目标 —— 那两个在意图期+ // 会翻到目标引擎,把「继续切到意图目标」错判成同引擎、把确认框跳过。hasSwitchIntent:- !!sessionId &&- !!targetAgent &&- (makerChatStore.getAgentSwitchIntent(sessionId)?.target === targetAgent ||- (runtimeAgentKind != null && runtimeAgentKind === targetAgent)),+ !!sessionId && !!targetAgent && runtimeAgentKind != null && runtimeAgentKind === targetAgent,confirm: confirmDialog,copy: {title: t('newChat.chatInput.agentSwitch.confirmation.title'),@@ -6419,6 +6404,10 @@ export function ChatInput({if (!currentAgent) return undefined;return {currentAgent,+ // 跨引擎确认 / 切换路由只认任务**正在跑**的引擎,不认挂着的意图目标。+ // 意图期 currentAgent 会翻到 Pi,若用它判断,点 Pi 收藏会被当成同引擎、不弹确认、+ // 还不带收藏里的思维(Chris 2026-08-20)。+ runtimeAgent: runtimeAgentKind ?? undefined,onCrossEngineSelect: async ({providerId,modelId,@@ -6487,6 +6476,7 @@ export function ChatInput({vendorKey,intentTargetAgent,remoteHostId,+ runtimeAgentKind,sessionAgentSwitchSupported,confirmAgentBrowseSwitch,// 锚点写入绑的是**这一份闭包里的** sessionId(见 setSessionFavoriteAnchor):它随会话@@ -6509,25 +6499,14 @@ export function ChatInput({* 下发给统一面板的收藏锚点:草稿用调用方(NewMakerDraftRoute)持有的那一份,会话用上面* 那份内存态。*- * 会话侧刻意做成**派生校验**而不是「配置一变就 setState 清掉」:同引擎选中一条收藏时,- * 模型的持久化是异步的(onProviderChange → IPC),清理式写法会在那个窗口里把刚记下的锚点- * 当场抹掉。派生写法在那一帧只是先不打勾,等 activeModel 收敛回来自然对上;而配置真被别的- * 路径改走(换模型 / 换引擎)之后,它永远对不上,等价于清除。判据与草稿侧同名兜底逐字同构:- * 比的是**快照里的 wire id** 与当前会话的 wire id(收藏条目按归一化行 id 存,两者天生可能不等)。- * 引擎身份未加载时(composerEngineMarkVendor 为 null)不参与判定,免得一帧未就绪就误判。- * 锚点指向的收藏被删 / 换账号后查无此条,由面板侧 activeFavoriteUid 兜底。+ * 收藏是**独立选中项**(Chris 2026-08-20):选中身份就是那条收藏的 uid,不拿正在跑的+ * 模型 / 引擎 / 思维去对副本 —— 对上才会勾,等于让下面的同名模型行把焦点抢走(点了+ * Pi 收藏、任务还停在 Claude 时必现)。uid 指向的收藏被删 / 换账号后查无此条,由面板+ * 侧 activeFavoriteUid 兜底。用户点普通模型行时 favoriteUid 显式置 null,那才是离开+ * 这条收藏。*/const effectiveSelectedFavoriteUid = sessionId- ? sessionFavoriteAnchor &&- sessionFavoriteAnchor.wireModelId === activeModel &&- // 来源同为锚点身份(2026-08-17 review):仅来源被切走(跨窗口 / 外部 patch,wire id- // 与引擎都没变)时锚点必须失效,否则面板继续勾旧来源的收藏。activeProviderId 为- // null = 会话跟随默认路由,与显式来源的锚点永不相等 —— 语义正确:锚点记录的是- // 一次显式来源选择。- sessionFavoriteAnchor.providerId === activeProviderId &&- (composerEngineMarkVendor === null || sessionFavoriteAnchor.engine === composerEngineMarkVendor)- ? sessionFavoriteAnchor.uid- : null+ ? (sessionFavoriteAnchor?.uid ?? null): selectedFavoriteUid;// 会话内拿不到跨引擎切换事务(SSH 远程会话 / 被控端不支持 session-agent-switch /diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsxindex 70c1981fe2..72d4189013 100644--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx@@ -3165,21 +3165,21 @@ export function ModelSelector({// 统一面板下没有「先切分段再选模型」那一步,跨引擎的确认落在**真正选中那一行**的这一下。// 确认用的 AlertDialog 同样会被 Popover 当成外部交互顺手把面板收掉,所以复用上面那把- // 保命锁;区别只在收尾:- // · 调用方执行了切换(返回非 false)→ 收起面板(与旧两步分段选完即收一致);- // · 用户在确认框上取消 / 事务失败(返回 false)→ 面板留在原地,他还能接着挑别的行。+ // 保命锁。收尾**成功也不关**(Chris 2026-08-20):切完引擎用户还要改思维 / 再点胶囊,+ // 以前 applied=true 就收窗,表象就是「所有模型改不了 Harness」。取消 / 失败同样留在原地。//// 2026-08-17 review 第二项之后,这个 await 等的是**整条切换事务**(确认框 + 登记往返),// 不再只是确认框那一下。保命锁刻意**覆盖整个 await 期**:事务在途时面板被 Popover 的// 外点判定收掉,收尾再把 open 设回 true,就成了「面板闪一下又自己弹回来」。锁按住期间- // 面板恒可见,切换 in-flight 由 interactionDisabled 置灰,收尾时才按结果决定收还是留- // —— 中途没有可以插进来的关闭窗口。+ // 面板恒可见,切换 in-flight 由 interactionDisabled 置灰。//- // ★ 因此 open 的表达式必须是 `(open && !disabled) || keepOpenForAgentConfirmation`,- // 不能是 `(open || keepOpen) && !disabled`(Chris 2026-08-19 实测「面板原地刷新一下」的- // 根因):事务一进 beginAgentSwitchOperation,调用方的 agentSwitchInFlight 就把 disabled- // 拉高,后一种写法会连保命锁一起压掉 —— 面板当场收合,收尾时 setOpenWithoutAutoRefresh(true)- // 又把它弹回来。保命锁的意义就是「这段时间里别关」,disabled 不该有权否决它。+ // ★ open 的表达式必须是 `open || keepOpenForAgentConfirmation`,disabled **不能**参与+ // 开关(Chris 2026-08-19「面板原地刷新」+ 2026-08-20「改思维闪关菜单」):+ // 事务一进 beginAgentSwitchOperation,调用方的 agentSwitchInFlight 就把 disabled 拉高。+ // `(open && !disabled) || keepOpen` 只保住确认框那条路,改思维 / 同引擎重登记不走+ // keepOpen,选单照关。disabled 只该让面板置灰(interactionDisabled),不该有权把窗口关掉。+ // 不能写成 `(open || keepOpen) && !disabled` —— 那是 08-19 的原症状。+ // 不能写成 `(open && !disabled) || keepOpen` —— 那是 08-20 改思维仍闪关。const contentSessionEngineFilter = useMemo(() => {if (!sessionEngineFilter) return undefined;const { onCrossEngineSelect } = sessionEngineFilter;@@ -3191,8 +3191,10 @@ export function ModelSelector({setKeepOpenForAgentConfirmation(true);try {const applied = await onCrossEngineSelect(args);- // 执行了切换 → 收面板;取消 → 留在原地(open 保持 true)。- setOpenWithoutAutoRefresh(applied === false);+ // 成功也不收选单(Chris 2026-08-20):切完引擎用户还要改思维 / 再点胶囊。+ // 以前 `applied === true` 就把窗口关了,表象就是「所有模型改不了 Harness」——+ // 一点胶囊选单消失,变量还没调完。取消 / 失败同样留在原地。用户自己点外面才关。+ setOpenWithoutAutoRefresh(true);return applied !== false;} finally {setKeepOpenForAgentConfirmation(false);@@ -3795,7 +3797,7 @@ export function ModelSelector({if (morphEnabled) {return (<MorphPopover- open={(open && !disabled) || keepOpenForAgentConfirmation}+ open={open || keepOpenForAgentConfirmation}onOpenChange={handleOpenChange}side={popoverSide}align="end"@@ -3822,7 +3824,7 @@ export function ModelSelector({return (<Popover- open={(open && !disabled) || keepOpenForAgentConfirmation}+ open={open || keepOpenForAgentConfirmation}onOpenChange={handleOpenChange}><PopoverTrigger asChild>{trigger}</PopoverTrigger>diff --git a/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx b/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsxindex 62d42ae52c..47d1c2bebb 100644--- a/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx+++ b/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx@@ -42,7 +42,6 @@ import {computeSelectedRowScrollTop,priceTierOf,railItemKey,- resolveActiveFavoriteAnchorUid,resolveFavoriteRowConfig,resolveUnifiedRowConfig,sameAnchor,@@ -172,6 +171,12 @@ export interface UnifiedModelPanelProps {*/sessionEngineFilter?: {currentAgent: AgentKind;+ /**+ * 任务**正在跑**的引擎(不跟随切换意图)。跨引擎确认与切换路由拿它和行上的生效引擎比:+ * 意图期 currentAgent 会翻到目标,用 currentAgent 判断会把「点 Pi 收藏」当成同引擎、+ * 跳过确认框(Chris 2026-08-20)。缺省 = 回落 currentAgent(草稿 / 无 runtime 的入口)。+ */+ runtimeAgent?: AgentKind;/*** 返回 `false` = 调用方**没有**执行这次切换(典型:跨引擎确认弹窗被取消)。* 面板本身不消费返回值,但包在外面的 ModelSelector 靠它决定「收起面板」还是@@ -418,30 +423,16 @@ export function UnifiedModelPanel({// 选中的收藏锚点**必须仍然存在**才算数(规格 §1.5「删除选中条目时选中回落到对应模型// 默认」)。同一条兜底也覆盖切账号:收藏 store 按 dataOwnerId 分区,换号后旧 uid 在新// 分区里查无此条 —— 不做这层解析就会两头落空(收藏行没了、模型行的勾又被抑制)。- // 存在之外还要**完整配置仍然相等**(2026-08-19 review P2):上游锚点校验只比身份三维- // (模型/来源/引擎),外部(device-link seed / 另一窗口 / 另一控制端)只改同一模型的- // 深度或 Fast 时,身份照样全对 —— 副本 ≠ live 的收藏不能再勾住。逐维口径与误杀- // 分析见 resolveActiveFavoriteAnchorUid 头注;所有锚点入口都汇到这一个派生点。+ //+ // 收藏是独立选中项(Chris 2026-08-20):只认 uid 还在不在,不拿正在跑的引擎/思维/加速+ // 去对副本。对上才打勾,等于让下面同名模型行把焦点抢走 —— 点了 Pi 收藏、任务还停在+ // Claude 时必现。const activeFavoriteUid = useMemo(() =>- resolveActiveFavoriteAnchorUid({- selectedFavoriteUid,- favorites,- entries,- liveEffort: selectedEffort,- liveFast: fastMode,- liveAgent: liveEngineAgent,- agentFastModeCapable,- }),- [- agentFastModeCapable,- entries,- fastMode,- favorites,- liveEngineAgent,- selectedEffort,- selectedFavoriteUid,- ],+ selectedFavoriteUid && favorites.some((item) => item.uid === selectedFavoriteUid)+ ? selectedFavoriteUid+ : null,+ [favorites, selectedFavoriteUid],);// ★ 引擎那一半(engineOverride / pinnedEngine / forceEngine 的合成与 isSelectedModelRow@@ -619,6 +610,9 @@ export function UnifiedModelPanel({rowTop: rowRect.top - listRect.top + el.scrollTop,rowBottom: rowRect.bottom - listRect.top + el.scrollTop,});+ // 只滚动、不抢焦点(DESIGN.md §14.2:弹层打开焦点在搜索框)。打开/改搜索词时+ // 把焦点搬到选中行,第一个字符就会把搜索框失焦。勾选与居中已经能让收藏行可见;+ // 键盘在行上 ←/Enter 仍由行自己的 tabIndex 接手。if (alignment.oversized) {// 行比可视区还高:此刻只能顶对齐,但**保持在途**(2026-08-19 预审 P1-3)——morph 生长// 途中的一串中间尺寸都可能暂时「装不下一行」,在这里收工的话面板长开后不再复核,@@ -747,9 +741,8 @@ export function UnifiedModelPanel({return () => document.removeEventListener('scroll', onAnyScroll, true);}, [cancelClose, closeFlyout, flyAnchor]);- useEffect(() => {- if (interactionDisabled) closeFlyout();- }, [closeFlyout, interactionDisabled]);+ // 切换事务 in-flight 时面板会 interactionDisabled 置灰,但浮层不能收 —— 收了就是+ // 「改思维闪关菜单」(Chris 2026-08-20):改档走 performAgentSwitch → disabled → 浮层没了。const isSelectedRow = useCallback((anchor: UnifiedAnchor, entry: UnifiedModelEntry): boolean => {@@ -789,9 +782,10 @@ export function UnifiedModelPanel({} = useUnifiedRowActions({interactionDisabled,isLiveRow,- // 两笔实时写入(深度 + Fast)里第二笔失败时回滚第一笔用的原值 —— 与 configOf 里- // 「选中行读 live 值」取的是同一个格子(见 useUnifiedRowActions.liveEffort)。+ // 两笔实时写入(深度 + Fast)里第二笔失败时回滚第一笔用的原值,以及收藏 live 判定+ // 要比的实时深度 / Fast —— 与 configOf 里「选中行读 live 值」取的是同一个格子。liveEffort: selectedEffort,+ liveFast: fastMode,modelMemory,onEffortChangeLive,onFastModeChangeLive,diff --git a/apps/desktop/src/renderer/components/new-chat/agentSwitchConfirmation.ts b/apps/desktop/src/renderer/components/new-chat/agentSwitchConfirmation.tsindex 58b9a23e0e..921da1f0fc 100644--- a/apps/desktop/src/renderer/components/new-chat/agentSwitchConfirmation.ts+++ b/apps/desktop/src/renderer/components/new-chat/agentSwitchConfirmation.ts@@ -17,17 +17,12 @@ export interface AgentSwitchConfirmationCopy {export interface ConfirmAgentSwitchRiskParams {/**- * 「这一次不必再问」——调用方按**两条**出口置位(任一成立即为 true):+ * 「这一次不必再问」——**只有**本次目标就是会话正在跑的真实引擎时才为 true+ * (撤销 / 回原引擎:main 侧 same-engine no-op,不重建上下文)。*- * 1. 会话上已有**指向本次目标引擎**的切换意图:用户此前已对这个方向确认过,后续在同一- * 目标里改选模型 / 来源 / 深度 / Fast 都不重复提示。- * 2. 本次目标**就是会话的真实引擎**(撤销 / 回原引擎):main 侧走 same-engine no-op,- * 不重建上下文、零风险。判它必须用不跟随意图的事实值,详见 ChatInput 的调用点。- *- * ★ 第 1 条必须带上「目标相同」这一维(Chris 2026-08-19 实测反馈)。只判「有没有意图」会- * 让确认框在会话上挂着**任何**残留意图之后永久静默:用户先切了 Codex(意图挂上),再去- * 选 Pi 的模型,风险确认一声不吭就直接改道了另一个引擎 —— 而每一次换目标都是一次新的- * 上下文重建风险,必须重新确认。+ * 挂着的切换意图**不能**当作已经确认过(Chris 2026-08-20):Claude 任务里点了 Pi 收藏、+ * 意图挂上但还没发消息,再点另一条非当前引擎的模型/收藏,仍然是一次新的上下文重建,+ * 必须再问。判据只认 runtime,不认意图目标,详见 ChatInput 的调用点。*/hasSwitchIntent: boolean;confirm: (options: ConfirmOptions) => Promise<boolean>;@@ -37,10 +32,8 @@ export interface ConfirmAgentSwitchRiskParams {/*** Agent 切换确认门。*- * 首次进入另一 Agent(顶部分段浏览态,或统一面板里点中一条跨引擎行)时提示;已有**同目标**- * 切换意图代表用户已经对这个方向确认过,后续改选模型/来源/effort/Fast 都直接放行;**返回- * 原引擎**(目标 = 会话真实引擎)同样放行 —— 那是 same-engine no-op,不重建上下文。- * 换一个目标引擎 = 一次新的风险,重新提示(两条出口见 hasSwitchIntent 的说明)。+ * 用户只要选的是**不是当前真实引擎**的模型或收藏,一律提示。返回原引擎(目标 = 会话+ * 真实引擎)放行 —— 那是 same-engine no-op,不重建上下文。挂着的意图不算已经确认过。*/export async function confirmAgentSwitchRisk({hasSwitchIntent,diff --git a/apps/desktop/src/renderer/components/new-chat/unifiedModelSelection.ts b/apps/desktop/src/renderer/components/new-chat/unifiedModelSelection.tsindex edc3429bd7..b35ceea2f0 100644--- a/apps/desktop/src/renderer/components/new-chat/unifiedModelSelection.ts+++ b/apps/desktop/src/renderer/components/new-chat/unifiedModelSelection.ts@@ -262,67 +262,9 @@ export function resolveFavoriteRowConfig(args: {}/**- * 「当前选中的收藏」锚点的**完整配置校验**(2026-08-19 review P2:深度与 Fast 纳入锚点判定)。- *- * 病根:锚点记录与上游派生校验(草稿 / 会话两侧)只比模型、来源、引擎三个**身份**维。- * 收藏的定义是**完整配置副本**(规格 §1.2,含深度与 Fast)——持久化锚点存在期间,- * device-link seed、另一窗口或另一控制端只改同一模型/来源的 effort 或 Fast 时,身份三维- * 照样全对,旧收藏 uid 被恢复:面板抑制真实模型行的勾选、把带旧深度/Fast 的副本当成- * 当前配置展示,编辑/删除还会按错误副本执行(删除会误触「先回落默认配置」)。- *- * 修法是**校验收窄,不是记录加维**:锚点记录刻意维持身份三元组(见 favoriteAnchorMemory- * 的 schema 注释)——把 effort/Fast 抄进锚点会造出第二份会过期的副本(编辑选中收藏的- * 每一条路径都得记得同步它,漏一处就误杀)。这里改为在**消费点**把「该收藏当前副本的- * 解析结果」与「正在跑的完整配置」直接比对:收藏 store 与 live 值都是各自的唯一事实源,- * 不新增任何写路径。所有锚点入口(草稿槽、会话槽、storage 事件回读、各建会话路径的- * 锚点携带)最终都汇到这一个派生点,天然一次覆盖。- *- * 逐维口径:- * - 引擎:`liveAgent` 已知时必须与副本解析引擎一致(意图期 = 目标引擎,与调用方- * liveEngineAgent 同口径);未知(身份未加载的一帧)不参与判定,免得误杀。- * - 深度:双方都有值才比 —— 副本解析出 null(不可调模型)或 live 值为空(上游未就绪)- * 时该维放行。- * - Fast:live 值按副本的 fastCapable 门控后逐字比(副本无能力时恒 false,两边同规则)。- * - 收藏指向的模型行不可路由(来源断开)时**不否决**:配置无从解析,身份校验已在上游- * 通过,此时列表里本就没有可勾的行,维持既有行为。- *- * 面板内正常操作不会被误杀:模型行上改 live 深度/Fast 会显式清锚(M2),编辑选中收藏- * 走「live 写成才落副本」的同一事务(两边同步收敛);只有**外部**改动才会造成真正的- * 副本 ≠ live,而那正是该松开勾选的时刻。+ * 收藏选中身份就是 uid(Chris 2026-08-20):面板只认「这条 uid 还在收藏列表里」,+ * 不拿正在跑的引擎/思维/加速去对副本 —— 对上才打勾会让下面同名模型行抢走焦点。*/-export function resolveActiveFavoriteAnchorUid(args: {- /** 上游身份校验(模型/来源/引擎快照)已通过的锚点 uid。 */- selectedFavoriteUid: string | null | undefined;- favorites: readonly ModelFavoriteItem[];- entries: readonly UnifiedModelEntry[];- /** 正在跑的深度(空值 = 未知,该维不参与判定)。 */- liveEffort: Effort | null | undefined;- /** 正在跑的 Fast。 */- liveFast: boolean;- /** 正在跑的引擎(意图期 = 目标引擎);null = 身份未加载,该维不参与判定。 */- liveAgent: AgentKind | null;- agentFastModeCapable?: (agent: AgentKind) => boolean;-}): string | null {- const { selectedFavoriteUid, favorites, entries, liveEffort, liveFast, liveAgent } = args;- if (!selectedFavoriteUid) return null;- // 选中的收藏必须仍然存在(规格 §1.5 删除回落;换账号后旧 uid 查无此条同此兜底)。- const item = favorites.find((favorite) => favorite.uid === selectedFavoriteUid);- if (!item) return null;- const entry = entries.find(- (candidate) =>- candidate.providerId === item.providerId && entryMatchesModelId(candidate, item.modelId),- );- if (!entry) return selectedFavoriteUid;- const config = resolveFavoriteRowConfig({- entry,- item,- ...(args.agentFastModeCapable ? { agentFastModeCapable: args.agentFastModeCapable } : {}),- });- if (liveAgent !== null && config.agent !== liveAgent) return null;- if (liveEffort && config.effort !== null && config.effort !== liveEffort) return null;- if (config.fast !== (config.fastCapable ? liveFast : false)) return null;- return selectedFavoriteUid;-}/*** 该收藏是否**就是**该模型的推荐配置 —— 决定收藏行右侧要不要挂 `引擎 · 深度 [⚡]` 后缀diff --git a/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts b/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.tsindex 3363eca1e8..0884b68aa3 100644--- a/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts+++ b/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts@@ -27,6 +27,7 @@ import {} from '@/state/modelEnginePrefs';import {addModelFavorite,+ getModelFavorite,removeModelFavorite,updateModelFavorite,type ModelFavoriteConfig,@@ -53,10 +54,17 @@ export interface UnifiedRowActionsOptions {* 正在跑的那一份的**实时深度**(会话 = live effort;草稿 = 调用方派生的同一个值 ——* 与 `onEffortChangeLive` 写的是同一个格子)。*- * 只用于**回滚**:两笔实时写入(深度 + Fast)里第二笔失败时,拿它把第一笔写回原值- * (见 applyDefaultsLive)。拿不到 = 没有可回滚的原值,那一路按注释里的说明处理。+ * 两处用它:① 回滚 —— 两笔实时写入(深度 + Fast)里第二笔失败时,拿它把第一笔写回原值+ * (见 applyDefaultsLive);② 收藏副本是否仍是正在跑的完整配置(与 liveFast 一起,+ * 见 favoriteCopyIsLive)。拿不到 = 没有可回滚的原值,那一路按注释里的说明处理。*/liveEffort?: Effort | undefined;+ /**+ * 正在跑的那一份的**实时 Fast**(与 `onFastModeChangeLive` 写的同一个格子)。+ * 收藏 live 判定必须拿它和副本比:composer / 另一窗口只改了 Fast 时,uid 还在,+ * 但副本已经不是正在跑的配置。缺省按关(与行配置合成一致)。+ */+ liveFast?: boolean | undefined;modelMemory?: ModelMemoryAccessors | undefined;/*** live 选中行改深度。返回值 = **这次写入真的落下去了没有**(`false` / 抛错 = 没落;@@ -94,6 +102,8 @@ export interface UnifiedRowActionsOptions {sessionEngineFilter?:| {currentAgent: AgentKind;+ /** 任务正在跑的引擎;缺省 = currentAgent。跨引擎确认路由必须用这个,不能用意图目标。 */+ runtimeAgent?: AgentKind;onCrossEngineSelect: (args: {providerId: string;modelId: string;@@ -187,6 +197,7 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): UnifiedinteractionDisabled,isLiveRow,liveEffort,+ liveFast,modelMemory,onEffortChangeLive,onFastModeChangeLive,@@ -212,6 +223,38 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified* 无损,直接写回草稿即可。两个字段必须同时具备:少了任一个,跨引擎行就没有落点。*/const inSession = sessionEngineFilter !== undefined && sessionAgent !== undefined;+ /**+ * 任务**正在跑**的引擎。只认调用方显式给的 `runtimeAgent`,缺省**不**回落 sessionAgent:+ * 那是面板展示 / 意图目标。冷加载 runtime 未到时回落,会把意图目标当成真实引擎,+ * 点它就绕过确认(2026-08-20 review)。+ */+ const runtimeAgent = sessionEngineFilter?.runtimeAgent;+ /** 面板展示的是待发送意图,不是正在跑的引擎。真实引擎未知时不算「已在意图上」。 */+ const pendingSwitch =+ inSession &&+ runtimeAgent !== undefined &&+ sessionEngineFilter.currentAgent !== runtimeAgent;+ const shouldCrossEngine = (target: AgentKind): boolean => {+ if (sessionEngineFilter === undefined) return false;+ // 真实引擎还没确认:一律走切换确认,不能当同引擎放行。+ if (runtimeAgent === undefined) return true;+ return target !== runtimeAgent || pendingSwitch;+ };+ /**+ * 这条收藏副本是不是**正在跑的完整配置**(来源 + 模型 + 引擎 + 思维 + Fast)。+ * `isLiveRow` 只比身份三元组,给模型行的引擎胶囊 / 实时写入用;收藏的删除回落与+ * 编辑写回必须再比思维 / Fast —— composer、另一窗口或控制端只改了这两格时,+ * uid 还在,但不能把后来的选择覆盖成旧副本(2026-08-20 review)。+ */+ const favoriteCopyIsLive = (anchor: UnifiedAnchor, entry: UnifiedModelEntry): boolean => {+ if (anchor.kind !== 'fav') return false;+ const item = getModelFavorite(anchor.uid);+ if (!item || !resolveFavoriteConfig) return false;+ const copy = resolveFavoriteConfig(entry, item);+ if (!isLiveRow(entry, copy)) return false;+ if ((copy.effort ?? null) !== (liveEffort ?? null)) return false;+ return copy.fast === (liveFast ?? false);+ };/*** 把一次 live 写入的结果归一成「成功了没有」:只有明确的 `false` 与抛错算失败,@@ -471,8 +514,8 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified}): undefined;// 改的不是当前选中的那条收藏(或引擎没变 / 没注入解析器)→ 它只描述「下次选它用什么」,- // 行为不变:只改副本。- if (!target) {+ // 行为不变:只改副本。副本已不再是正在跑的配置时同样只改记录,不隐式写回运行态。+ if (!target || !favoriteCopyIsLive(anchor, entry)) {commit();return;}@@ -495,7 +538,9 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unifiedconst next = resolveEngineConfig?.(entry, engine);if (sessionEngineFilter && sessionAgent !== undefined) {const targetAgent = agentKindOfEngine(engine);- if (targetAgent === sessionAgent) return; // 已在该引擎上,无事可做。+ // 已在真实引擎上、也没有待发送意图 → 无事可做。真实引擎未知、或挂着意图时+ // 点回正在跑的引擎,都走切换事务(未知 fail-closed;意图由 same-engine 路径清掉)。+ if (!shouldCrossEngine(targetAgent)) return;// 会话内改选中行的引擎 = 一次跨引擎切换:交给 performAgentSwitch 事务(确认弹窗// + 上下文重建)。**不预写全局 override**:用户取消确认时不该留下任何痕迹。sessionEngineFilter.onCrossEngineSelect({@@ -534,7 +579,7 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unifiedconst commit = (): void => updateModelFavorite(anchor.uid, { effort });// 改的不是当前选中的那条收藏(或压根没有 live 深度通道)→ 它只描述「下次选它用什么」,// 行为不变:只改副本。- if (selectedFavoriteUid !== anchor.uid || !onEffortChangeLive) {+ if (selectedFavoriteUid !== anchor.uid || !onEffortChangeLive || !favoriteCopyIsLive(anchor, entry)) {commit();return;}@@ -579,7 +624,7 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unifiedif (anchor.kind === 'fav') {const commit = (): void => updateModelFavorite(anchor.uid, { fast: enabled });// 同 applyEffort:非选中收藏(或没有 live Fast 通道)只改副本,不动正在跑的那一份。- if (selectedFavoriteUid !== anchor.uid || !onFastModeChangeLive) {+ if (selectedFavoriteUid !== anchor.uid || !onFastModeChangeLive || !favoriteCopyIsLive(anchor, entry)) {commit();return;}@@ -743,9 +788,13 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): UnifiedonBeforeRemoveFavorite(anchor);removeModelFavorite(anchor.uid);};- // 删的不是当前选中锚点 → 它不影响「正在跑什么」,行为不变:只删记录。+ // 勾选身份只认 uid(收藏是独立条目);**回落正在跑的配置**必须另过一关:+ // 副本仍是正在跑的那一份。用户选中收藏后又从别的入口改了模型/思维,uid 还在,+ // 但不能把后来的选择覆盖成这条旧收藏的默认(2026-08-20 review P1)。const fallback =- selectedFavoriteUid && selectedFavoriteUid === anchor.uid+ selectedFavoriteUid &&+ selectedFavoriteUid === anchor.uid &&+ favoriteCopyIsLive(anchor, entry)? resolveDefaultRowConfig?.(entry): undefined;if (!fallback) {@@ -765,27 +814,28 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unifiedcommit();return;}- // 会话 + 默认引擎 == 当前引擎:无损,两个 live 回调把深度 / Fast 复位即可。- // 与跨引擎分支同一条顺序(2026-08-17 review 第三轮 G2):**live 真写成了才**删记录 ——- // 收藏是用户手存的东西,不可逆,写穿失败时必须原样留着。- if (fallback.agent === sessionAgent) {- void applyDefaultsLive(fallback.effort).then((applied) => {- if (applied) commit();+ // 会话内回落:默认引擎 ≠ 正在跑的引擎,或正挂着待发送意图,都走切换事务。+ // 挂着 Pi 意图、默认却回到 Claude 时,只复位深度 / Fast 清不掉意图,下一条消息+ // 仍会切到 Pi —— 与引擎胶囊 / 普通行的 same-engine 取消同一条 shouldCrossEngine。+ if (shouldCrossEngine(fallback.agent)) {+ runCrossEngineSwitch({+ providerId: anchor.providerId,+ wireModelId,+ targetAgent: fallback.agent,+ effort: fallback.effort,+ // 默认配置的 Fast(resolveDefaultRowConfig 给的是「无收藏语境」的那一份,恒为关)——+ // 与恢复推荐同族:显式交给事务,不留给目标记忆重解析。+ fast: fallback.fast,+ // 这条收藏马上就没了 → 清锚点(留着会让面板在一条已删的收藏上打勾)。+ favoriteUid: null,+ onApplied: commit,});return;}- // 会话 + 默认引擎 ≠ 当前引擎:有损,走跨引擎切换事务;真成功才删收藏。- runCrossEngineSwitch({- providerId: anchor.providerId,- wireModelId,- targetAgent: fallback.agent,- effort: fallback.effort,- // 默认配置的 Fast(resolveDefaultRowConfig 给的是「无收藏语境」的那一份,恒为关)——- // 与恢复推荐同族:显式交给事务,不留给目标记忆重解析。- fast: fallback.fast,- // 这条收藏马上就没了 → 清锚点(留着会让面板在一条已删的收藏上打勾)。- favoriteUid: null,- onApplied: commit,+ // 会话 + 默认引擎 == 正在跑的引擎,且没有待发送意图:无损,两个 live 回调把深度 / Fast 复位。+ // 与跨引擎分支同一条顺序:**live 真写成了才**删记录。+ void applyDefaultsLive(fallback.effort).then((applied) => {+ if (applied) commit();});};@@ -799,7 +849,7 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified// 交出去的一律是**该引擎的 wire id**(建会话 / 切模型 / 写 draft 都用它);// 行的归一化身份另放在 config.rowModelId 里,调用方要记 override / 收藏时用那个。const wireModelId = config.wireModelId ?? anchor.modelId;- if (sessionEngineFilter && sessionAgent !== undefined && config.agent !== sessionAgent) {+ if (sessionEngineFilter && shouldCrossEngine(config.agent)) {// 收藏锚点一并交出去:会话侧要在事务**真成功后**才把它记成「当前选中的收藏」// (取消 / 失败时什么都没换,锚点当然不能动)。同引擎那一路由 onSelect 的 config 带走。sessionEngineFilter.onCrossEngineSelect({diff --git a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsxindex 0f03ee31aa..e932be67c4 100644--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx@@ -2026,12 +2026,11 @@ export function NewMakerDraftRoute() {// (本地草稿 × 远程草稿)共用同一引擎槽时也会互删。派生「不符不亮」已保证不会勾错;// 显式选择(选普通模型行 → handleUnifiedDraftSelect 写 null)仍会清槽。留下的休眠锚点// 只在 (模型, 来源) 改回那一刻重新亮起 —— 那本来就是用户对该配置最后一次显式选中的副本。- const selectedFavoriteUid =- draftFavoriteAnchor &&- draftFavoriteAnchor.wireModelId === draftInitialModel &&- draftFavoriteAnchor.providerId === chatInitialProviderId- ? draftFavoriteAnchor.uid- : null;+ // 收藏是独立选中项(Chris 2026-08-20):勾选身份就是 uid,不拿草稿当前模型/来源去对+ // 快照 —— 对不上就不勾,等于让下面同名模型行把焦点抢走。草稿模型被 coerce / seed+ // 改走时收藏行仍是用户点过的那一条;显式点普通模型行才会经 handleUnifiedDraftSelect+ // 把槽写成 null。条目被删 / 换账号由面板 activeFavoriteUid 兜底。+ const selectedFavoriteUid = draftFavoriteAnchor?.uid ?? null;/*** 草稿锚点 → 会话锚点的**延续**(Chris 2026-08-19):草稿里选了收藏第 3 条、发出去建会话,diff --git a/apps/desktop/src/renderer/state/favoriteAnchorMemory.ts b/apps/desktop/src/renderer/state/favoriteAnchorMemory.tsindex adf27a5615..072d0019c2 100644--- a/apps/desktop/src/renderer/state/favoriteAnchorMemory.ts+++ b/apps/desktop/src/renderer/state/favoriteAnchorMemory.ts@@ -67,12 +67,10 @@ export interface DraftFavoriteAnchor {* 选中 A 的收藏并抑制 B 模型行的勾,之后编辑 / 删除的也是错误副本。面板行恒带显式来源,* 所以这里恒为 string(与会话槽同口径)。*- * ★ 深度 / Fast **刻意不进锚点记录**(2026-08-19 review P2):锚点只存**身份**快照- * (哪个 uid、指向哪个 wire model / 来源 / 引擎),配置维的等值校验放在消费点 ——- * 统一面板派生 activeFavoriteUid 时用「该收藏当前副本的解析结果 vs 正在跑的完整配置」- * 直接比(见 unifiedModelSelection.resolveActiveFavoriteAnchorUid)。把 effort/Fast 抄进- * 锚点会造出第二份会过期的副本:编辑选中收藏的每条路径都得记得同步它,漏一处就把- * 刚编辑完、本该保持选中的收藏误杀出勾选态。+ * ★ 深度 / Fast **刻意不进锚点记录**:锚点只存**身份**快照(哪个 uid、指向哪个+ * wire model / 来源 / 引擎)。收藏是独立选中项(Chris 2026-08-20)——勾选只认 uid+ * 还在不在,不拿正在跑的思维/加速去对副本。把 effort/Fast 抄进锚点会造出第二份+ * 会过期的副本。*/providerId: string;}diff --git a/docs/product-rules/model-selector-unified.md b/docs/product-rules/model-selector-unified.mdindex f5b5888f75..340964bf0c 100644--- a/docs/product-rules/model-selector-unified.md+++ b/docs/product-rules/model-selector-unified.md@@ -68,8 +68,9 @@别家时同样不显示。- 跨引擎:点「全部/供应商」显式切换,列表顶部一行警示「⚠ 跨引擎切换会重建上下文,有丢失风险」。- 切引擎执行仍走既有 `performAgentSwitch` 链路(确认弹窗、fastMode 不跨引擎带入等语义保留)。-- **风险确认按目标引擎判重**(Chris 2026-08-19):「已确认过、不再重复弹」的条件是会话上已有**指向本次目标- 引擎**的切换意图;换一个目标引擎是一次新的上下文重建风险,必须重新确认。+- **风险确认只认任务真实引擎**(Chris 2026-08-20):用户只要选的是**不是当前正在跑的引擎**的模型或收藏,+ 一律弹出换引擎确认。挂着的切换意图不算已经确认过 —— Claude 任务里点了 Pi 收藏、还没发消息,再点+ 另一条非 Claude 的模型/收藏,仍然要问。只有目标就是正在跑的引擎(回原引擎)才不弹。- **切换事务的「成功」= 本端请求的完整配置原样落地**(2026-08-19 review 收口):main 先广播意图回声、后回ack,回声身份匹配只比 target/model/provider 三元组(effort/Fast 可能被 main 归一化,providerId 传 null 时跟随默认路由解析)。因此三元组匹配、但权威回声里的 effort/Fast 与本端请求不一致(device-link 往返期间另一@@ -133,13 +134,9 @@Chris 2026-08-19 实测后从内存态改为持久化:`{ drafts: { <cc|codex|pi>: { uid, wireModelId, providerId } }, sessions: [{ sessionId, uid, wireModelId, engine, providerId }] }`- 草稿槽按引擎分(与 `lastByVendor` 同一分槽维度);会话槽按 sessionId,**LRU 上限 100**(队首=最近一次写)。- - 存的是**选中那一刻的快照**,消费方与当前 (模型/引擎/来源) 逐项比对后才打勾,对不上就回落模型行 —— 过期- 锚点永远不会让面板勾一份已经不生效的配置。- - 快照只含**身份**维;深度/Fast **不进锚点记录**,而在消费点校验(2026-08-19 review):统一面板派生选中收藏时,- 把该收藏**当前副本的解析结果**与正在跑的完整配置(引擎/深度/Fast)比对,任一维不等即回落模型行 —— 覆盖- device-link seed / 另一窗口 / 另一控制端只改同一模型深度或 Fast 的全部路径(草稿槽、会话槽、storage 回读、- 建会话锚点携带都汇到这一个派生点)。不把 effort/Fast 抄进锚点:那是第二份会过期的副本,编辑选中收藏的每条- 路径都得同步它,漏一处就误杀刚编辑完的选中态。逐维宽严见 `resolveActiveFavoriteAnchorUid` 头注。+ - 存的是**选中那一刻的快照**。收藏是独立选中项(Chris 2026-08-20):勾选只认 uid 还在收藏列表里,+ 不拿正在跑的模型/引擎/思维去对副本 —— 对上才打勾会让下面同名模型行抢走焦点。用户点普通模型行时+ 才把 uid 置空。快照里的 wire/来源仍用于建会话延续,不参与勾选判定。- 仍**不是用户配置**:不落库、不进 device-link payload、写失败静默吞;丢了只是回落模型行。- 草稿发送建会话时,仍有效且**有显式来源**的草稿锚点写进该 sessionId 的会话槽(跟随默认路由的会话`providerId` 为 null,与显式来源的锚点永不相等,存了也打不上勾,故不延续)。