Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 已有任务换模后下次新建仍跟随这次选择
Dash26c9bde1148b
diff --git a/apps/desktop/src/renderer/App.tsx b/apps/desktop/src/renderer/App.tsxindex cebaf9d7c4..861243c983 100644--- a/apps/desktop/src/renderer/App.tsx+++ b/apps/desktop/src/renderer/App.tsx@@ -235,7 +235,7 @@ export function App() {const shouldPatchActiveModel = markModelChoice !== false || effort !== undefined;if (shouldPatchActiveModel) {patch(vendor, {- model: modelId,+ ...(markModelChoice === false ? {} : { model: modelId }),providerId: providerId || null,...(effort !== undefined ? { effort: effort as Effort } : {}),});diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.tsindex 90e3279358..9051878b2b 100644--- a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts+++ b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts@@ -951,7 +951,7 @@ describe('远程交互接线不变式', () => {expect(finalize).toBeGreaterThan(sync);});- it('会话同步 New Maker 草稿默认不应打 modelChosenByVendor 显式选择标记', () => {+ it('已有任务换模会打选模标记,只改思考档 / Fast 不会', () => {const chatInputSrc = read('components/new-chat/ChatInput.tsx');const syncStart = chatInputSrc.indexOf('const syncSessionDraftModelPrefs');const syncEnd = chatInputSrc.indexOf('const persistFastModeChange', syncStart);@@ -959,12 +959,14 @@ describe('远程交互接线不变式', () => {expect(syncEnd).toBeGreaterThan(syncStart);const syncBody = chatInputSrc.slice(syncStart, syncEnd);expect(syncBody).toContain('patchVendorPrefsPreservingModelChoice');- expect(syncBody).toContain('markModelChoice: false');+ expect(syncBody).toContain('markModelChoice ? patchVendorPrefs : patchVendorPrefsPreservingModelChoice');+ expect(syncBody).toContain("opts.markModelChoice === true");expect(syncBody).toContain('opts.remoteDeviceId ?? getSessionDeviceId(sessionId) ?? deviceLinkDeviceId',);expect(syncBody).toContain(".invoke(remoteDeviceId, 'maker:apply-new-maker-draft-pref'");- expect(syncBody).not.toContain('patchVendorPrefs(vendor');++ expect(chatInputSrc).toContain('markModelChoice: true');const appSrc = read('App.tsx');expect(appSrc).toContain(diff --git a/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts b/apps/desktop/src/renderer/__tests__/newMakerDraft.test.tsindex 9024f27c90..6e68327089 100644--- a/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts+++ b/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts@@ -350,14 +350,12 @@ describe('newMakerDraft store', () => {expect(m2.getPersistedVendorModel('cc')).toBe('claude-opus-4-8');});- it('patchVendorPrefsPreservingModelChoice:会话同步草稿默认不打显式选择标记', async () => {+ it('patchVendorPrefsPreservingModelChoice:只改思考档不打显式选择标记', async () => {const m1 = await loadModule();m1.patchVendorPrefsPreservingModelChoice('cc', {- model: 'claude-opus-4-8',effort: 'high',});- expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-opus-4-8');expect(m1.getDraft().lastByVendor.cc.effort).toBe('high');expect(m1.getDraft().modelChosenByVendor).toEqual({});expect(m1.getPersistedVendorModel('cc')).toBe('');@@ -367,31 +365,26 @@ describe('newMakerDraft store', () => {expect(m1.getPersistedVendorModel('cc')).toBe('claude-opus-4-8');});- it('patchVendorPrefsPreservingModelChoice:会话同步 model 会清掉旧显式选模标记', async () => {+ it('patchVendorPrefsPreservingModelChoice:已有任务换模后只改思考档不得清掉选模标记', async () => {const m1 = await loadModule();m1.patchVendorPrefs('cc', { model: 'claude-sonnet-4-6' });expect(m1.getDraft().modelChosenByVendor).toEqual({ cc: true });expect(m1.getPersistedVendorModel('cc')).toBe('claude-sonnet-4-6');m1.patchVendorPrefsPreservingModelChoice('cc', {- model: 'claude-opus-4-8',effort: 'high',});- expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-opus-4-8');- expect(m1.getDraft().modelChosenByVendor).toEqual({});- expect(m1.getPersistedVendorModel('cc')).toBe('');+ expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-sonnet-4-6');+ expect(m1.getDraft().lastByVendor.cc.effort).toBe('high');+ expect(m1.getDraft().modelChosenByVendor).toEqual({ cc: true });+ expect(m1.getPersistedVendorModel('cc')).toBe('claude-sonnet-4-6');});- it('patchVendorPrefsPreservingModelChoice:会话同步同一 model 保留旧显式选模标记', async () => {+ it('已有任务换模走 patchVendorPrefs,下次新建跟随这次选择', async () => {const m1 = await loadModule();- m1.patchVendorPrefs('cc', { model: 'claude-opus-4-8' });- expect(m1.getDraft().modelChosenByVendor).toEqual({ cc: true });-- m1.patchVendorPrefsPreservingModelChoice('cc', {- model: 'claude-opus-4-8',- effort: 'high',- });+ m1.patchVendorPrefs('cc', { model: 'claude-sonnet-4-6' });+ m1.patchVendorPrefs('cc', { model: 'claude-opus-4-8', effort: 'high' });expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-opus-4-8');expect(m1.getDraft().lastByVendor.cc.effort).toBe('high');diff --git a/apps/desktop/src/renderer/__tests__/scheduleDefaultModel.test.ts b/apps/desktop/src/renderer/__tests__/scheduleDefaultModel.test.tsindex dab3b385b9..d5ec93feae 100644--- a/apps/desktop/src/renderer/__tests__/scheduleDefaultModel.test.ts+++ b/apps/desktop/src/renderer/__tests__/scheduleDefaultModel.test.ts@@ -114,40 +114,37 @@ describe('getScheduleDefaultModel 三级回退', () => {expect(getScheduleDefaultModel('claude-code')).toBe('claude-sonnet-4-6');});- it('三级:已有会话同步 New Maker 草稿默认不打显式选择标记 → 调度仍走 Sonnet 兜底', async () => {+ it('三级:已有任务只改思考档不打显式选择标记 → 调度仍走 Sonnet 兜底', async () => {const draft = await import('@/state/newMakerDraft');draft.patchVendorPrefsPreservingModelChoice('cc', {- model: 'claude-opus-4-8',effort: 'high',});const { getScheduleDefaultModel } = await loadModule();- expect(draft.getDraft().lastByVendor.cc.model).toBe('claude-opus-4-8');expect(draft.getPersistedVendorModel('cc')).toBe('');expect(getScheduleDefaultModel('claude-code')).toBe('claude-sonnet-4-6');});- it('三级:旧 New Maker 显式选模被会话同步覆盖后不污染调度默认模型', async () => {+ it('三级:已有任务换模后调度跟随这次选择', async () => {const draft = await import('@/state/newMakerDraft');draft.patchVendorPrefs('cc', { model: 'claude-opus-4-8' });expect(draft.getPersistedVendorModel('cc')).toBe('claude-opus-4-8');- draft.patchVendorPrefsPreservingModelChoice('cc', {+ draft.patchVendorPrefs('cc', {model: 'claude-sonnet-4-7',effort: 'high',});const { getScheduleDefaultModel } = await loadModule();expect(draft.getDraft().lastByVendor.cc.model).toBe('claude-sonnet-4-7');- expect(draft.getPersistedVendorModel('cc')).toBe('');- expect(getScheduleDefaultModel('claude-code')).toBe('claude-sonnet-4-6');+ expect(draft.getPersistedVendorModel('cc')).toBe('claude-sonnet-4-7');+ expect(getScheduleDefaultModel('claude-code')).toBe('claude-sonnet-4-7');});- it('三级:旧 New Maker 显式选模被同 model 会话同步更新后仍作为调度默认模型', async () => {+ it('三级:旧显式选模后只改思考档,调度仍用原来的模型', async () => {const draft = await import('@/state/newMakerDraft');draft.patchVendorPrefs('cc', { model: 'claude-opus-4-8' });draft.patchVendorPrefsPreservingModelChoice('cc', {- model: 'claude-opus-4-8',effort: 'high',});diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 794636c46b..4d95719f3b 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -296,6 +296,7 @@ import {} from '@/state/providerModelMemory';import {getDraft,+ patchVendorPrefs,patchVendorPrefsPreservingModelChoice,setEffortForModel,setFastModeForModel,@@ -5181,6 +5182,8 @@ export function ChatInput({activeProviderId?: string | null;memoryProviderId?: string | null;remoteDeviceId?: string;+ /** 已有任务里换模 / 换来源时为 true,下次新建跟随这次选择。只改思考档 / Fast 保持 false。 */+ markModelChoice?: boolean;} = {},) => {if (!sessionId || !currentModelAgentKind || !modelId) return;@@ -5190,6 +5193,7 @@ export function ChatInput({opts.memoryProviderId !== undefined ? opts.memoryProviderId : effectiveSourceId;const remoteDeviceId =opts.remoteDeviceId ?? getSessionDeviceId(sessionId) ?? deviceLinkDeviceId;+ const markModelChoice = opts.markModelChoice === true;if (!remoteDeviceId) {const vendor =currentModelAgentKind === 'codex'@@ -5197,8 +5201,10 @@ export function ChatInput({: currentModelAgentKind === 'pi'? 'pi': 'cc';- patchVendorPrefsPreservingModelChoice(vendor, {- model: modelId,+ const persistPrefs = markModelChoice ? patchVendorPrefs : patchVendorPrefsPreservingModelChoice;+ persistPrefs(vendor, {+ // 只改思考档 / Fast 不得改写下次新建用的模型;换模才带 model 并打标记。+ ...(markModelChoice ? { model: modelId } : {}),providerId: activeProviderId ?? null,...(patch.effort !== undefined ? { effort: patch.effort } : {}),});@@ -5221,7 +5227,7 @@ export function ChatInput({providerId: activeProviderId ?? '',modelId,active: true,- markModelChoice: false,+ markModelChoice,...(patch.effort !== undefined ? { effort: patch.effort } : {}),...(patch.fast !== undefined ? { fast: patch.fast } : {}),},@@ -5700,7 +5706,7 @@ export function ChatInput({syncSessionDraftModelPrefs(newModelId,{ effort: newEffort, fast: fastPersisted ? restoredFast : fastMode },- { remoteDeviceId: sourceRemoteDeviceId },+ { remoteDeviceId: sourceRemoteDeviceId, markModelChoice: true },);if (remoteDeferred && isSourceSessionCurrent()) {toast.success(t('newChat.chatInput.credentialSwitchDeferred'), { duration: 4000 });@@ -5734,7 +5740,9 @@ export function ChatInput({// 默认 success 1200ms 读不完这句;拉长到 4s。toast.success(t('newChat.chatInput.credentialSwitchDeferred'), { duration: 4000 });}- syncSessionDraftModelPrefs(newModelId, { effort: newEffort, fast: restoredFast });+ syncSessionDraftModelPrefs(newModelId, { effort: newEffort, fast: restoredFast }, {+ markModelChoice: true,+ });if (currentModelAgentKind && effectiveSourceId) {modelMemory?.setFast(currentModelAgentKind,@@ -6104,6 +6112,7 @@ export function ChatInput({activeProviderId: newProviderId,memoryProviderId: newProviderId,remoteDeviceId: sourceRemoteDeviceId,+ markModelChoice: true,},);onModelDidChange?.(targetModel);@@ -6161,7 +6170,11 @@ export function ChatInput({syncSessionDraftModelPrefs(modelId,{ effort: eff, fast: restoredFast },- { activeProviderId: newProviderId, memoryProviderId: newProviderId },+ {+ activeProviderId: newProviderId,+ memoryProviderId: newProviderId,+ markModelChoice: true,+ },);if (currentModelAgentKind && newProviderId) {modelMemory?.setFast(currentModelAgentKind, newProviderId, modelId, restoredFast);diff --git a/apps/desktop/src/renderer/state/newMakerDraft.ts b/apps/desktop/src/renderer/state/newMakerDraft.tsindex 92c12e9824..f456167c8e 100644--- a/apps/desktop/src/renderer/state/newMakerDraft.ts+++ b/apps/desktop/src/renderer/state/newMakerDraft.ts@@ -144,13 +144,13 @@ export interface NewMakerDraft {/** 每个 vendor 的"上次使用配置"——切回该 vendor 时自动恢复。 */lastByVendor: Record<MakerVendor, VendorPrefs>;/**- * 用户是否在 New Maker 界面**显式**选过该 vendor 的模型。+ * 用户是否**显式**选过该 vendor 的模型(新建页 picker,或已有任务里换模)。* lastByVendor 整个快照随任意 draft 写入落盘,model 即使从没被用户碰过也会带上* sanitize 的种子默认值 —— 仅凭 lastByVendor 无法区分"真选过"和"默认回填"。* 调度任务默认模型的三级回退(getPersistedVendorModel 消费)只认这里标记过的* vendor,否则全新 / 没用过该 vendor 的用户会被对话侧 Opus 种子默认顶掉- * 成本保守兜底。patchVendorPrefs 收到 New Maker 显式 model 时置 true;会话同步 model- * 覆盖 lastByVendor 时清掉,避免把会话侧模型误当成 New Maker picker 选择。+ * 成本保守兜底。patchVendorPrefs 收到显式 model 时置 true;只改思考档 / Fast+ * 的会话回写走 patchVendorPrefsPreservingModelChoice,不得清掉已有标记。*/modelChosenByVendor: Partial<Record<MakerVendor, boolean>>;}@@ -741,19 +741,12 @@ function patchVendorPrefsInternal(const modelChosen = { ...currentDraft.modelChosenByVendor };if (typeof patch.model === 'string' && patch.model.length > 0) {if (opts.markModelChoice) {- // New Maker 显式 model 选择 → 打标记(见 modelChosenByVendor 注释)。+ // 新建页 picker 或已有任务换模 → 打标记,下次新建跟随这次选择,不再回落区域默认。modelChosen[vendor] = true;- } else if (- currentDraft.modelChosenByVendor[vendor] &&- currentDraft.lastByVendor[vendor].model === patch.model- ) {- // 会话同步的是同一个 model:保留原 New Maker picker 选择语义。- modelChosen[vendor] = true;- } else {- // 会话同步 model 会覆盖 lastByVendor[vendor].model。若 model 发生变化,旧标记已不能继续代表- // "New Maker picker 选过这个 model",否则 scheduler 会把会话侧模型误当成显式选择。- delete modelChosen[vendor];}+ // markModelChoice=false 只回写思考档 / 来源等非选模字段。即便 patch 里带着+ // 当前任务的 model id,也不得把已有标记清掉,否则已有任务里随手换模 / 改档+ // 会让下次新建重新落到服务端区域默认。}currentDraft = {...currentDraft,@@ -772,9 +765,10 @@ export function patchVendorPrefs(vendor: MakerVendor, patch: Partial<VendorPrefs}/**- * 已创建会话把最近一次成功应用的模型偏好同步回 New Maker 草稿默认时使用。- * 这会更新 lastByVendor 供下一次新建聊天复用,但不把 modelChosenByVendor 打成- * "用户在 New Maker 显式选过模型",避免影响 scheduler 的成本保守默认模型兜底。+ * 已创建任务把思考档等非选模偏好同步回新建草稿时使用。+ * 更新 lastByVendor,但不把 modelChosenByVendor 打成「显式选过模型」:+ * 只改思考档不能把区域默认升级成用户选择,也不得清掉已有的选模标记。+ * 已有任务里换模型应走 patchVendorPrefs,让下次新建跟随这次选择。*/export function patchVendorPrefsPreservingModelChoice(vendor: MakerVendor,@@ -859,11 +853,11 @@ export function getCurrentVendorPrefs(): VendorPrefs {* 与 getDraft().lastByVendor[v].model 的区别:后者永远非空 —— sanitize 会用* getDefaultModelForVendor 兜底填充,且 lastByVendor 整个快照随任意 draft 写入* 落盘,即使用户从没碰过该 vendor 的模型,持久化里也躺着种子默认值。- * 所以这里要求 modelChosenByVendor[vendor] === true(只在 patchVendorPrefs- * 收到显式 model 时打的标)才返回,否则一律 ''。+ * 所以这里要求 modelChosenByVendor[vendor] === true(新建页 picker 或已有+ * 任务换模经 patchVendorPrefs 打的标)才返回,否则一律 ''。* 调度任务的默认模型三级回退(useScheduleForm getScheduleDefaultModel)依赖这个* 区分:没显式选过的用户应落到调度自己的成本保守兜底(Sonnet),而不是被- * 对话侧的 Opus 默认顶掉。读 raw localStorage 而非 getDraft(),解析失败 → ''。+ * 对话侧的 Opus 种子默认顶掉。读 raw localStorage 而非 getDraft(),解析失败 → ''。*/export function getPersistedVendorModel(vendor: MakerVendor): string {if (typeof window === 'undefined') return '';