Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
merge: preserve scheduled model routing when syncing main
Yuewei-LLfe1c82ab419f
diff --cc apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.tsindex a36ccdf15b,edb5857779..4e713a952e--- a/apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/model-route-guard-live.test.ts@@@ -4,13 -4,11 +4,13 @@@ const h = vi.hoisted(() => (catalog: { modelRegistry: {} },listProviders: vi.fn(),effectiveSourceIdForModel: vi.fn(),+ readDeviceProviderViews: vi.fn(),}));+vi.mock('@cindy/model-providers', async (importOriginal) => ({findCatalogModel: (await importOriginal<typeof import('@cindy/model-providers')>()).findCatalogModel,- connectedProvidersForAgent: vi.fn(() => []),+ connectedProvidersForAgent: (await importOriginal<typeof import('@cindy/model-providers')>()).connectedProvidersForAgent,effectiveSourceIdForModel: h.effectiveSourceIdForModel,getModel: vi.fn(() => null),isExclusiveXaiModelId: (model: string | null | undefined) =>@@@ -47,24 -45,6 +47,24 @@@ importresolveLenientSessionRoute,} from '../model-route-guard-live.js';+// Unit: use the remote authorized catalog even when the local provider has the+// same id. An offline/revoked share must fail before trying local credentials.+describe('scheduled remote model catalog', () => {+ it('resolves only the selected computer catalog and preserves its axes', async () => {+ vi.clearAllMocks();- h.readDeviceProviderViews.mockResolvedValue([{ id: 'shared-provider', connected: true, agents: ['pi'],++ h.readDeviceProviderViews.mockResolvedValue([{ id: 'shared-provider', connected: true, agents: ['pi'], routing: { pi: {} },+ models: { pi: [{ id: 'remote-model', efforts: ['high'], defaultEffort: 'high', supportsFastMode: false }] } }]);+ const choice = { agentKind: 'pi' as const, agentDeviceId: 'shared:owner', model: 'remote-model',+ providerId: 'shared-provider', effort: 'ultra' as const, fastMode: true };+ await expect(resolveScheduledModelSelectionLive(choice, h.readDeviceProviderViews)).resolves.toMatchObject({ ...choice, effort: 'high', fastMode: false });+ expect(h.listProviders).not.toHaveBeenCalled();+ expect(h.readDeviceProviderViews).toHaveBeenCalledWith('shared:owner');+ h.readDeviceProviderViews.mockRejectedValueOnce(new Error('[REMOTE_AGENT_SHARE_REMOVED] removed'));+ await expect(resolveScheduledModelSelectionLive(choice, h.readDeviceProviderViews)).rejects.toThrow('REMOTE_AGENT_SHARE_REMOVED');+ expect(h.listProviders).not.toHaveBeenCalled();+ });+});+describe('resolveDefaultScheduleRoute', () => {beforeEach(() => {vi.clearAllMocks();diff --cc apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.tsindex 2c8148d548,407e2f4de9..af40a5df49--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts@@@ -48,49 -58,6 +61,57 @@@ describe('one-run automation model prefawait scope.restore('task');expect(h.state()).toEqual({ profile: h.original, baseline: null });});+ // Unit: location is part of the durable restore record, including explicit local null.+ it.each([null, 'shared:owner'])('restores the original Agent location %j after restart', async (device) => {+ const h = scopeFixture('high', false, device);+ const scopeId = await h.scope.begin('task');+ h.automate();+ await createScheduledModelScope(h.deps).restore('task', scopeId);+ expect(h.state()).toEqual({ profile: h.original, baseline: null });+ });+ // Merge regression, unit: old baselines have no location. A repeated automation+ // must capture that missing axis before moving the task, preserving the old model.- it.each([null, 'shared:owner'])('upgrades a legacy baseline at %j before a location change', async (device) => {++ it.each([++ { device: null, prepare: false }, { device: 'shared:owner', prepare: false },++ { device: 'shared:owner', prepare: true },++ ])('upgrades a legacy baseline before a location change: %j', async ({ device, prepare }) => {+ const h = scopeFixture('high', false, device);+ const { agentDeviceId: _location, ...legacy } = h.original;+ await h.deps.write('task', { ...legacy, scopeId: 'legacy-scope' });- // Companion baseline writes now require the revision captured with the route.++ if (prepare) await h.deps.write('task', { ...legacy, scopeId: 'legacy-scope', pendingBotProfileVersion: 2 });++ // Both the profile revision and the existing baseline must match for an++ // upgrade, including a baseline returned by permanent-choice preparation.+ const scope = createScheduledModelScope({ ...h.deps,+ read: async () => ({ ...await h.deps.read(), profileRevision: 'A' }),- write: async (id, baseline, revision) => {- if (baseline && revision !== 'A') return false;++ prepareBaseline: prepare ? async () => {++ await h.deps.write('task', { ...legacy, scopeId: 'legacy-scope' });++ } : undefined,++ write: async (id, baseline, revision, expectedBaseline) => {++ if (baseline && (revision !== 'A' || expectedBaseline !== h.state().baseline)) return false;+ await h.deps.write(id, baseline);+ return true;+ },+ });+ expect(await scope.begin('task')).toBe('legacy-scope');+ h.automate();+ await createScheduledModelScope(h.deps).restore('task', 'legacy-scope');+ expect(h.state()).toEqual({ profile: h.original, baseline: null });+ });+ // Merge regression, unit: a profile save can invalidate a legacy location+ // upgrade after its read. A rejected durable write must stop the automation+ // before it moves the task; earlier coverage only exercised successful writes.+ it('retries a legacy location upgrade when the profile changes before writing', async () => {+ const h = scopeFixture('high', false, 'shared:owner');+ const { agentDeviceId: _location, ...legacy } = h.original;+ await h.deps.write('task', { ...legacy, scopeId: 'legacy-scope' });+ const saved = h.state().baseline;+ const scope = createScheduledModelScope({ ...h.deps,+ read: async () => ({ ...await h.deps.read(), profileRevision: 'A' }),+ write: async () => false,+ });+ await expect(scope.begin('task')).rejects.toThrow(ScheduledModelSelectionBusyError);+ expect(h.state()).toEqual({ profile: h.original, baseline: saved });+ });// #6895 unit regression: preparing a newly saved route may defer/fail. The// stale session row must not become durable recovery state in that case.it('does not capture an old baseline when preparing the saved choice fails', async () => {@@@ -349,13 -268,6 +388,12 @@@ function provider(id: string, model: Pa}describe('saved effort uses the selected provider and Harness catalog copy', () => {- // Local admission remains owned by the live route guard; capability resolution- // must not impose the stricter remote new-route policy on an owner's baseline.- it('preserves local capability resolution for an existing disabled model', () => {- expect(resolveScheduledModelSelection({ ...selection, agentDeviceId: null, effort: 'high' }, [++ // Main now applies new-route admission to both local and remote restores.++ it('rejects a disabled local model during scheduled resolution', () => {++ expect(() => resolveScheduledModelSelection({ ...selection, agentDeviceId: null, effort: 'high' }, [+ provider('custom', { disabled: true }),- ])).toEqual({ ...selection, agentDeviceId: null, effort: 'high' });++ ])).toThrow('MODEL_SELECTION_UNAVAILABLE');+ });it.each([null, 'ultra'] as const)('fills or reconciles %s to the route default', (effort) => {const selected = provider('custom', { efforts: ['low', 'high'], defaultEffort: 'high' });const other = provider('other', { efforts: ['low'], defaultEffort: 'low' });@@@ -440,3 -343,174 +478,193 @@@ describe('bound target Harness capabiliexpect(() => assertScheduledHarnessSupported(null, 'pi')).not.toThrow();});});++ // #6745: invoke the same production resolver wired into register.ts with the+ // real persisted-scope lifecycle; only catalog, storage and engine I/O are fakes.+ const remoteChoice: ScheduledModelSelection = {+ agentKind: 'codex', model: 'test-model', providerId: 'openai-shared', effort: 'high', fastMode: false,+ };+ function remoteCatalog(id: string): ProviderView[] {+ return [{ id, connected: true, agents: ['codex'], routing: { codex: {} }, source: 'user', models: { codex: [{+ id: 'test-model', efforts: ['low', 'high'], defaultEffort: 'low', supportsFastMode: false,+ }] } }] as ProviderView[];+ }+ function remoteFixture(device: string | null = 'share:test', status = 'active') {+ let current = { ...remoteChoice, agentDeviceId: device };+ let baseline: string | null = JSON.stringify({ ...remoteChoice, scopeId: 'old-run' });+ const local = remoteCatalog('openai');+ const remote = vi.fn(async () => remoteCatalog('openai-shared'));+ const guard = vi.fn(async (_agent: string, _model: string, providerId: string | null) => {+ if (!local.some(p => p.id === providerId)) throw new Error('provider unavailable on this computer');+ return undefined;+ });+ const switchHarness = vi.fn(async () => ({ engineReady: true }));+ const applyModel = vi.fn(async (route: ScheduledModelSelection) => {+ current = { ...current, ...route };+ });+ const apply = async (_id: string, selection: ScheduledModelSelection) => applyScheduledModelSelection(selection, {+ getTarget: async () => status === 'missing' ? null : ({ ...current, status }),+ isBusy: () => false,+ resolveSelection: createScheduledModelSelectionResolver({+ readRemoteProviders: remote,+ resolveLocalSelection: async route => {+ await guard(route.agentKind, route.model, route.providerId);+ return resolveScheduledModelSelection(route, local);+ },+ }),+ switchHarness, applyModel,+ });+ const deps = {+ read: async () => ({ profile: current, baseline }),+ write: async (_id: string, value: unknown) => { baseline = value ? JSON.stringify(value) : null; },+ isBusy: () => false, createId: () => 'new-run',+ apply: async (id: string, profile: ScheduledModelSelection) => { await apply(id, profile); },+ };+ return { deps, apply, remote, guard, switchHarness, applyModel, scope: createScheduledModelScope(deps),+ state: () => ({ current, baseline }), save: (value: unknown) => { baseline = JSON.stringify(value); } };+ }++ describe('automation restore uses the execution computer', () => {++ // Merge regression, unit: the shared resolver previously only inspected the++ // bound task. Explicit location changes must validate the destination catalog.++ it.each([++ { current: null, chosen: 'share:test', providerId: 'openai-shared' },++ { current: 'share:test', chosen: null, providerId: 'openai' },++ ])('resolves an explicit destination instead of the current task location: %j', async ({ current, chosen, providerId }) => {++ const h = remoteFixture(current);++ const choice = { ...remoteChoice, agentDeviceId: chosen, providerId };++ await h.apply('task', choice);++ expect(h.state().current).toMatchObject(choice);++ expect(h.switchHarness).toHaveBeenCalledWith(choice);++ if (chosen) {++ expect(h.remote).toHaveBeenCalledWith(chosen, 'codex', 'test-model', providerId);++ expect(h.guard).not.toHaveBeenCalled();++ } else {++ expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', providerId);++ expect(h.remote).not.toHaveBeenCalled();++ }++ });+ it.each(['share:test', 'other-device'])('restores a legacy baseline on %s after restart', async device => {+ const h = remoteFixture(device);+ await createScheduledModelScope(h.deps).restore('task');+ expect(h.remote).toHaveBeenCalledWith(device, 'codex', 'test-model', 'openai-shared');+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.applyModel).toHaveBeenCalledOnce();+ expect(h.state().baseline).toBeNull();+ expect(h.state().current).toMatchObject(remoteChoice);+ });+ it('validates an automation choice on the same remote execution computer', async () => {+ const h = remoteFixture();+ await h.apply('task', remoteChoice);+ expect(h.remote).toHaveBeenCalledWith('share:test', 'codex', 'test-model', 'openai-shared');+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ expect(h.state().current.agentDeviceId).toBe('share:test');+ });+ it('keeps ordinary local-provider validation for a local task', async () => {+ const h = remoteFixture(null);+ h.save({ ...remoteChoice, providerId: 'openai', scopeId: 'old-run' });+ await h.scope.restore('task');+ expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', 'openai');+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.state().current.providerId).toBe('openai');+ expect(h.state().baseline).toBeNull();+ });+ it('does not substitute a local provider when the remote catalog no longer contains the source', async () => {+ const h = remoteFixture();+ h.remote.mockResolvedValueOnce(remoteCatalog('another-source'));+ await expect(h.scope.restore('task')).rejects.toThrow('unavailable');+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.state().baseline).not.toBeNull();+ });+ it('preserves the standard admission exception for a custom user-owned model group', async () => {+ const h = remoteFixture();+ const views = remoteCatalog('openai-shared');+ const model = 'gpt-4o-audio-preview';+ views[0].models.codex![0].id = model;+ views[0].models.codex![0].group = 'custom:openai-shared';+ h.save({ ...remoteChoice, model, scopeId: 'old-run' });+ h.remote.mockResolvedValueOnce(views);+ await h.scope.restore('task');+ expect(h.state().baseline).toBeNull();+ expect(h.state().current).toMatchObject({ ...remoteChoice, model });+ });+ it.each([{ status: 'retired' }, { availability: 'requires_payment' }, { mode: 'image' }])(+ 'rejects a remote catalog entry outside new-route admission: %j', async flags => {+ const h = remoteFixture();+ const before = h.state();+ const views = remoteCatalog('openai-shared');+ Object.assign(views[0].models.codex![0], flags);+ h.remote.mockResolvedValueOnce(views);+ await expect(h.scope.restore('task')).rejects.toThrow('unavailable');+ expect(h.state()).toEqual(before);+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ },+ );+ it.each(['provider', 'model'] as const)('preserves the baseline when the remote %s is disabled after restart', async disabled => {+ const h = remoteFixture();+ const before = h.state();+ const views = remoteCatalog('openai-shared');+ if (disabled === 'provider') views[0].suspended = true;+ else views[0].models.codex![0].disabled = true;+ h.remote.mockResolvedValueOnce(views);+ await expect(h.scope.restore('task')).rejects.toThrow('unavailable');+ expect(h.state()).toEqual(before);+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ });+ // #6759: the model can remain in the catalog after its Harness route is+ // removed or disabled. Exercise the production resolver and persisted restore.+ it.each(['agent-removed', 'route-missing', 'route-disabled'] as const)(+ 'preserves the baseline when the remote Harness is unavailable: %s', async reason => {+ const h = remoteFixture();+ const before = h.state();+ const views = remoteCatalog('openai-shared');+ if (reason === 'agent-removed') views[0].agents = [];+ else if (reason === 'route-missing') views[0].routing = {};+ else views[0].routing.codex!.disabled = true;+ h.remote.mockResolvedValueOnce(views);+ await expect(createScheduledModelScope(h.deps).restore('task')).rejects.toThrow('unavailable');+ expect(h.state()).toEqual(before);+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ },+ );+ it.each(['archived', 'deleted', 'missing'])('defers a %s replacement to the runner without querying either catalog', async status => {+ const h = remoteFixture('share:test', status);+ const before = h.state();+ h.remote.mockRejectedValue(new Error('REMOTE_AGENT_SHARE_PAUSED'));+ const localChoice = { ...remoteChoice, providerId: 'openai' };+ await expect(h.apply('task', localChoice)).resolves.toEqual(localChoice);+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ expect(h.state()).toEqual(before);+ });+ it.each(['archived', 'deleted'])('preserves the saved remote source for runner recovery of a %s target', async status => {+ const h = remoteFixture('share:test', status);+ await expect(h.apply('task', remoteChoice)).resolves.toEqual(remoteChoice);+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.switchHarness).not.toHaveBeenCalled();+ });+ it('retains the scope and task when the sharing host rejects access', async () => {+ const h = remoteFixture();+ h.remote.mockRejectedValueOnce(new Error('REMOTE_AGENT_SHARE_PAUSED'));+ await expect(h.scope.restore('task')).rejects.toThrow('REMOTE_AGENT_SHARE_PAUSED');+ expect(h.state().baseline).not.toBeNull();+ expect(h.applyModel).not.toHaveBeenCalled();+ expect(h.guard).not.toHaveBeenCalled();+ });+ it('rejects a missing local provider without guessing a remote source', async () => {+ const h = remoteFixture(null);+ await expect(h.scope.restore('task')).rejects.toThrow('provider unavailable');+ expect(h.remote).not.toHaveBeenCalled();+ expect(h.state().baseline).not.toBeNull();+ });+ });diff --cc apps/desktop/src/main/maker-ipc/scheduledModelSelection.tsindex 528bc2419b,caeddd4a0d..4139eb06af--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts@@@ -45,19 -43,8 +45,21 @@@ export function createScheduledModelScolet row = await deps.read(sessionId);assertOwner(owner);if (!row) return undefined;- const existing = parseScheduledModelBaseline(row.baseline);- if (existing) {++ const reuseBaseline = async (existing: ScheduledModelBaseline, captured: NonNullable<typeof row>) => {+ // Older baselines predate location overrides. Capture the current location+ // before this automation can move it, without replacing the owner's model.+ if (existing.agentDeviceId === undefined) {+ const written = await deps.write(sessionId,- { ...existing, agentDeviceId: row.profile.agentDeviceId ?? null }, row.profileRevision);++ { ...existing, agentDeviceId: captured.profile.agentDeviceId ?? null }, captured.profileRevision, captured.baseline);++ assertOwner(owner);+ if (written === false) {+ throw new ScheduledModelSelectionBusyError('Companion profile changed during baseline upgrade');+ }+ }+ return existing.scopeId;- }++ };+ const existing = parseScheduledModelBaseline(row.baseline);- if (existing && !existing.pendingBotProfileVersion) return existing.scopeId;++ if (existing && !existing.pendingBotProfileVersion) return reuseBaseline(existing, row);const profileRevision = row.profileRevision;// Settings may have committed while their asynchronous runtime refresh is// still queued. Align the owner under this same send lease before capture.@@@ -71,12 -58,15 +73,16 @@@if (row.profileRevision !== profileRevision) {throw new ScheduledModelSelectionBusyError('Companion profile changed during baseline preparation');}+ const prepared = parseScheduledModelBaseline(row.baseline);+ if (prepared?.pendingBotProfileVersion) {+ throw new ScheduledModelSelectionBusyError('Permanent model selection is still pending');+ }- if (prepared) return prepared.scopeId;++ if (prepared) return reuseBaseline(prepared, row);const scopeId = deps.createId();- const written = await deps.write(sessionId, { ...row.profile, effort: row.profile.effort || null, scopeId }, profileRevision, row.baseline);+ const written = await deps.write(sessionId, { ...row.profile, agentDeviceId: row.profile.agentDeviceId ?? null,- effort: row.profile.effort || null, scopeId }, profileRevision);- if (written === false) {- throw new ScheduledModelSelectionBusyError('Companion profile changed during baseline capture');- }++ effort: row.profile.effort || null, scopeId }, profileRevision, row.baseline);+ assertOwner(owner);+ if (written === false) throw new ScheduledModelSelectionBusyError('Scheduled model selection changed before scope creation');return scopeId;},async restore(sessionId: string, expectedScopeId?: string): Promise<void> {@@@ -166,6 -155,22 +175,24 @@@ export function resolveScheduledModelSe};}+ /** Resolve against the bound execution computer; the runner owns inactive-target recovery. */+ export function createScheduledModelSelectionResolver(deps: {+ readRemoteProviders: (deviceId: string, agent: AgentKind, model: string, providerId: string | null) => Promise<ProviderView[]>;+ resolveLocalSelection: (selection: ScheduledModelSelection) => Promise<ScheduledModelSelection>;+ }) {+ return async (selection: ScheduledModelSelection, target?: ScheduledModelTarget | null): Promise<ScheduledModelSelection> => {- if (target?.agentDeviceId && !target.remoteHostId) {++ const agentDeviceId = selection.agentDeviceId === undefined++ ? target?.agentDeviceId : selection.agentDeviceId;++ if (agentDeviceId && !target?.remoteHostId) {+ const providers = await deps.readRemoteProviders(- target.agentDeviceId, selection.agentKind, selection.model, selection.providerId,++ agentDeviceId, selection.agentKind, selection.model, selection.providerId,+ );+ return resolveScheduledModelSelection(selection, providers);+ }+ return deps.resolveLocalSelection(selection);+ };+ }+/** Reuse the ordinary history handoff; never stage an automation intent on a busy task. */export async function applyScheduledModelSelection(selection: ScheduledModelSelection,@@@ -186,17 -191,12 +213,17 @@@return selection;}if (deps.isBusy()) throw new ScheduledModelSelectionBusyError('Scheduled model selection waits for the current turn');- assertScheduledHarnessSupported(target, selection.agentKind);- // Automation changes model preferences within the bound task's execution location.- // Persisted baselines from older clients have no location of their own.- const resolved = await deps.resolveSelection(selection, target);- if (target.agentKind !== resolved.agentKind) {- const result = await deps.switchHarness(resolved);+ assertScheduledHarnessSupported(target, selection.agentKind, selection.agentDeviceId);+ const resolved = await deps.resolveSelection({ ...selection,+ ...(selection.agentDeviceId === undefined && target.agentDeviceId !== undefined+ ? { agentDeviceId: target.agentDeviceId } : {}),- });++ }, target);+ const changesDevice = (target.agentDeviceId ?? null) !== (resolved.agentDeviceId ?? null);+ if (target.agentKind !== resolved.agentKind || changesDevice) {+ // The handoff treats an explicit location as a relocation request. Preserve+ // engine-only switching for execution-device Workers without relaxing that boundary.+ const { agentDeviceId: _location, ...harnessSelection } = resolved;+ const result = await deps.switchHarness(changesDevice ? resolved : harnessSelection);if (!result.engineReady || result.retryPending) throwIpcError('HARNESS_SWITCH_NOT_READY', 'Scheduled Harness switch did not become ready');}await deps.applyModel(resolved);diff --cc apps/desktop/src/shared/scheduledModelBaseline.tsindex ce5fe9199e,c4cd363134..461db0f1a2--- a/apps/desktop/src/shared/scheduledModelBaseline.ts+++ b/apps/desktop/src/shared/scheduledModelBaseline.ts@@@ -3,8 -3,9 +3,10 @@@ import type { MakerAgentKindWire } fro/** Only model preferences; native checkpoints and permission settings keep their own lifecycle. */export interface ScheduledModelBaseline {scopeId: string;+ /** Permanent profile save not yet accepted by the runtime; survives pause/restart. */+ pendingBotProfileVersion?: number;agentKind: MakerAgentKindWire;+ agentDeviceId?: string | null;model: string;providerId: string | null;effort: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'ultra' | null;diff --cc docs/product-rules/model-selector-unified.mdindex c0859d106a,7b74dee1ba..bc160832fb--- a/docs/product-rules/model-selector-unified.md+++ b/docs/product-rules/model-selector-unified.md@@@ -207,25 -207,10 +207,27 @@@绑定已有任务的自动化在保存时只更新自动化配置,下次触发时才通过现有任务切换流程应用完整选择;目标正忙时顺延,不能抢占当前轮次。新增的 `modelAgentKind` 标识显式 Harness 选择;旧记录不补默认值,继续跟随绑定任务的 Harness。选择“跟随”会清除整套显式覆盖,切换新建/绑定模式往返时保留用户已选配置。-自动化应用模型以及恢复之前的模型偏好时,都按活动任务当前的 Agent 执行位置校验来源与模型,并遵守现有新路由准入(含停用、退役、付费与对话能力限制);同账号远程电脑和分享来源使用对应电脑的目录,不能拿本机目录判定不可用,也不能静默换成本机来源。重启后遗留的恢复记录沿用同一规则,无需补字段。失效绑定的恢复由 runner 负责:普通已归档目标先恢复,删除或缺失目标按自动化保存的位置重建,不能查询失效目标的旧目录。伙伴永久模型选择成功处理后(包括选择已与当前临时模型一致、无需切换的情况),清除被新选择取代的旧自动化恢复记录,避免下一条普通消息恢复旧来源;登记失败仍保留原记录。普通伙伴协调即使需要切换路由,也不清除自动化恢复记录;只有明确的永久保存成功接受后才使旧记录失效。暂停期间的永久保存与恢复记录在同一事务中记录待接受版本,重启或切账号后仍可继续接受;并发更新通过版本对应的恢复记录比较写入,旧选择不能清除新保存。++自动化应用模型以及恢复之前的模型偏好时,都按显式选择的 Agent 执行位置校验来源与模型,未指定位置时继承活动任务的位置,并遵守现有新路由准入(含停用、退役、付费与对话能力限制);同账号远程电脑和分享来源使用对应电脑的目录,不能拿本机目录判定不可用,也不能静默换成本机来源。重启后未记录位置的旧恢复记录继承当前位置;再次跨位置运行自动化前,按原记录与 Profile 版本比较写入补记位置,保留原模型。失效绑定的恢复由 runner 负责:普通已归档目标先恢复,删除或缺失目标按自动化保存的位置重建,不能查询失效目标的旧目录。伙伴永久模型选择成功处理后(包括选择已与当前临时模型一致、无需切换的情况),清除被新选择取代的旧自动化恢复记录,避免下一条普通消息恢复旧来源;登记失败仍保留原记录。普通伙伴协调即使需要切换路由,也不清除自动化恢复记录;只有明确的永久保存成功接受后才使旧记录失效。暂停期间的永久保存与恢复记录在同一事务中记录待接受版本,重启或切账号后仍可继续接受;并发更新通过版本对应的恢复记录比较写入,旧选择不能清除新保存。+项目自动化的 `schedules.json` 同样保存可选的 `modelAgentKind`,导出、加载与配置同步均保留该标记;删除标记时清除数据库中的覆盖,已有绑定任务不丢失。旧版 `version: 1` 文件无需补字段。自动触发前按实际来源、Harness 和模型的当前目录拷贝补齐或收敛 effort,并清除已不受支持的 Fast;仍有效的用户选择保持不变。+自动化复用统一选择器的远程电脑与分享供应商列表、来源标识及图标。可选 `modelAgentDeviceId`+保存所选 Agent 位置:缺省沿用绑定任务;首次新建或重建时沿用 `agentDeviceId` 默认位置,未配置才用本机。空字符串明确选择自动化所在电脑,+非空为既有远程/分享来源 id。只修改后续触发的配置,不改历史记录、不打断当前运行;+新建、持续与绑定模式保持不变。恢复记录同时保存原 Agent 位置,下次用户输入时恢复;自动化完成时不重建原生上下文。+工作目录、文件、Skill 与插件仍走自动化所在电脑的既有远程 Agent 通道与权限,不借用分享方配置。+Desktop 的 `ModelRouteSelector` 提供完整控件,`ModelRouteSelectorContent` 提供嵌入既有弹层的面板;+两者共用位置候选与按设备隔离的模型记忆接入,浏览其他来源和重新打开已选来源都保留思考档与 Fast 偏好。+自动化使用后者,保留自身按钮、跟随选项与保存时机,不另行拼装远程来源。+两种形式均透传统一选择器的完整选模结果;专用能力限制仍由调用场景声明。+前置检查脚本的 AI 生成使用直接 utility HTTP 接口。表单选择远程来源时沿用本机辅助模型兜底;+直接向该接口传远程来源仍明确拒绝,不得误用本机同名供应商。已有脚本的执行不受影响。+绑定远程任务但显式选回本机时,生成请求保留本机标记与所选引擎,缺省来源按本机目录补齐;+绑定任务只提供工作目录,不借用它的远程模型或来源。+“仅运行脚本”模式暂不支持远程模型来源;切换保存时保留完整来源并明确拒绝,原配置不变,+先选回本机模型后可切换。脚本的 `sessions.dispatch` 新建任务同样不得将远程配置解释成本机来源。+本机脚本新建任务使用 `modelAgentKind ?? agentKind` 与所选模型配对;投递既有任务仍沿用该任务配置。+---## 4. 特殊情况检查表(实现与 review 逐条过)