Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(scheduler): preserve model locations across template and save flows
Yuewei-LLe2f61b7e7b9e
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.tsindex fe5c0e6261..e0579b1d22 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.ts@@ -177,8 +177,12 @@ describe('scheduled model selection IPC compatibility', () => {it.each([{ model: '', rebind: false }, { model: ' ', rebind: false }, { model: '', rebind: true },- ])('saves and reopens a Mobile bound form after clearing its model: %j', async ({ model, rebind }) => {- let saved = { ...existing, ...fullForm, name: 'Bound', prompt: 'Run',+ // Integration, PR #6830: clearing a saved location through JSON must restore+ // follow mode, not produce an incomplete explicit local selection.+ { model: '', rebind: false, modelAgentDeviceId: 'shared:owner' },+ { model: '', rebind: false, modelAgentDeviceId: '' },+ ])('saves and reopens a Mobile bound form after clearing its model: %j', async ({ model, rebind, modelAgentDeviceId }) => {+ let saved = { ...existing, ...fullForm, name: 'Bound', prompt: 'Run', modelAgentDeviceId,recurring: true, timezone: 'UTC', status: 'active', workspaceKind: 'dialogue' } as Schedule;const storage = {get: vi.fn(async () => ({ ...saved })),@@ -199,7 +203,7 @@ describe('scheduled model selection IPC compatibility', () => {expect(wire).not.toHaveProperty('modelAgentKind');const result = await handlers.get('maker:schedule:update')!(null, existing.id, wire);expect(result).toMatchObject({ agentKind: 'codex', targetSessionId, persistentSession: rebind,- modelAgentKind: undefined, model: undefined, providerId: undefined, effort: 'high', fastMode: false });+ modelAgentKind: undefined, modelAgentDeviceId: undefined, model: undefined, providerId: undefined, effort: 'high', fastMode: false });expect(storage.update).toHaveBeenCalledTimes(1);const reopened = createMobileScheduleDraft({ ...saved, source: 'user' });expect(reopened).toMatchObject({ agentKind: 'codex', model: '', modelAgentKind: undefined });diff --git a/apps/desktop/src/main/maker-ipc/schedule.ts b/apps/desktop/src/main/maker-ipc/schedule.tsindex 35916ba1ce..ece7bc6b0e 100644--- a/apps/desktop/src/main/maker-ipc/schedule.ts+++ b/apps/desktop/src/main/maker-ipc/schedule.ts@@ -279,8 +279,12 @@ export function normalizeLegacyDeviceLinkModelSelection(|| !Object.prototype.hasOwnProperty.call(patch, 'notify')|| !(patch.targetSessionId ?? existing.targetSessionId)) return patch;const model = patch.model?.trim() || undefined;- if (patch.agentKind === existing.agentKind && model === (existing.model?.trim() || undefined)) return patch;+ // A full form with no model follows its task. Its JSON-safe empty location+ // clears the old selection; location-only partial patches still select local.+ const clearsLocation = !model && patch.modelAgentDeviceId === '';+ if (!clearsLocation && patch.agentKind === existing.agentKind && model === (existing.model?.trim() || undefined)) return patch;return { ...patch, modelAgentKind: model ? patch.agentKind : undefined,+ ...(clearsLocation ? { modelAgentDeviceId: undefined } : {}),// The old bound form omits empty model/provider/effort and has no Fast control.// Clear the previous route when the visible selection changes instead of retaining// a provider or Fast preference belonging to the old Harness/model.diff --git a/apps/desktop/src/renderer/features/scheduler/components/__tests__/ThreadPickerInline.test.tsx b/apps/desktop/src/renderer/features/scheduler/components/__tests__/ThreadPickerInline.test.tsxindex c28db947f0..de8df2f541 100644--- a/apps/desktop/src/renderer/features/scheduler/components/__tests__/ThreadPickerInline.test.tsx+++ b/apps/desktop/src/renderer/features/scheduler/components/__tests__/ThreadPickerInline.test.tsx@@ -16,6 +16,8 @@ const mocks = vi.hoisted(() => ({}));vi.mock('@/lib/sessionService', () => ({ list: mocks.list }));+// These cases mount the task picker only; model location state is unrelated.+vi.mock('@/hooks/useModelRouteDevices', () => ({ useModelRouteDevices: () => ({ devices: undefined }) }));vi.mock('react-i18next', () => ({useTranslation: () => ({ t: (key: string) => key }),}));diff --git a/apps/desktop/src/renderer/features/scheduler/hooks/__tests__/useScheduleForm.validate.test.tsx b/apps/desktop/src/renderer/features/scheduler/hooks/__tests__/useScheduleForm.validate.test.tsxindex a063b97676..f9ea9317f3 100644--- a/apps/desktop/src/renderer/features/scheduler/hooks/__tests__/useScheduleForm.validate.test.tsx+++ b/apps/desktop/src/renderer/features/scheduler/hooks/__tests__/useScheduleForm.validate.test.tsx@@ -56,6 +56,32 @@ describe('saved automation model selection', () => {category: 'code-quality', source: 'builtin',};+ // PR #6830: the hook used to reset location separately from the retained route.+ // Unit/jsdom: apply a same-Harness template to a shared choice, then serialize it.+ it('keeps the shared route when a template only repeats the current Harness', () => {+ const { result } = renderHook(() => useScheduleForm(null));+ const route = { agentKind: 'claude-code' as const, model: 'remote-model', providerId: 'remote-provider',+ modelAgentDeviceId: 'shared:owner', effort: 'high' as const, fastMode: true };+ act(() => result.current.selectModelConfiguration(route));+ act(() => result.current.applyTemplateAgentFields({ ...template, agentKind: route.agentKind }));+ expect(result.current.toInput()).toMatchObject({ modelAgentDeviceId: route.modelAgentDeviceId,+ agentKind: route.agentKind, model: route.model, providerId: route.providerId });+ });++ // A partial local template must not combine its model/provider with the old share.+ it.each([+ { model: 'local-model' },+ { providerId: 'local-provider' },+ ])('discards inherited shared fields when applying a local route %j', (override) => {+ const { result } = renderHook(() => useScheduleForm(null));+ act(() => result.current.selectModelConfiguration({ agentKind: 'claude-code', model: 'remote-model',+ providerId: 'remote-provider', modelAgentDeviceId: 'shared:owner', effort: 'high', fastMode: true }));+ act(() => result.current.applyTemplateAgentFields({ ...template, ...override }));+ expect(result.current.form).toMatchObject({ ...override, modelAgentDeviceId: '' });+ expect(result.current.form.model).not.toBe('remote-model');+ expect(result.current.form.providerId).not.toBe('remote-provider');+ });+it.each(['codex', 'pi'] as const)('saves the %s template Harness with its model after binding a task', (agentKind) => {const { result } = renderHook(() => useScheduleForm(null));act(() => result.current.selectBoundSession({ id: 'bound-codex', agentKind: 'codex' } as Session));diff --git a/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleForm.ts b/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleForm.tsindex 272fdbcfa0..ac3f9b83a2 100644--- a/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleForm.ts+++ b/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleForm.ts@@ -374,8 +374,7 @@ export function useScheduleForm(initial: Schedule | null = null): UseScheduleForgetAgentPrefs: getScheduleAgentPrefs,});// A template that supplies a model is an explicit selection, even while following a bound task.- return { ...f, ...selection, modelAgentKind: selection.model.trim() ? selection.agentKind : undefined,- modelAgentDeviceId: template.model || template.agentKind || template.providerId ? '' : f.modelAgentDeviceId };+ return { ...f, ...selection, modelAgentKind: selection.model.trim() ? selection.agentKind : undefined };});}, []);diff --git a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleFormLogic.test.ts b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleFormLogic.test.tsindex ed072037e1..45f9dc7938 100644--- a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleFormLogic.test.ts+++ b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleFormLogic.test.ts@@ -712,6 +712,7 @@ describe('resolveTemplateAgentFields', () => {expect(fields).toEqual({agentKind: 'claude-code',+ modelAgentDeviceId: '',model: 'claude-sonnet-4-6',providerId: 'anthropic',effort: 'medium',@@ -754,6 +755,7 @@ describe('resolveTemplateAgentFields', () => {expect(fields).toEqual({agentKind: 'claude-code',+ modelAgentDeviceId: '',model: 'claude-opus-4-8',providerId: '',effort: 'xhigh',diff --git a/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts b/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.tsindex 90fe0df90f..a4575597bd 100644--- a/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts+++ b/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts@@ -404,31 +404,36 @@ export function resolveTemplateAgentFields(form: ScheduleFormState,template: Pick<ScheduleTemplate, 'agentKind' | 'model' | 'providerId' | 'effort' | 'fastMode'>,defaults: TemplateAgentDefaults,-): Pick<ScheduleFormState, 'agentKind' | 'model' | 'providerId' | 'effort' | 'fastMode'> {+): Pick<ScheduleFormState, 'agentKind' | 'model' | 'providerId' | 'effort' | 'fastMode' | 'modelAgentDeviceId'> {const agentKind = template.agentKind ?? form.agentKind;const agentChanged = agentKind !== form.agentKind;- const agentPrefs = agentChanged ? defaults.getAgentPrefs(agentKind) : null;const templateModel = typeof template.model === 'string' ? template.model.trim() : '';const templateProviderId = typeof template.providerId === 'string' ? template.providerId.trim() : undefined;+ const selectsLocalRoute = agentChanged || !!templateModel || templateProviderId !== undefined;+ // Retaining a route also retains its location. An explicit local template must+ // resolve missing fields from local defaults, never from the previous share.+ const useLocalDefaults = agentChanged || (!!form.modelAgentDeviceId && selectsLocalRoute);+ const agentPrefs = useLocalDefaults ? defaults.getAgentPrefs(agentKind) : null;const templateEffort = template.effort && isEffortValue(template.effort) ? template.effort : undefined;- // 模板没给模型、换了 agent 时用默认路由:限定在模板 / 任务记忆的来源内,模型与来源整对应用。+ // 模板没给模型、切换引擎或回到本机时用本机默认路由,模型与来源整对应用。const defaultRoute =- agentChanged && !templateModel+ useLocalDefaults && !templateModel? defaults.getDefaultRoute(agentKind, templateProviderId ?? (agentPrefs?.providerId || null)): null;return {agentKind,- model: templateModel || (agentChanged ? (defaultRoute?.model ?? '') : form.model),+ modelAgentDeviceId: selectsLocalRoute ? '' : form.modelAgentDeviceId,+ model: templateModel || (useLocalDefaults ? (defaultRoute?.model ?? '') : form.model),providerId:templateProviderId ??- (agentChanged+ (useLocalDefaults? defaultRoute? (defaultRoute.providerId ?? ''): (agentPrefs?.providerId ?? ''): form.providerId),- effort: templateEffort ?? (agentChanged ? (agentPrefs?.effort ?? '') : form.effort),- fastMode: template.fastMode ?? (agentChanged ? (agentPrefs?.fastMode ?? false) : form.fastMode),+ effort: templateEffort ?? (useLocalDefaults ? (agentPrefs?.effort ?? '') : form.effort),+ fastMode: template.fastMode ?? (useLocalDefaults ? (agentPrefs?.fastMode ?? false) : form.fastMode),};}diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex ad87f339c9..ef73415262 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -3077,6 +3077,8 @@ namespace + id 下同一插件的有界 JSON 请求;`deviceSync: true` 是独`Schedule` / 创建与更新输入增量增加可选 `modelAgentDeviceId`:缺省保持旧版绑定任务的位置继承,空字符串表示自动化所在电脑,非空使用既有远程/分享 Agent 标识。SQLite 新增可空文本列,SQL NULL 对应缺省;项目 `version: 1` 配置同样允许该字段,旧文件无需改写。+绑定任务或持续模式的 Agent 自动化显式选本机时也须有 `modelAgentKind` 与 `model`;不完整选择在保存前拒绝,+不把“选本机”误作继承绑定任务的位置。更新可沿用已存的完整选择,恢复跟随时清除显式选择。`maker:get-capabilities` 返回 `supportsScheduleAgentDeviceSelection: true`。新调用方只有明确看到此能力才向其它电脑提交位置选择;旧端未知字段会被忽略,禁止静默降级。旧调用方修改新自动化的非模型字段仍保留位置;修改模型路线却未携带已固定的位置时拒绝保存,diff --git a/docs/product-rules/agent-user-parity.md b/docs/product-rules/agent-user-parity.mdindex fb956037b2..e6821b7860 100644--- a/docs/product-rules/agent-user-parity.md+++ b/docs/product-rules/agent-user-parity.md@@ -52,7 +52,7 @@| 协同 / Worker | 为 Worker 新建 worktree、指定源分支、归档时回收 | 有 | 无 || 定时任务 | 列出、详情、运行记录、修改、暂停、恢复、删除、立即运行 | 有 | 有(2026-10-14) || 定时任务 | 新建、安装检查脚本 | 有 | 无 |-| 定时任务 | 选择远程/分享供应商模型(运行位置、引擎、模型与速度) | 有 | 有(目标电脑须支持 `supportsScheduleAgentDeviceSelection`) |+| 定时任务 | 选择远程/分享供应商模型(运行位置、引擎、模型与速度);绑定任务或持续模式切回本机须保留完整引擎/模型选择 | 有 | 有(目标电脑须支持 `supportsScheduleAgentDeviceSelection`) || 定时任务 | 删除单条运行记录、标记已读 | 无 | 无 || 项目 | 列出、登记、改名、移除;工作目录列表 | 有 | 无 || 伙伴 | 发现伙伴、伙伴间消息 | 有 | 有 |diff --git a/packages/lizi-mcps/src/scheduler/create.ts b/packages/lizi-mcps/src/scheduler/create.tsindex 8842d11135..e1fd351c55 100644--- a/packages/lizi-mcps/src/scheduler/create.ts+++ b/packages/lizi-mcps/src/scheduler/create.ts@@ -92,7 +92,7 @@ export function registerScheduleCreateTool(agentKind: z.enum(AGENT_KIND).describe('claude-code / codex / pi'),modelAgentKind: z.enum(AGENT_KIND).optional().describe('显式模型选择的引擎;绑定任务仅在下次执行时临时切换,结束后恢复'),fastMode: z.union([z.boolean(), z.literal('ultrafast')]).optional().describe('模型速度:false 标准、true 快速、ultrafast 超快;按所选模型支持的档位执行'),- modelAgentDeviceId: z.string().optional().describe('模型运行位置:远程或分享供应商的 agentDeviceId;空字符串=自动化所在电脑,省略=沿用绑定任务。远程选择须同时传 modelAgentKind、model、providerId;工作目录和工具仍属于自动化所在电脑'),+ modelAgentDeviceId: z.string().optional().describe('模型运行位置:远程或分享供应商的 agentDeviceId;空字符串=自动化所在电脑,省略=沿用绑定任务。远程选择须同时传 modelAgentKind、model、providerId;绑定任务或持续模式显式选择本机也须传 modelAgentKind 和 model;工作目录和工具仍属于自动化所在电脑'),kind: z.literal('cron').default('cron')diff --git a/packages/lizi-mcps/src/scheduler/update.ts b/packages/lizi-mcps/src/scheduler/update.tsindex 270196f1cb..786567e162 100644--- a/packages/lizi-mcps/src/scheduler/update.ts+++ b/packages/lizi-mcps/src/scheduler/update.ts@@ -42,7 +42,7 @@ export function registerScheduleUpdateTool(agentKind: z.enum(AGENT_KIND).optional(),modelAgentKind: z.enum(AGENT_KIND).nullable().optional().describe('显式模型选择的引擎;null 清除覆盖'),fastMode: z.union([z.boolean(), z.literal('ultrafast')]).optional().describe('模型速度:false 标准、true 快速、ultrafast 超快;省略不修改'),- modelAgentDeviceId: z.string().nullable().optional().describe('模型运行位置:远程或分享供应商的 agentDeviceId;空字符串=自动化所在电脑,null=恢复沿用绑定任务,省略=不修改。远程选择须同时指定 modelAgentKind、model、providerId'),+ modelAgentDeviceId: z.string().nullable().optional().describe('模型运行位置:远程或分享供应商的 agentDeviceId;空字符串=自动化所在电脑,null=恢复沿用绑定任务,省略=不修改。远程选择须同时指定 modelAgentKind、model、providerId;绑定任务或持续模式切回本机也须有 modelAgentKind 和 model,可沿用已保存的完整选择'),kind: z.literal('cron').optional(),model: z.string()diff --git a/packages/maker-scheduler/src/__tests__/scheduler.test.ts b/packages/maker-scheduler/src/__tests__/scheduler.test.tsindex df4a0cf6b8..883227c254 100644--- a/packages/maker-scheduler/src/__tests__/scheduler.test.ts+++ b/packages/maker-scheduler/src/__tests__/scheduler.test.ts@@ -237,6 +237,33 @@ describe('Scheduler', () => {await expect(h.scheduler.create({ ...baseInput, modelAgentDeviceId: 'shared:owner' })).rejects.toThrow('remote model selection');});+ // Unit, PR #6830 review: a legacy bound automation has no explicit Harness.+ // A location-only local patch used to save successfully but still run remotely.+ it('rejects an incomplete local selection on a bound automation without changing its saved route', async () => {+ const legacy = { ...baseInput, agentKind: 'codex' as const, targetSessionId: 'remote-task', model: 'same-model', providerId: 'openai' };+ const saved = await h.scheduler.create(legacy);+ await expect(h.scheduler.update(saved.id, { modelAgentDeviceId: '' })).rejects.toThrow('bound task');+ expect(await h.scheduler.get(saved.id)).toEqual(saved);+ await expect(h.scheduler.create({ ...legacy, modelAgentDeviceId: '' })).rejects.toThrow('bound task');+ expect(await h.scheduler.update(saved.id, { modelAgentDeviceId: '', modelAgentKind: 'codex' }))+ .toMatchObject({ modelAgentDeviceId: '', modelAgentKind: 'codex', model: 'same-model' });+ const followed = await h.scheduler.update(saved.id, {+ modelAgentDeviceId: undefined, modelAgentKind: undefined, model: undefined, providerId: undefined,+ });+ expect(followed.modelAgentDeviceId).toBeUndefined();+ expect(followed.modelAgentKind).toBeUndefined();+ });++ // Unit: persistent schedules become bound after their first run. Accepting an+ // incomplete local selection must not make that required internal update fail.+ it('requires an executable local selection before a persistent automation first binds', async () => {+ const persistent = { ...baseInput, persistentSession: true, modelAgentDeviceId: '', model: 'local-model' };+ await expect(h.scheduler.create(persistent)).rejects.toThrow('bound task');+ const saved = await h.scheduler.create({ ...persistent, modelAgentKind: 'codex' });+ expect(await h.scheduler.update(saved.id, { targetSessionId: 'first-run-task' }))+ .toMatchObject({ targetSessionId: 'first-run-task', modelAgentDeviceId: '', modelAgentKind: 'codex' });+ });+// Unit (model-selector-unified.md §3): update/runNow must preserve an active// run and history while later runs use the saved route. The former one-way// case missed same-model/provider remote -> local -> remote -> local changes,diff --git a/packages/maker-scheduler/src/engine/scheduler.ts b/packages/maker-scheduler/src/engine/scheduler.tsindex c68abf11ac..76665bac4e 100644--- a/packages/maker-scheduler/src/engine/scheduler.ts+++ b/packages/maker-scheduler/src/engine/scheduler.ts@@ -59,6 +59,13 @@ function validateScheduleExecutionShape(schedule: Pick<Schedule, 'executionMode' | 'scriptConfig' | 'workspaceKind' | 'workingDir' | 'useWorktree' | 'targetSessionId' | 'persistentSession' | 'prompt' | 'silentWhenIdle' | 'modelAgentKind' | 'modelAgentDeviceId' | 'model' | 'providerId'>,opts: { checkAgentPrompt: boolean } = { checkAgentPrompt: true },): void {+ // A bound agent run only overrides its task's location with an explicit model+ // selection. Reject a local-only patch instead of silently inheriting remote.+ if (schedule.modelAgentDeviceId === '' && (schedule.targetSessionId || schedule.persistentSession) &&+ (schedule.executionMode ?? 'agent') === 'agent' &&+ (!schedule.modelAgentKind || !schedule.model?.trim())) {+ throw new Error('Explicit scheduled Agent location for a bound task requires a Harness and model');+ }if (schedule.modelAgentDeviceId !== undefined && (typeof schedule.modelAgentDeviceId !== 'string' ||(schedule.modelAgentDeviceId !== '' && (!schedule.modelAgentDeviceId.trim() ||diff --git a/packages/maker-shared/src/__tests__/scheduleForm.test.ts b/packages/maker-shared/src/__tests__/scheduleForm.test.tsindex 72b8f81b1b..484fe4869e 100644--- a/packages/maker-shared/src/__tests__/scheduleForm.test.ts+++ b/packages/maker-shared/src/__tests__/scheduleForm.test.ts@@ -45,6 +45,30 @@ function schedule(patch: Partial<RemoteSchedule> = {}): RemoteSchedule {}describe('mobile schedule form model', () => {+ // PR #6830, unit: apply/serialize is the shared production entry point. Existing+ // template cases had no remote location and missed an unchanged route becoming local.+ it('preserves the shared route when a template keeps the same Harness', () => {+ const route = { agentKind: 'claude-code' as const, modelAgentKind: 'claude-code' as const,+ model: 'remote-model', providerId: 'remote-provider', modelAgentDeviceId: 'shared:owner' };+ const draft = createMobileScheduleDraft(schedule(route));+ const selected = applyTemplateToMobileScheduleDraft(draft, { id: 'same', name: 'Same Harness',+ description: '', category: 'custom', source: 'user', agentKind: route.agentKind });+ expect(JSON.parse(JSON.stringify(buildMobileScheduleInput(selected)))).toMatchObject(route);+ });++ it.each([+ { model: 'local-model' },+ { providerId: 'local-provider' },+ ])('does not inherit shared fields into a partial local template %j', (override) => {+ const draft = createMobileScheduleDraft(schedule({ modelAgentKind: 'claude-code',+ model: 'remote-model', providerId: 'remote-provider', modelAgentDeviceId: 'shared:owner' }));+ const selected = applyTemplateToMobileScheduleDraft(draft, { id: 'local', name: 'Local route',+ description: '', category: 'custom', source: 'user', ...override });+ expect(selected).toMatchObject({ ...override, modelAgentDeviceId: '' });+ expect(selected.model).not.toBe('remote-model');+ expect(selected.providerId).not.toBe('remote-provider');+ });+it('builds a desktop-compatible create input for recurring project schedules', () => {const draft = createMobileScheduleDraft(null, { fallbackWorkingDir: '/repo/xdt-maker' });const input = buildMobileScheduleInput({diff --git a/packages/maker-shared/src/scheduleForm.ts b/packages/maker-shared/src/scheduleForm.tsindex a219484da3..1ea14fcbce 100644--- a/packages/maker-shared/src/scheduleForm.ts+++ b/packages/maker-shared/src/scheduleForm.ts@@ -213,7 +213,11 @@ export function applyTemplateToMobileScheduleDraft(paramValues: Record<string, string> = {},): MobileScheduleDraft {const agentKind = template.agentKind ?? draft.agentKind;- const model = template.model ?? (draft.agentKind === agentKind ? draft.model : '');+ const selectsLocalRoute = agentKind !== draft.agentKind || !!template.model?.trim() || template.providerId !== undefined;+ // Keep location with an inherited route; local template overrides must not+ // borrow the missing model/provider from a remote catalog.+ const keepRoute = agentKind === draft.agentKind && !(draft.modelAgentDeviceId && selectsLocalRoute);+ const model = template.model ?? (keepRoute ? draft.model : '');return {...draft,name: template.name || draft.name,@@ -227,12 +231,12 @@ export function applyTemplateToMobileScheduleDraft(agentKind,// A template producing a model is an explicit choice, including a legacy bound draft....(model.trim() || draft.modelAgentKind ? { modelAgentKind: agentKind } : {}),- modelAgentDeviceId: template.model || template.agentKind || template.providerId+ modelAgentDeviceId: selectsLocalRoute? (draft.modelAgentDeviceId === undefined ? undefined : '') : draft.modelAgentDeviceId,model,// 模板若固定了 provider,必须随模板一起落到新建任务;否则 Pi 的空模型会在// host 侧按错误的默认来源解析。模板未指定时才保留同 agent 的用户选择。- providerId: template.providerId ?? (draft.agentKind === agentKind ? draft.providerId : ''),+ providerId: template.providerId ?? (keepRoute ? draft.providerId : ''),effort: template.effort ?? '',fastMode: (template.fastMode === 'ultrafast' ? 'ultrafast' : template.fastMode === true),useWorktree: template.useWorktree ?? draft.useWorktree,