Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-agent): 远程控制下新建任务也能选到第三台电脑的远程供应商
Lizi9fb59bb93cd3
diff --git a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.tsindex 4dd9226321..25dbdacc9a 100644--- a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts+++ b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts@@ -490,7 +490,7 @@ describe('ChatInput model source switching wiring', () => {const draftBlock = chatInputSource.slice(draftStart,chatInputSource.indexOf(- '[sessionId, settingsLocked, modelMemory, onUnifiedDraftSelect, agentDeviceId]',+ '[sessionId, settingsLocked, modelMemory, taskComputerModelMemory, onUnifiedDraftSelect, agentDeviceId]',draftStart,),);@@ -503,10 +503,10 @@ describe('ChatInput model source switching wiring', () => {]) {expect(draftBlock).toContain(write);}- // 远程 Agent 换落点:记忆按目标目录写(回本机写本机预设,去另一台电脑写本机为那台记的- // 一份),落点原样交给草稿层。+ // 远程 Agent 换落点:记忆按目标目录写(回任务所在电脑写那份 —— 本机预设 / 被控电脑的镜像,+ // 去另一台电脑写本机为那台记的一份),落点原样交给草稿层。expect(draftBlock).toContain('? agentDeviceModelMemoryAccessors(selection.agentDevice.deviceId)');- expect(draftBlock).toContain(': LOCAL_MODEL_MEMORY;');+ expect(draftBlock).toContain(': taskComputerModelMemory;');expect(draftBlock).toContain('agentDevice: selection.agentDevice');// 「恢复推荐」已先删除记忆键;直通草稿时不得把推荐档位重新写成 override。expect(draftBlock).toContain('!selection.resetToRecommended');@@ -518,7 +518,7 @@ describe('ChatInput model source switching wiring', () => {it('keeps a new conversation model pick on the draft path', () => {const draftStart = chatInputSource.indexOf('const handleUnifiedDraftSelect = useCallback(');const draftEnd = chatInputSource.indexOf(- '[sessionId, settingsLocked, modelMemory, onUnifiedDraftSelect, agentDeviceId]',+ '[sessionId, settingsLocked, modelMemory, taskComputerModelMemory, onUnifiedDraftSelect, agentDeviceId]',draftStart,);const draftHandler = chatInputSource.slice(draftStart, draftEnd);diff --git a/apps/desktop/src/renderer/__tests__/controlledDraftRemoteAgentWiring.test.ts b/apps/desktop/src/renderer/__tests__/controlledDraftRemoteAgentWiring.test.tsnew file mode 100644index 0000000000..e11869ee16--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/controlledDraftRemoteAgentWiring.test.ts@@ -0,0 +1,155 @@+/**+ * 远程控制下新建任务:Agent 也能在第三台电脑运行(2026-10-09 用户反馈:新建任务时选了远程电脑,+ * 模型列表里选不到远程供应商,只有选本机才选得到;手机新建任务已经能选)。+ *+ * 场景:同账号 A(本机,控制端)、B(新任务建在这台)、C(开了「允许被远程调用」的电脑)。锁住+ * 草稿页与输入框的几条接线:+ * 1. 只有 B 的供应商目录带「允许被远程调用」标记(认得 create-session 的 agentDeviceId)时才开放,+ * 共享任务访客与 SSH 不开放;候选电脑去掉 B 本身,不并入 A 收到的分享;+ * 2. 选了 C 时草稿的模型目录跟着 C,B 的新建草稿记忆不被写进 C 的模型;+ * 3. 建任务时把 agentDeviceId 交给 B(普通发送与新建目标两条路径);+ * 4. 输入框的模型面板先列 B 的目录与它的镜像记忆,再列 C。+ */+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { describe, expect, it } from 'vitest';++const read = (relative: string): string =>+ readFileSync(resolve(__dirname, relative), 'utf8').replace(/\r\n/g, '\n');++const draftRouteSource = read('../features/cc-agent/NewMakerDraftRoute.tsx');+const chatInputSource = read('../components/new-chat/ChatInput.tsx');++describe('草稿页:建到被控电脑的任务也能选第三台电脑', () => {+ it('被控电脑认得 agentDeviceId 才开放;共享任务访客与 SSH 不开放', () => {+ const start = draftRouteSource.indexOf('const deviceLinkRemoteAgentSupported =');+ expect(start).toBeGreaterThan(0);+ const block = draftRouteSource.slice(start, draftRouteSource.indexOf(';\n', start));+ expect(block).toContain('!isSharedTaskPeer(effectiveDeviceLinkDeviceId)');+ expect(block).toContain('controlledComputerSupportsRemoteAgent(deviceLinkHostProviders)');+ // 已选好的另一台电脑在被控电脑目录暂时读不到时继续生效(不在两份目录之间来回重种)。+ expect(block).toContain('(draft.agentDeviceId != null && deviceLinkHostProviders.length === 0)');+ expect(draftRouteSource).toContain(+ 'const { providers: deviceLinkHostProviders } = useDeviceProviders(effectiveDeviceLinkDeviceId);',+ );+ const agentStart = draftRouteSource.indexOf('const effectiveAgentDeviceId =');+ const agentBlock = draftRouteSource.slice(agentStart, draftRouteSource.indexOf(';\n', agentStart));+ expect(agentBlock).toContain('!effectiveRemoteHostId');+ expect(agentBlock).toContain('(!effectiveDeviceLinkDeviceId || deviceLinkRemoteAgentSupported)');+ });++ it('候选电脑去掉被控电脑本身,不并入本机收到的分享;不支持时不传', () => {+ const start = draftRouteSource.indexOf('const remoteAgentDevices = useMemo(() => {');+ expect(start).toBeGreaterThan(0);+ const branchEnd = draftRouteSource.indexOf(': undefined;', start);+ const controlledBranch = draftRouteSource.slice(start, branchEnd);+ expect(controlledBranch).toContain('if (effectiveDeviceLinkDeviceId) {');+ expect(controlledBranch).toContain('selectControlledTaskAgentDevices({');+ expect(controlledBranch).toContain('controlledDeviceId: effectiveDeviceLinkDeviceId,');+ expect(controlledBranch).not.toContain('providerShareDevices');+ });++ it('选了另一台电脑时模型目录跟着那台', () => {+ expect(draftRouteSource).toContain(+ 'const catalogDeviceId = effectiveAgentDeviceId ?? effectiveDeviceLinkDeviceId;',+ );+ });++ it('不把另一台电脑的模型写进被控电脑的新建草稿记忆,也不跟被控电脑的档位推送', () => {+ const push = draftRouteSource.indexOf('const pushActiveDraftPref = useCallback(');+ expect(push).toBeGreaterThan(0);+ const guard = draftRouteSource.indexOf(+ 'if (effectiveAgentDeviceId && !options?.taskComputerSelection) return;',+ push,+ );+ const invoke = draftRouteSource.indexOf("'maker:apply-new-maker-draft-pref'", push);+ expect(guard).toBeGreaterThan(push);+ expect(invoke).toBeGreaterThan(guard);+ expect(draftRouteSource).toContain('if (capabilities && !effectiveAgentDeviceId) {');+ });++ it('权限在被控电脑上生效:换 Agent 所在电脑沿用被控电脑草稿的权限档,被夹掉时也不掺本机偏好', () => {+ expect(draftRouteSource).toContain(+ "(isAgentDeviceDraft && !isDeviceLinkDraft) || remoteDraftState.status === 'ready';",+ );+ expect(draftRouteSource).toContain('? { ...recalled, permissionMode: taskComputerPermission }');+ expect(draftRouteSource).toContain(+ '...(taskComputerPermission ? { permissionMode: taskComputerPermission } : {}),',+ );+ const start = draftRouteSource.indexOf('const chatInitialPermissionMode = isDeviceLinkDraft');+ const block = draftRouteSource.slice(start, draftRouteSource.indexOf(';\n', start));+ const remote = block.indexOf('remoteDraftState.value?.permissionMode');+ const local = block.indexOf('chatPrefs.permissionMode)');+ expect(remote).toBeGreaterThan(0);+ expect(local).toBeGreaterThan(remote);+ });++ it('来源与协同 Worker 只用那台电脑开放了远程调用的供应商(那台是最终裁决方)', () => {+ expect(draftRouteSource).toContain(+ '() => (effectiveAgentDeviceId ? remoteAgentProviders(deviceProviders) : deviceProviders),',+ );+ // 两次提交给被控电脑 + 默认来源解析。+ expect(draftRouteSource.split('deviceProviders: agentCatalogProviders,').length - 1).toBe(2);+ const initialProvider = draftRouteSource.indexOf('const chatInitialProviderId = useMemo');+ expect(+ draftRouteSource.slice(initialProvider, initialProvider + 400),+ ).toContain('effectiveSourceIdForModel(\n agentCatalogProviders,');+ // 远程协同(普通发送与新建目标)按同一份收窄。+ expect(+ draftRouteSource.match(/draftEnableOrcaOptions\(\s*effectiveCollab,\s*agentCatalogProviders,/g),+ ).toHaveLength(2);+ });++ it('选回被控电脑的模型:这次选择作为被控电脑目录的种子并写穿被控端,不写本机草稿', () => {+ const start = draftRouteSource.indexOf(+ 'if (switchesAgentDevice && isDeviceLinkDraft && effectiveDeviceLinkDeviceId) {',+ );+ expect(start).toBeGreaterThan(0);+ const branch = draftRouteSource.slice(start, draftRouteSource.indexOf('return;', start));+ expect(branch).toContain('seedSwitchedCatalog(effectiveDeviceLinkDeviceId);');+ expect(branch).toContain('{ taskComputerSelection: true },');+ expect(branch).toContain('patchDraft({ agentDeviceId: null, agentDeviceName: null });');+ expect(branch).not.toContain('patchVendorPrefs(');+ });++ it('同一台被控电脑重新验证时不拿它的能力快照覆盖另一台电脑的选择', () => {+ expect(draftRouteSource).toContain(+ 'if (req.remoteSnapshot && !deviceChanged && effectiveAgentDeviceId) {',+ );+ });++ it('普通发送与新建目标都把 agentDeviceId 交给被控电脑', () => {+ expect(draftRouteSource.split('agentDeviceId: effectiveAgentDeviceId,').length - 1).toBe(2);+ });++ it('两条标识都显示:上一条写任务在哪台,下一条写 Agent 在哪台', () => {+ expect(draftRouteSource).toContain("? 'ccAgent.draft.agentDeviceElsewhereBanner'");+ const deviceBanner = draftRouteSource.indexOf("t('ccAgent.draft.remoteDialogueBanner'");+ const agentBanner = draftRouteSource.indexOf("'ccAgent.draft.agentDeviceElsewhereBanner'");+ expect(agentBanner).toBeGreaterThan(deviceBanner);+ });+});++describe('输入框:草稿的模型面板', () => {+ it('建到被控电脑的草稿也给远程 Agent 入口,先列被控电脑的目录与它的镜像记忆', () => {+ const start = chatInputSource.indexOf(+ 'const remoteAgentOptions = useMemo<RemoteAgentSelectorOptions | undefined>(',+ );+ expect(start).toBeGreaterThan(0);+ const block = chatInputSource.slice(start, chatInputSource.indexOf('\n );\n', start));+ expect(block).toContain('!sessionId &&');+ expect(block).toContain('agentLocationAware &&');+ expect(block).not.toContain('!deviceLinkDeviceId');+ expect(block).toContain('...(deviceLinkDeviceId ? { homeDeviceId: deviceLinkDeviceId } : {}),');+ expect(block).toContain(+ '...(taskComputerModelMemory ? { localModelMemory: taskComputerModelMemory } : {}),',+ );+ });++ it('选回任务所在电脑时档位记进那份记忆(被控电脑的镜像),不写本机预设', () => {+ const start = chatInputSource.indexOf('const handleUnifiedDraftSelect = useCallback(');+ const block = chatInputSource.slice(start, chatInputSource.indexOf('onUnifiedDraftSelect?.({', start));+ expect(block).toContain(': taskComputerModelMemory;');+ expect(block).not.toContain(': LOCAL_MODEL_MEMORY;');+ });+});diff --git a/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsxindex e33f9a5671..645a46d956 100644--- a/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx+++ b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx@@ -273,6 +273,86 @@ describe('被控电脑上的任务:模型面板列出第三台电脑的远程供});});+// 2026-10-09 用户反馈:远程控制下新建任务(选了另一台电脑当任务电脑)时模型列表里选不到远程供应商,+// 只有选本机才选得到。草稿走 onUnifiedSelect 直通,不经 onRelocate。+describe('远程控制下新建任务:草稿的模型面板同样列出第三台电脑的远程供应商', () => {+ function renderControlledDraftPanel(+ remoteAgent: Partial<React.ComponentProps<typeof ModelSelectorContent>['remoteAgent']> = {},+ props: Partial<React.ComponentProps<typeof ModelSelectorContent>> = {},+ ) {+ const onUnifiedSelect = vi.fn(async () => true);+ const onProviderChange = vi.fn();+ render(+ React.createElement(ModelSelectorContent, {+ modelId: 'b-model',+ effort: 'high',+ onModelChange: vi.fn(),+ onEffortChange: vi.fn(),+ currentProviderId: 'b-main',+ onProviderChange,+ actualRoute: false,+ vendorKey: 'cc',+ deviceId: 'device-b',+ onUnifiedSelect,+ remoteAgent: {+ devices,+ selectedDeviceId: null,+ homeDeviceId: 'device-b',+ ...remoteAgent,+ },+ ...props,+ }),+ );+ return { onUnifiedSelect, onProviderChange };+ }++ it('先列被控电脑的全部供应商,再列第三台电脑开放了远程调用的供应商', () => {+ renderControlledDraftPanel();+ expect(screen.getByRole('button', { name: 'B Main' })).toBeTruthy();+ expect(screen.getByRole('button', { name: 'B Closed' })).toBeTruthy();+ expect(screen.queryByRole('button', { name: 'A Local' })).toBeNull();+ expect(screen.getByRole('button', { name: 'C Open · Studio' })).toBeTruthy();+ expect(screen.queryByRole('button', { name: 'C Closed · Studio' })).toBeNull();+ });++ it('选中第三台电脑的模型:把那台电脑交给草稿层,不走换位置', async () => {+ const { onUnifiedSelect, onProviderChange } = renderControlledDraftPanel();+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'C Open · Studio' }));+ });+ const row = within(list()).getByText('C Model').closest('[data-unified-anchor]') as HTMLElement;+ await act(async () => {+ fireEvent.click(row);+ });+ expect(onUnifiedSelect).toHaveBeenCalledWith(+ expect.objectContaining({+ providerId: 'c-open',+ modelId: 'c-model',+ engine: 'cc',+ agentDevice: { deviceId: 'device-c', name: 'Studio' },+ }),+ );+ expect(onProviderChange).not.toHaveBeenCalled();+ });++ it('Agent 已选在第三台电脑:选回被控电脑的模型带 agentDevice: null', async () => {+ const { onUnifiedSelect } = renderControlledDraftPanel(+ { selectedDeviceId: 'device-c' },+ { deviceId: 'device-c', modelId: 'c-model', currentProviderId: 'c-open' },+ );+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'B Main' }));+ });+ const row = within(list()).getByText('B Model').closest('[data-unified-anchor]') as HTMLElement;+ await act(async () => {+ fireEvent.click(row);+ });+ expect(onUnifiedSelect).toHaveBeenCalledWith(+ expect.objectContaining({ providerId: 'b-main', modelId: 'b-model', agentDevice: null }),+ );+ });+});+describe('本机任务不受影响', () => {it('不传 homeDeviceId 时任务所在电脑一格仍是本机目录', () => {renderControlledTaskPanel(diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkCreateArgs.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkCreateArgs.test.tsindex 8a2bbcbd7f..b9f265970c 100644--- a/apps/desktop/src/renderer/__tests__/deviceLinkCreateArgs.test.ts+++ b/apps/desktop/src/renderer/__tests__/deviceLinkCreateArgs.test.ts@@ -319,6 +319,72 @@ describe('buildProvisionalRemoteSession', () => {});});+// 远程控制下新建任务,Agent 在同账号第三台电脑运行(与手机新建任务同一个 create-session 参数)。+describe('Agent 在另一台电脑运行', () => {+ const NOW = '2026-10-09T03:00:00.000Z';+ const candidate = {+ model: 'c-model',+ effort: 'high' as const,+ permissionMode: 'default' as const,+ fastMode: false,+ };+ // 模型目录是运行 Agent 的那台电脑的:来源在那份目录里解析。+ const agentComputerCatalog = [deviceProvider('c-open', true, ['c-model'])];++ it('agentDeviceId 交给被控电脑,来源按那台电脑的目录解析', () => {+ const args = resolveDeviceLinkSubmission({+ agentKind: 'cc',+ workingDir: '/peer/proj',+ candidate,+ deviceProviders: agentComputerCatalog,+ capabilityAgentKind: 'claude-code',+ agentDeviceId: 'device-c',+ });+ expect(args.agentDeviceId).toBe('device-c');+ expect(args.providerId).toBe('c-open');+ expect(args.model).toBe('c-model');+ });++ it('Agent 在被控电脑本身时不带这个字段(旧被控电脑与原有调用不变)', () => {+ for (const agentDeviceId of [undefined, null, '']) {+ const args = resolveDeviceLinkSubmission({+ agentKind: 'cc',+ candidate,+ deviceProviders: agentComputerCatalog,+ capabilityAgentKind: 'claude-code',+ agentDeviceId,+ });+ expect('agentDeviceId' in args).toBe(false);+ }+ });++ it('临时行就带上 Agent 所在电脑;不带时不出现这个字段', () => {+ const remote = buildDeviceLinkCreateArgs({+ agentKind: 'cc',+ model: 'c-model',+ effort: 'high',+ permissionMode: 'default',+ fastMode: false,+ agentDeviceId: 'device-c',+ });+ expect(+ buildProvisionalRemoteSession({ sessionId: 's-6', workDir: '/w', args: remote, nowIso: NOW })+ .agentDeviceId,+ ).toBe('device-c');+ const plain = buildDeviceLinkCreateArgs({+ agentKind: 'cc',+ model: 'b-model',+ effort: 'high',+ permissionMode: 'default',+ fastMode: false,+ });+ expect(+ 'agentDeviceId' in+ buildProvisionalRemoteSession({ sessionId: 's-7', workDir: '/w', args: plain, nowIso: NOW }),+ ).toBe(false);+ });+});+/*** resolveDeviceLinkSubmission —— 远程建会话参数的**唯一入口**。*diff --git a/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts b/apps/desktop/src/renderer/__tests__/newMakerDraft.test.tsindex f9f8f0a98d..eefc4eaa9d 100644--- a/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts+++ b/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts@@ -1880,6 +1880,31 @@ describe('newMakerDraft agent computer', () => {expect(getDraft()).toMatchObject({ agentDeviceId: null, remoteHostId: 'ssh-1' });});+ // 远程控制下新建任务:任务建到被控电脑 dev-a,Agent 在第三台电脑 dev-c。+ it('keeps the agent computer for a task on a controlled computer until that computer changes', async () => {+ const { getDraft, patchDraft } = await loadModule();+ patchDraft({ deviceLinkDeviceId: 'dev-a', deviceLinkDeviceName: 'Studio', workingDir: null });+ patchDraft({ agentDeviceId: 'dev-c', agentDeviceName: 'Office Mac' });+ expect(getDraft()).toMatchObject({ deviceLinkDeviceId: 'dev-a', agentDeviceId: 'dev-c' });+ // 同一台被控电脑上换项目(设备字段照样显式带上):Agent 仍在那台。+ patchDraft({ deviceLinkDeviceId: 'dev-a', deviceLinkDeviceName: 'Studio', workingDir: '/a/proj' });+ expect(getDraft()).toMatchObject({ agentDeviceId: 'dev-c', agentDeviceName: 'Office Mac' });+ // 换到另一台被控电脑 / 回到本机:上一台的选择不再适用。+ patchDraft({ deviceLinkDeviceId: 'dev-d', deviceLinkDeviceName: 'Lab', workingDir: null });+ expect(getDraft()).toMatchObject({ agentDeviceId: null, agentDeviceName: null });+ patchDraft({ deviceLinkDeviceId: 'dev-a', deviceLinkDeviceName: 'Studio', workingDir: null });+ patchDraft({ agentDeviceId: 'dev-c', agentDeviceName: 'Office Mac' });+ patchDraft({ deviceLinkDeviceId: null, deviceLinkDeviceName: null, workingDir: null });+ expect(getDraft()).toMatchObject({ agentDeviceId: null, agentDeviceName: null });+ });++ it('never lets the agent computer be the computer the task is on', async () => {+ const { getDraft, patchDraft } = await loadModule();+ patchDraft({ deviceLinkDeviceId: 'dev-a', deviceLinkDeviceName: 'Studio', workingDir: null });+ patchDraft({ agentDeviceId: 'dev-a', agentDeviceName: 'Studio' });+ expect(getDraft()).toMatchObject({ deviceLinkDeviceId: 'dev-a', agentDeviceId: null, agentDeviceName: null });+ });+it('does not restore the agent computer after a restart', async () => {let mod = await loadModule();mod.patchDraft({ workingDir: '/local/proj', agentDeviceId: 'dev-b', agentDeviceName: 'Office Mac' });diff --git a/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts b/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.tsindex 92062a3ce5..bb4ad6deb6 100644--- a/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts+++ b/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts@@ -1702,9 +1702,13 @@ describe('Shared create project picker', () => {const body = derive.slice(0, derive.indexOf('}, ['));// 本机分支行为不变。expect(body).toContain('if (!usesDeviceCatalog) return localProviderIdForDraft;');- // 远程分支按**被控端**目录 + 草稿当前模型复算,用与 main 同源的解析函数。+ // 远程分支按**模型目录所在电脑**的目录 + 草稿当前模型复算,用与 main 同源的解析函数。+ // 目录通常就是被控端的;Agent 在另一台电脑运行时只取那台开放了远程调用的供应商(2026-10-09)。expect(body).toContain('effectiveSourceIdForModel(');- expect(body).toContain('deviceProviders,');+ expect(body).toContain('agentCatalogProviders,');+ expect(newMakerDraftRouteSource).toContain(+ '() => (effectiveAgentDeviceId ? remoteAgentProviders(deviceProviders) : deviceProviders),',+ );expect(body).toContain('draftInitialModel,');expect(body).toContain('return deviceLinkInitial?.providerId || effectiveSourceIdForModel(');});diff --git a/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts b/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.tsindex 3d827ab555..e1bf6d1fd4 100644--- a/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts+++ b/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts@@ -85,16 +85,17 @@ describe('ChatInput:换位置进切换事务', () => {});describe('被控电脑上的任务:换 Agent 所在电脑', () => {- it('只在调用方传了候选电脑(被控端支持)、不是草稿 / SSH / 共享任务访客、位置本机读得到时开放', () => {+ it('只在调用方传了候选电脑(被控端支持)、不是 SSH / 共享任务访客时开放;已建任务还要位置本机读得到', () => {const start = chatInputSource.indexOf('const deviceLinkAgentLocation =');expect(start).toBeGreaterThan(0);- const block = chatInputSource.slice(start, chatInputSource.indexOf('});\n', start));+ const block = chatInputSource.slice(start, chatInputSource.indexOf('}));\n', start));for (const guard of [- '!!sessionId','!!deviceLinkDeviceId','!remoteHostId','!sharedGuest','remoteAgentDevices !== undefined',+ // 草稿(还没有 sessionId)的落点只来自候选电脑;已建任务另看当前与挂着的位置。+ '(!sessionId ||','controlledTaskAgentLocationReadable({',]) {expect(block).toContain(guard);diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 002e9f614e..ca3804db8d 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -541,8 +541,8 @@ interface ChatInputProps {/*** Agent 在同账号另一台电脑上运行:那台电脑的 deviceId(null = 任务所在电脑)。只决定**模型目录*** (能力、供应商、可用引擎)从哪台读 —— 任务、文件、命令、斜杠命令、附件仍按任务所在电脑处理,- * 切换模型也走任务所在电脑(由它转给那台的 Agent)。被控电脑上的任务传被控电脑投影的值,只在- * 传了 remoteAgentDevices 时生效。+ * 切换模型也走任务所在电脑(由它转给那台的 Agent)。被控电脑上的任务(已建任务传被控电脑投影的值,+ * 草稿传草稿里的选择)只在传了 remoteAgentDevices 时生效。*/agentDeviceId?: string | null;/** agentDeviceId 那台电脑的名字(模型选择器悬停 / 读屏用);未知时显示「另一台电脑」。 */@@ -550,8 +550,8 @@ interface ChatInputProps {/*** 「Agent 在其他电脑运行」的可选目标(同账号电脑,不含任务所在电脑)。传了且非空时,模型面板* 左侧栏在任务所在电脑的供应商之后列出这些电脑上的供应商:草稿里选中会经 onUnifiedDraftSelect- * 的 agentDevice 交给草稿层;已建任务里选中 = 把 Agent 挪过去。被控电脑上的已建任务只在那台- * 支持远程 Agent 时传;SSH 任务不传。+ * 的 agentDevice 交给草稿层;已建任务里选中 = 把 Agent 挪过去。被控电脑上的任务(已建任务与建到+ * 被控电脑的草稿)只在那台支持远程 Agent 时传;SSH 任务不传。*/remoteAgentDevices?: readonly { deviceId: string; name: string }[];/**@@ -1263,21 +1263,22 @@ export function ChatInput({const sharedGuest = isSharedTaskPeer(deviceLinkDeviceId ?? '');const selfDeviceId = useOptionalAuthDeviceId();/**- * 远程控制的被控电脑上的已建任务,Agent 同样可以在第三台电脑运行(与手机同一套)。调用方只在- * 被控电脑支持时才传 remoteAgentDevices;草稿、SSH 任务与共享任务访客不走这条。Agent 现在或- * 挂着的位置是本机读不到目录的地方(被控电脑收到的分享 / 本机自己)时,维持原有的被控电脑列表。+ * 远程控制的被控电脑上的任务(已建任务,或建到被控电脑的新任务草稿),Agent 同样可以在第三台电脑+ * 运行(与手机同一套)。调用方只在被控电脑支持时才传 remoteAgentDevices;SSH 任务与共享任务访客+ * 不走这条。已建任务里 Agent 现在或挂着的位置是本机读不到目录的地方(被控电脑收到的分享 / 本机+ * 自己)时,维持原有的被控电脑列表;草稿的落点只会是 remoteAgentDevices 里的电脑。*/const deviceLinkAgentLocation =- !!sessionId &&!!deviceLinkDeviceId &&!remoteHostId &&!sharedGuest &&remoteAgentDevices !== undefined &&- controlledTaskAgentLocationReadable({- agentDeviceId: _agentDeviceId,- pendingAgentDeviceId: makerChatStore.getAgentSwitchIntent(sessionId)?.agentDeviceId,- selfDeviceId,- });+ (!sessionId ||+ controlledTaskAgentLocationReadable({+ agentDeviceId: _agentDeviceId,+ pendingAgentDeviceId: makerChatStore.getAgentSwitchIntent(sessionId)?.agentDeviceId,+ selfDeviceId,+ }));/** 这个任务的 Agent 位置由本机呈现与切换:本机任务,或上面那种被控电脑上的任务。 */const agentLocationAware = !deviceLinkDeviceId || deviceLinkAgentLocation;/** Agent 在另一台电脑运行(null = 任务所在电脑);只影响模型目录来源。 */@@ -2118,18 +2119,32 @@ export function ChatInput({*/const taskComputerModelMemory = deviceLinkDeviceId ? modelMemoryOverride : LOCAL_MODEL_MEMORY;- // 远程 Agent(仅本机新任务草稿):模型面板左侧栏同时列出其他电脑上的供应商。+ // 远程 Agent · 新任务草稿:模型面板左侧栏同时列出其他电脑上的供应商。本机草稿先列本机目录;+ // 建到被控电脑的草稿(被控电脑支持时调用方才传候选电脑)先列被控电脑的目录与它的镜像记忆。const remoteAgentOptions = useMemo<RemoteAgentSelectorOptions | undefined>(() =>- !sessionId && !deviceLinkDeviceId && !remoteHostId && remoteAgentDevices && remoteAgentDevices.length > 0+ !sessionId &&+ agentLocationAware &&+ !remoteHostId &&+ remoteAgentDevices &&+ remoteAgentDevices.length > 0? {devices: remoteAgentDevices,selectedDeviceId: agentDeviceId,- localModelMemory: LOCAL_MODEL_MEMORY,+ ...(deviceLinkDeviceId ? { homeDeviceId: deviceLinkDeviceId } : {}),+ ...(taskComputerModelMemory ? { localModelMemory: taskComputerModelMemory } : {}),deviceModelMemory: agentDeviceModelMemoryAccessors,}: undefined,- [sessionId, deviceLinkDeviceId, remoteHostId, remoteAgentDevices, agentDeviceId],+ [+ sessionId,+ agentLocationAware,+ deviceLinkDeviceId,+ taskComputerModelMemory,+ remoteHostId,+ remoteAgentDevices,+ agentDeviceId,+ ],);// 把「用户在当前来源下选定的 (model, effort)」记进模型全局预设,供其它非活跃行和之后的@@ -7311,8 +7326,8 @@ export function ChatInput({}) => {if (sessionId || settingsLocked) return;const targetKind = vendorKeyToAgentKind(selection.engine);- // 这一行与当前目录不在同一台电脑(远程 Agent 换落点):记忆按目标目录写 —— 落到本机就写- // 本机预设;落到另一台电脑就写本机为那台记的那一份。+ // 这一行与当前目录不在同一台电脑(远程 Agent 换落点):记忆按目标目录写 —— 落回任务所在+ // 电脑就写那份(本机预设 / 被控电脑的镜像);落到另一台电脑就写本机为那台记的那一份。const crossDevice =selection.agentDevice !== undefined &&(selection.agentDevice?.deviceId ?? null) !== agentDeviceId;@@ -7320,7 +7335,7 @@ export function ChatInput({? modelMemory: selection.agentDevice? agentDeviceModelMemoryAccessors(selection.agentDevice.deviceId)- : LOCAL_MODEL_MEMORY;+ : taskComputerModelMemory;if (targetKind && selection.providerId && !selection.resetToRecommended) {if (selection.effort) {targetMemory?.setEffort(@@ -7345,7 +7360,7 @@ export function ChatInput({...(selection.agentDevice !== undefined ? { agentDevice: selection.agentDevice } : {}),});},- [sessionId, settingsLocked, modelMemory, onUnifiedDraftSelect, agentDeviceId],+ [sessionId, settingsLocked, modelMemory, taskComputerModelMemory, onUnifiedDraftSelect, agentDeviceId],);const showModelSwitchFailure = useCallback(diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsxindex 640cbbabc9..4f045e668e 100644--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx@@ -660,7 +660,8 @@ export interface RemoteAgentRelocation {}/**- * 远程 Agent 的选择入口(本机新任务草稿、本机已建任务,以及远程控制的被控电脑上的已建任务传)。+ * 远程 Agent 的选择入口(本机新任务草稿、本机已建任务,以及远程控制的被控电脑上的已建任务与+ * 建到被控电脑的新任务草稿传)。* 模型面板的左侧栏在任务所在电脑的供应商之后列出这些电脑上的供应商;选中那台电脑上的模型 =* Agent 在那台电脑运行,任务和文件仍在任务所在电脑。*/@@ -670,7 +671,7 @@ export interface RemoteAgentSelectorOptions {/** 当前的 Agent 所在电脑(已建任务按下一条消息时的位置);null = 任务所在电脑。 */selectedDeviceId: string | null;/**- * 任务所在电脑:远程控制的被控电脑上的任务传那台的 deviceId,它的目录照远程控制列出全部供应商;+ * 任务所在电脑:远程控制的被控电脑上的任务(含草稿)传那台的 deviceId,它的目录照远程控制列出全部供应商;* 不传 = 本机任务,用本机目录。*/homeDeviceId?: string;diff --git a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsxindex 0ff4a1bdf3..d460974feb 100644--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx@@ -64,6 +64,11 @@ import { useHasAnyRemoteTarget } from '@/hooks/useHasAnyReadyRemoteHost';import { useSelectableDevices } from '@/hooks/useControllableDevices';import { useProviderShareAgentDevices } from '@/features/provider-share/useProviderShareAgentDevices';import { isProviderShareAgentDeviceId } from '../../../shared/providerShare';+import { isSharedTaskPeer } from '@cindy/device-link';+import {+ controlledComputerSupportsRemoteAgent,+ selectControlledTaskAgentDevices,+} from '@/lib/controlledTaskAgentLocation';import { useProviderOnboarding } from '@/hooks/useProviderOnboarding';import { HomeZeroModelAction } from './HomeZeroModelAction';import { resolveDeviceLinkSubmission } from './deviceLinkCreateArgs';@@ -284,6 +289,7 @@ import {import { recallAgentDeviceSelection, rememberAgentDeviceSelection } from './agentDeviceDraftMemory';import { makeMirrorAccessors, replaceScope, clearScope } from '@/state/deviceLinkModelMirror';import type { ModelMemoryAccessors } from '@/components/new-chat/ModelSelector';+import { remoteAgentProviders } from '@/components/new-chat/unifiedModelSelection';import { resolveNewMakerDraftRightSidebar } from './newMakerDraftRightSidebar';import { resolveNewMakerDraftEffort } from './newMakerDraftModelPrefs';import { loadSshSessionModelSelection, SshModelSelectionError } from './sshSessionModelSelection';@@ -884,11 +890,26 @@ export function NewMakerDraftRoute() {const effectiveDeviceLinkDeviceId = draft.deviceLinkDeviceId ?? undefined;const effectiveDeviceLinkDeviceName = draft.deviceLinkDeviceName;/**- * 「Agent 在另一台电脑运行」:任务、项目文件与命令留在本机,Agent 用那台的登录、供应商与网络。- * 只对本机任务成立(与 device-link / SSH 目标互斥,store 已保证)。+ * 远程控制下新建任务(建到被控电脑上)时,Agent 同样可以在第三台电脑运行(与手机新建任务、+ * 远程控制的已建任务同一套):被控电脑的供应商目录带「允许被远程调用」标记才提供(它认得+ * create-session 的 agentDeviceId)。共享任务访客读到的是自己账号的设备,与这台电脑无关。+ */+ const { providers: deviceLinkHostProviders } = useDeviceProviders(effectiveDeviceLinkDeviceId);+ // 已经选好的另一台电脑一定是在这台被控电脑确认支持时选的(换被控电脑 store 即清空):被控电脑的+ // 目录暂时读不到(首次加载 / 重连)时继续生效,不让草稿在两份目录之间来回重种。+ const deviceLinkRemoteAgentSupported =+ !!effectiveDeviceLinkDeviceId &&+ !isSharedTaskPeer(effectiveDeviceLinkDeviceId) &&+ (controlledComputerSupportsRemoteAgent(deviceLinkHostProviders) ||+ (draft.agentDeviceId != null && deviceLinkHostProviders.length === 0));+ /**+ * 「Agent 在另一台电脑运行」:任务、项目文件与命令留在任务所在电脑(本机,或上面那种被控电脑),+ * Agent 用那台的登录、供应商与网络。SSH 任务不成立(store 已保证)。*/const effectiveAgentDeviceId =- !effectiveDeviceLinkDeviceId && !effectiveRemoteHostId ? (draft.agentDeviceId ?? undefined) : undefined;+ !effectiveRemoteHostId && (!effectiveDeviceLinkDeviceId || deviceLinkRemoteAgentSupported)+ ? (draft.agentDeviceId ?? undefined)+ : undefined;const isAgentDeviceDraft = effectiveAgentDeviceId != null;/*** 远程 Agent 的可选落点:在线的同账号电脑,在模型选择器左侧栏里按供应商列出(选中那里的@@ -898,8 +919,19 @@ export function NewMakerDraftRoute() {// 供应商分享:别人分享给我的供应商(`share:<id>`)同样是落点,只并进模型选择器,不进设备切换器。const { devices: providerShareDevices } =useProviderShareAgentDevices([effectiveAgentDeviceId]);- const remoteAgentDevices = useMemo(- () => [+ const remoteAgentDevices = useMemo(() => {+ if (effectiveDeviceLinkDeviceId) {+ // 建到被控电脑的任务:候选去掉被控电脑本身;本机收到的分享被控电脑用不了,不并入。+ // 被控电脑不支持时不传,模型面板维持只列被控电脑的目录。+ return deviceLinkRemoteAgentSupported+ ? selectControlledTaskAgentDevices({+ devices: selectableDevices,+ controlledDeviceId: effectiveDeviceLinkDeviceId,+ keepDeviceIds: [effectiveAgentDeviceId],+ })+ : undefined;+ }+ return [...selectableDevices.filter((device) =>@@ -907,14 +939,19 @@ export function NewMakerDraftRoute() {).map(({ deviceId, name }) => ({ deviceId, name })),...providerShareDevices,- ],- [selectableDevices, providerShareDevices, effectiveAgentDeviceId],- );+ ];+ }, [+ selectableDevices,+ providerShareDevices,+ effectiveDeviceLinkDeviceId,+ deviceLinkRemoteAgentSupported,+ effectiveAgentDeviceId,+ ]);/**- * 模型目录所在的电脑:任务建到远程设备时是那台;Agent 在另一台电脑运行时也是那台(模型、- * Agent 登录与可用引擎都以运行 Agent 的电脑为准)。本机任务为 undefined。+ * 模型目录所在的电脑:Agent 在另一台电脑运行时是那台(模型、Agent 登录与可用引擎都以运行+ * Agent 的电脑为准);否则任务建到远程设备时是那台。本机任务为 undefined。*/- const catalogDeviceId = effectiveDeviceLinkDeviceId ?? effectiveAgentDeviceId;+ const catalogDeviceId = effectiveAgentDeviceId ?? effectiveDeviceLinkDeviceId;/** 草稿的模型选择以 catalogDeviceId 那台的目录为准(dlSel),不读写本机草稿记忆。 */const usesDeviceCatalog = catalogDeviceId != null;// 入口门控:只在 runtime 已注册的 agent 上开放创建入口(Pi 二进制缺失时 buildPiAgent 返回@@ -1218,6 +1255,15 @@ export function NewMakerDraftRoute() {unsupported: deviceProvidersUnsupported,} = useDeviceProviders(catalogDeviceId);const providers = catalogDeviceId ? deviceProviders : localProviders;+ /**+ * 远程 Agent 只能用运行 Agent 那台电脑开放了「允许被远程调用」的供应商(那台是最终裁决方,+ * 显式指定未开放的来源会被拒):Agent 在另一台电脑运行时,默认来源解析、提交给被控电脑的来源+ * 与协同 Worker 收窄都只看这些。其余情况就是目录本身。+ */+ const agentCatalogProviders = useMemo(+ () => (effectiveAgentDeviceId ? remoteAgentProviders(deviceProviders) : deviceProviders),+ [effectiveAgentDeviceId, deviceProviders],+ );// 新旧用户统一使用 A。老被控端只有 capabilities、没有供应商目录时,// 保留兼容列表与引擎下拉;否则联合列表会为空,也无法切换引擎。const unifiedModelPanelEnabled = !catalogDeviceId || !deviceProvidersUnsupported;@@ -1465,24 +1511,30 @@ export function NewMakerDraftRoute() {remoteDraftRetryEpoch,]);- // 运行 Agent 的电脑只提供模型目录:任务在本机,没有远程草稿默认值,改用本次运行内对这台- // 电脑的上一次选择 + 本机为这台电脑记的每模型档位(见 agentDeviceDraftMemory)。+ // 运行 Agent 的电脑只提供模型目录:没有它的草稿默认值,改用本次运行内对这台电脑的上一次+ // 选择 + 本机为这台电脑记的每模型档位(见 agentDeviceDraftMemory)。任务建到被控电脑时,权限+ // 在被控电脑上生效:等被控电脑的草稿值到了,沿用其中的权限档。const agentDeviceModelMemoryVersion = useAgentDeviceModelMemoryVersion();- const deviceDraftDefaultsReady = isAgentDeviceDraft || remoteDraftState.status === 'ready';- const deviceDraftDefaults = useMemo<RemoteDraftDefaults | null>(- () =>- isAgentDeviceDraft && effectiveAgentDeviceId- ? recallAgentDeviceSelection(effectiveAgentDeviceId, capabilityAgentKind)- : remoteDraftState.value,+ const deviceDraftDefaultsReady =+ (isAgentDeviceDraft && !isDeviceLinkDraft) || remoteDraftState.status === 'ready';+ const deviceDraftDefaults = useMemo<RemoteDraftDefaults | null>(() => {+ if (!isAgentDeviceDraft || !effectiveAgentDeviceId) return remoteDraftState.value;+ const recalled = recallAgentDeviceSelection(effectiveAgentDeviceId, capabilityAgentKind);+ const taskComputerPermission = isDeviceLinkDraft+ ? remoteDraftState.value?.permissionMode+ : undefined;+ return taskComputerPermission+ ? { ...recalled, permissionMode: taskComputerPermission }+ : recalled;// agentDeviceModelMemoryVersion:档位记忆变了要重新取回,切模型时才按最新档位还原。- [- isAgentDeviceDraft,- effectiveAgentDeviceId,- capabilityAgentKind,- remoteDraftState.value,- agentDeviceModelMemoryVersion,- ],- );+ }, [+ isAgentDeviceDraft,+ isDeviceLinkDraft,+ effectiveAgentDeviceId,+ capabilityAgentKind,+ remoteDraftState.value,+ agentDeviceModelMemoryVersion,+ ]);// seed dlSel:等被控端 capabilities + 草稿值都就绪后播种。切设备 / vendor 必须重种;同一目标// 在被控端明确未选过模型且控制端未编辑时,允许 capabilities 刷新重新校准区域默认。@@ -1609,7 +1661,8 @@ export function NewMakerDraftRoute() {setRemoteDraftState({ status: 'ready', value: next });// 选中行(dlSel)的 effort/fast 也跟被控端走:按当前 dlSel.model 重解析,但保留控制端的// permission/source/model 选择(非按模型记 / 控制端 launch 意图)。被控端改选中模型 effort 即时反映。- if (capabilities) {+ // Agent 在另一台电脑运行时选中的是那台目录里的模型,档位与被控端的记忆无关,不跟。+ if (capabilities && !effectiveAgentDeviceId) {setDlSel((prev) => {if (!prev) return prev;const re = resolveDeviceLinkDraftDefaults(@@ -1622,7 +1675,13 @@ export function NewMakerDraftRoute() {});}});- }, [isDeviceLinkDraft, effectiveDeviceLinkDeviceId, capabilityAgentKind, capabilities]);+ }, [+ isDeviceLinkDraft,+ effectiveDeviceLinkDeviceId,+ effectiveAgentDeviceId,+ capabilityAgentKind,+ capabilities,+ ]);// ── worktree 勾选 = 工作端记忆的镜像(2026-07-29 用户裁决:状态只属于用户) ────// 本地草稿读本地 draft.worktreeEnabled;device-link 远程草稿只接受被控端明确返回的@@ -1892,8 +1951,16 @@ export function NewMakerDraftRoute() {modelId: string;effort?: Effort;},+ /**+ * 这次选择落在被控电脑自己的目录里(从另一台电脑改回被控电脑):此刻闭包里 Agent 仍在+ * 另一台电脑,但目标模型属于被控电脑,照常写穿。+ */+ options?: { taskComputerSelection?: boolean },) => {if (!isDeviceLinkDraft || !effectiveDeviceLinkDeviceId) return;+ // Agent 在另一台电脑运行:选中的是那台目录里的模型,不写进被控端的新建草稿记忆+ // (档位已由 ChatInput 记进本机为那台电脑记的一份)。+ if (effectiveAgentDeviceId && !options?.taskComputerSelection) return;const model = target?.modelId ?? dlSel?.model ?? deviceLinkInitial?.model;if (!model) return;// 只改 Fast 时也要带上激活档(被控端 trigger 要更新激活 effort)。给了显式目标就**只**@@ -1924,7 +1991,14 @@ export function NewMakerDraftRoute() {]).catch(() => {});},- [isDeviceLinkDraft, effectiveDeviceLinkDeviceId, capabilityAgentKind, dlSel, deviceLinkInitial],+ [+ isDeviceLinkDraft,+ effectiveDeviceLinkDeviceId,+ effectiveAgentDeviceId,+ capabilityAgentKind,+ dlSel,+ deviceLinkInitial,+ ],);// Fast 可用判定:本地 + device-link 统一走 resolveFastSupported(共享 per-provider 逻辑,@@ -1995,8 +2069,14 @@ export function NewMakerDraftRoute() {}, [usesDeviceCatalog, deviceLinkInitial, calibratedDraftModel, localDraftEffort]);// 远程草稿的权限档 / 来源同样取镜像 holder;本地走 chatPrefs。+ // Agent 在另一台电脑运行时权限仍在被控电脑上生效:那台的能力清单里没有这一档(被夹掉)时,回落到+ // 被控电脑草稿的权限档(被控电脑自己校准过),不掺控制端本机的偏好。const chatInitialPermissionMode = isDeviceLinkDraft- ? (deviceLinkInitial?.permissionMode ?? chatPrefs.permissionMode)+ ? (deviceLinkInitial?.permissionMode ??+ (effectiveAgentDeviceId+ ? (remoteDraftState.value?.permissionMode as PermissionMode | undefined)+ : undefined) ??+ chatPrefs.permissionMode): chatPrefs.permissionMode;// 显式连接始终随草稿提交;未指定连接时才按 UI 与 main 的默认来源差异决定是否固化。const localProviderIdForDraft = useMemo<string | null>(() => {@@ -2019,7 +2099,7 @@ export function NewMakerDraftRoute() {const chatInitialProviderId = useMemo<string | null>(() => {if (!usesDeviceCatalog) return localProviderIdForDraft;return deviceLinkInitial?.providerId || effectiveSourceIdForModel(- deviceProviders,+ agentCatalogProviders,null,draftInitialModel,capabilityAgentKind,@@ -2027,7 +2107,7 @@ export function NewMakerDraftRoute() {}, [usesDeviceCatalog,localProviderIdForDraft,- deviceProviders,+ agentCatalogProviders,deviceLinkInitial?.providerId,draftInitialModel,capabilityAgentKind,@@ -2144,7 +2224,11 @@ export function NewMakerDraftRoute() {// 远程运行配置。给了 snapshot 就当场定;没给且换了设备就打回未加载,由 seed effect 接手 ——// 不打回的话 seed effect 会拿**上一台**的 capabilities + defaults 种下 dlSel 并把新设备记成// 「已 seed」,等新设备真正的值到达时 seedKey 又把重种挡掉,于是向新设备提交上一台的配置。- if (req.remoteSnapshot) {+ if (req.remoteSnapshot && !deviceChanged && effectiveAgentDeviceId) {+ // 同一台被控电脑重新验证,但 Agent 在另一台电脑运行:草稿的模型属于那台的目录,被控电脑+ // 的能力快照校准不了它(store 也不会清掉那台的选择)。只刷新被控电脑的草稿值。+ setRemoteDraftState({ status: 'ready', value: req.remoteSnapshot.defaults });+ } else if (req.remoteSnapshot) {const { capabilities: freshCaps, defaults: freshDefaults } = req.remoteSnapshot;dlSeedKeyRef.current = req.deviceId ? `${req.deviceId}:${capabilityAgentKind}` : null;dlSeedCapabilitiesRef.current = freshCaps;@@ -2241,6 +2325,7 @@ export function NewMakerDraftRoute() {[effectiveDeviceLinkDeviceId,effectiveRemoteHostId,+ effectiveAgentDeviceId,draft.workingDir,capabilityAgentKind,stripProjectRelativeMentions,@@ -2698,35 +2783,63 @@ export function NewMakerDraftRoute() {// 必须无条件进入 store 的 rebase:当前 renderer 的 draft.vendor 可能还停在 storage// event 到达前的旧 Harness。switchVendor 自身同值早返,不会制造额外写入。switchVendor(selection.vendor);- // ── 远程 Agent:模型面板里选到了另一台电脑上的模型(或从那台回到本机)──────────- // 连 Agent 的运行位置一起换。任务、项目、附件都在本机,一概不动;只有模型目录与这次- // 选择改按目标电脑。+ // ── 远程 Agent:模型面板里选到了另一台电脑上的模型(或从那台回到任务所在电脑)──────+ // 连 Agent 的运行位置一起换。任务、项目、附件都在任务所在电脑(本机或被控电脑),一概不动;+ // 只有模型目录与这次选择改按目标电脑。const targetAgentDevice = selection.agentDevice;const switchesAgentDevice =targetAgentDevice !== undefined &&(targetAgentDevice?.deviceId ?? null) !== (effectiveAgentDeviceId ?? null);- if (switchesAgentDevice && targetAgentDevice) {- // 这次显式选择就是那台电脑上的种子:seed key 按播种 effect 的构造逐字前置,并标记- // 控制端已触碰 —— 那台的 capabilities 到达时只做合法性夹紧,不会换成那台的默认模型- // (与下方跨引擎选择同一条修法)。+ // 任务建到被控电脑时权限在被控电脑上生效,换 Agent 所在电脑不改它。+ const taskComputerPermission = isDeviceLinkDraft+ ? deviceLinkInitial?.permissionMode+ : undefined;+ // 这次显式选择就是目标目录里的种子:seed key 按播种 effect 的构造逐字前置,并标记控制端+ // 已触碰 —— 目标电脑的 capabilities 到达时只做合法性夹紧,不会换成那台的默认模型(与下方+ // 跨引擎选择同一条修法)。+ const seedSwitchedCatalog = (catalogOwnerDeviceId: string) => {dlRuntimeTouchedRef.current = true;- dlSeedKeyRef.current = `${targetAgentDevice.deviceId}:${dbToMakerAgentKind(+ dlSeedKeyRef.current = `${catalogOwnerDeviceId}:${dbToMakerAgentKind(normalizeDbAgentKind(selection.vendor),)}`;dlSeedCapabilitiesRef.current = null;setDlSel({model: selection.modelId,- // 没有档位的模型由播种夹紧按那台的目录补成合法值。+ // 没有档位的模型由播种夹紧按目标目录补成合法值。effort: selection.effort ?? 'high',fastMode: selection.fast,providerId: selection.providerId,+ ...(taskComputerPermission ? { permissionMode: taskComputerPermission } : {}),});+ };+ if (switchesAgentDevice && targetAgentDevice) {+ seedSwitchedCatalog(targetAgentDevice.deviceId);patchDraft({agentDeviceId: targetAgentDevice.deviceId,agentDeviceName: targetAgentDevice.name,});return;}+ if (switchesAgentDevice && isDeviceLinkDraft && effectiveDeviceLinkDeviceId) {+ // 回到被控电脑:这次选择落在被控电脑的目录里,同样作为那里的种子(不写本机草稿),并与+ // 被控电脑目录里的普通选中一样把 effort / Fast 写穿被控端(目标显式给,理由同下)。+ seedSwitchedCatalog(effectiveDeviceLinkDeviceId);+ pushActiveDraftPref(+ {+ ...(selection.effort ? { effort: selection.effort } : {}),+ fast: selection.fast,+ },+ {+ agent: dbToMakerAgentKind(normalizeDbAgentKind(selection.vendor)),+ providerId: selection.providerId,+ modelId: selection.modelId,+ ...(selection.effort ? { effort: selection.effort } : {}),+ },+ { taskComputerSelection: true },+ );+ patchDraft({ agentDeviceId: null, agentDeviceName: null });+ return;+ }if (switchesAgentDevice) {// 回到本机:清掉那台电脑的选择,下面按本机草稿写入这次选择。setDlSel(null);@@ -2836,6 +2949,8 @@ export function NewMakerDraftRoute() {draft.vendor,usesDeviceCatalog,catalogDeviceId,+ isDeviceLinkDraft,+ effectiveDeviceLinkDeviceId,effectiveAgentDeviceId,deviceLinkInitial,capabilities,@@ -3666,8 +3781,10 @@ export function NewMakerDraftRoute() {planModeEnabled: effectivePlanMode,providerId,},- deviceProviders,+ deviceProviders: agentCatalogProviders,capabilityAgentKind,+ // Agent 在另一台电脑运行:被控电脑把它记进任务,模型与来源属于那台的目录。+ agentDeviceId: effectiveAgentDeviceId,});let created: { sessionId?: string; workDir?: string } | null = null;const remoteSessionId =@@ -3878,7 +3995,7 @@ export function NewMakerDraftRoute() {pendingLeadInput: message,options: draftEnableOrcaOptions(effectiveCollab,- deviceProviders,+ agentCatalogProviders,!deviceProvidersLoading,true,),@@ -4478,6 +4595,7 @@ export function NewMakerDraftRoute() {remoteModelListStatus,remoteDraftState.status,deviceProviders,+ agentCatalogProviders,deviceProvidersLoading,effectiveDeviceLinkDeviceId,effectiveDeviceLinkDeviceName,@@ -4752,8 +4870,9 @@ export function NewMakerDraftRoute() {planModeEnabled: effectivePlanMode,providerId: chatInitialProviderId,},- deviceProviders,+ deviceProviders: agentCatalogProviders,capabilityAgentKind,+ agentDeviceId: effectiveAgentDeviceId,});let created: { sessionId?: string; workDir?: string } | null = null;const remoteSessionId = await (@@ -4836,7 +4955,7 @@ export function NewMakerDraftRoute() {pendingLeadInput: objective,options: draftEnableOrcaOptions(effectiveCollab,- deviceProviders,+ agentCatalogProviders,!deviceProvidersLoading,true,),@@ -5108,6 +5227,7 @@ export function NewMakerDraftRoute() {remoteModelListStatus,remoteDraftState.status,deviceProviders,+ agentCatalogProviders,deviceProvidersLoading,vendorAuthGate,authVendor,@@ -5699,24 +5819,6 @@ export function NewMakerDraftRoute() {}/></div>- {/* Agent 在另一台电脑运行:任务和文件在本机,只有 Agent 在那台。与下面的远程设备- 标识同位置、同样式,两者互斥。 */}- {isAgentDeviceDraft && (- <div className="mt-3 flex max-w-full items-center gap-2 self-center rounded-full border border-[var(--border-default)] bg-[var(--surface-chip)] px-3 py-1 text-12 text-[var(--text-secondary)]">- {/* 与侧栏同一标识:Agent 图标 + 右上信号波纹。 */}- <VendorIcon- vendor={persistedAgentKind}- size={persistedAgentKind === 'cc' ? 14 : 13}- remote- colorClassName="text-[var(--folder-item-icon)]"- />- <span className="min-w-0 truncate">- {t('ccAgent.draft.agentDeviceBanner', {- device: draft.agentDeviceName ?? effectiveAgentDeviceId ?? '',- })}- </span>- </div>- )}{/* device-link:为远程设备项目新建对话时的明显标识。让用户清楚这条对话会建在被控设备上、属于那台机器的项目,而不是本机。放输入框正下方并与其水平居中(父列 items-start,靠 self-center 相对 w-full 的输入框居中)。 */}@@ -5745,6 +5847,27 @@ export function NewMakerDraftRoute() {</span></div>)}+ {/* Agent 在另一台电脑运行:只有 Agent 在那台,任务和文件留在任务所在电脑。与上面的+ 远程设备标识同样式;任务建到被控电脑时两条都显示(上一条已写明任务在哪台)。 */}+ {isAgentDeviceDraft && (+ <div className="mt-3 flex max-w-full items-center gap-2 self-center rounded-full border border-[var(--border-default)] bg-[var(--surface-chip)] px-3 py-1 text-12 text-[var(--text-secondary)]">+ {/* 与侧栏同一标识:Agent 图标 + 右上信号波纹。 */}+ <VendorIcon+ vendor={persistedAgentKind}+ size={persistedAgentKind === 'cc' ? 14 : 13}+ remote+ colorClassName="text-[var(--folder-item-icon)]"+ />+ <span className="min-w-0 truncate">+ {t(+ isDeviceLinkDraft+ ? 'ccAgent.draft.agentDeviceElsewhereBanner'+ : 'ccAgent.draft.agentDeviceBanner',+ { device: draft.agentDeviceName ?? effectiveAgentDeviceId ?? '' },+ )}+ </span>+ </div>+ )}{/* 零可用模型 → states.html B:单行动卡,不铺供应商清单。 */}{showProviderOnboardingCard && (<HomeZeroModelActiondiff --git a/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts b/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.tsindex fd75691ed6..d1c904a127 100644--- a/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts+++ b/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts@@ -55,6 +55,11 @@ export interface DeviceLinkCreateParams {* 落 `sessions.provider_id`,使新远程会话首个请求即按所选来源路由(与会话内切来源对称)。*/providerId?: string | null;+ /**+ * 远程 Agent:Agent 在同账号另一台电脑运行(被控电脑支持时才会给)。此时 model / providerId+ * 属于那台电脑的目录,被控电脑把它记进任务、经那台运行 Agent(与手机新建任务同一个参数)。+ */+ agentDeviceId?: string | null;}export interface DeviceLinkCreateArgs {@@ -75,6 +80,8 @@ export interface DeviceLinkCreateArgs {writableDirs?: string[];/** 仅当草稿显式选了非空来源时出现(null/空 = 跟随默认路由 → 不放进 args,provider_id 留 NULL)。 */providerId?: string;+ /** 仅当 Agent 在另一台电脑运行时出现;缺省 = Agent 在被控电脑本身。 */+ agentDeviceId?: string;}export function buildDeviceLinkCreateArgs(p: DeviceLinkCreateParams): DeviceLinkCreateArgs {@@ -98,6 +105,7 @@ export function buildDeviceLinkCreateArgs(p: DeviceLinkCreateParams): DeviceLink...(p.writableDirs && p.writableDirs.length > 0 ? { writableDirs: p.writableDirs } : {}),// providerId 同理:仅非空显式来源才放进 args;null/空 → 不带 → 被控端 provider_id 留 NULL(默认路由)。...(p.providerId ? { providerId: p.providerId } : {}),+ ...(p.agentDeviceId ? { agentDeviceId: p.agentDeviceId } : {}),};}@@ -124,9 +132,14 @@ export interface DeviceLinkSubmissionParams {extraDirs?: string[];writableDirs?: string[];candidate: DeviceLinkSubmissionCandidate;- /** **被控端**供应商目录(useDeviceProviders 经隧道拉到的那一份)。 */+ /**+ * 模型目录(useDeviceProviders 经隧道拉到的那一份):通常是**被控端**的;Agent 在另一台电脑运行时+ * 是那台的(来源也在那份目录里解析)。+ */deviceProviders: ProviderView[];capabilityAgentKind: AgentKind;+ /** 远程 Agent:运行 Agent 的另一台电脑;缺省 = 被控电脑本身。 */+ agentDeviceId?: string | null;}/**@@ -168,6 +181,7 @@ export function resolveDeviceLinkSubmission(p: DeviceLinkSubmissionParams): DeviextraDirs: p.extraDirs,writableDirs: p.writableDirs,providerId,+ agentDeviceId: p.agentDeviceId,});}@@ -230,6 +244,8 @@ export function buildProvisionalRemoteSession(p: ProvisionalRemoteSessionParams)status: 'active',// Session.agentKind 是本机形态('cc' | 'codex' | 'pi'),args 里是 maker-core 形态,这里转回来。agentKind: p.args.agentKind === 'claude-code' ? 'cc' : p.args.agentKind,+ // 乐观行就带上 Agent 所在电脑:会话页的模型按钮与目录从一开始就按那台显示。+ ...(p.args.agentDeviceId ? { agentDeviceId: p.args.agentDeviceId } : {}),extraDirs: p.args.extraDirs ?? [],writableDirs: p.args.writableDirs ?? [],createdAt: p.nowIso,diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 4e2c12d8de..352c25bebd 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -10959,7 +10959,8 @@"sessionInactive": "Session is no longer active","remoteProjectBanner": "New session in {{project}} on {{device}}","remoteDialogueBanner": "New chat on {{device}} (no project)",- "agentDeviceBanner": "Session and files stay on this computer — the Agent runs on {{device}}"+ "agentDeviceBanner": "Session and files stay on this computer — the Agent runs on {{device}}",+ "agentDeviceElsewhereBanner": "The Agent runs on {{device}}"},"jumpSession": {"emptyId": "Enter a sessionId to jump to",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 3e4dccdbdd..b76a65199e 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -10931,7 +10931,8 @@"sessionInactive": "セッションはすでにアクティブではありません","remoteProjectBanner": "{{device}} の {{project}} で新しいセッションを作成","remoteDialogueBanner": "{{device}} で新しい対話(プロジェクトなし)",- "agentDeviceBanner": "セッションとファイルはこのパソコンに残り、Agent は {{device}} で実行されます"+ "agentDeviceBanner": "セッションとファイルはこのパソコンに残り、Agent は {{device}} で実行されます",+ "agentDeviceElsewhereBanner": "Agent は {{device}} で実行されます"},"jumpSession": {"emptyId": "移動先の sessionId を入力してください",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 177ea0e42b..ae9a846baf 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -10931,7 +10931,8 @@"sessionInactive": "세션이 더 이상 활성 상태가 아닙니다","remoteProjectBanner": "{{device}}의 {{project}}에서 새 세션 만들기","remoteDialogueBanner": "{{device}}에서 새 대화(프로젝트 없음)",- "agentDeviceBanner": "세션과 파일은 이 컴퓨터에 남고, Agent는 {{device}}에서 실행됩니다"+ "agentDeviceBanner": "세션과 파일은 이 컴퓨터에 남고, Agent는 {{device}}에서 실행됩니다",+ "agentDeviceElsewhereBanner": "Agent는 {{device}}에서 실행됩니다"},"jumpSession": {"emptyId": "이동할 sessionId를 입력하세요",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 1c6b34d726..a75e0ebb34 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -10931,7 +10931,8 @@"sessionInactive": "任务已不再处于活跃状态","remoteProjectBanner": "在 {{device}} 的 {{project}} 中新建任务","remoteDialogueBanner": "在 {{device}} 上新建对话(不绑定项目)",- "agentDeviceBanner": "任务和文件留在本机,Agent 在 {{device}} 上运行"+ "agentDeviceBanner": "任务和文件留在本机,Agent 在 {{device}} 上运行",+ "agentDeviceElsewhereBanner": "Agent 在 {{device}} 上运行"},"jumpSession": {"emptyId": "请输入要跳转的任务 ID",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 4099674c19..5982b92213 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -10931,7 +10931,8 @@"sessionInactive": "任務已不再處於活躍狀態","remoteProjectBanner": "在 {{device}} 的 {{project}} 中新建任務","remoteDialogueBanner": "在 {{device}} 上新建對話(不繫結專案)",- "agentDeviceBanner": "任務和檔案留在本機,Agent 在 {{device}} 上執行"+ "agentDeviceBanner": "任務和檔案留在本機,Agent 在 {{device}} 上執行",+ "agentDeviceElsewhereBanner": "Agent 在 {{device}} 上執行"},"jumpSession": {"emptyId": "請輸入要跳轉的任務 ID",diff --git a/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.ts b/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.tsindex 841cb92965..810d60d0c8 100644--- a/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.ts@@ -5,12 +5,26 @@import { describe, expect, it } from 'vitest';import {+ controlledComputerSupportsRemoteAgent,controlledTaskAgentLocationReadable,controlledTaskSupportsAgentLocation,isControllerReadableAgentDevice,selectControlledTaskAgentDevices,} from '../controlledTaskAgentLocation';+describe('controlledComputerSupportsRemoteAgent', () => {+ it('被控电脑的供应商目录带「允许被远程调用」布尔标记(开或关都算)就支持远程控制下新建任务', () => {+ expect(controlledComputerSupportsRemoteAgent([{ remoteInvocationEnabled: false }])).toBe(true);+ expect(controlledComputerSupportsRemoteAgent([{}, { remoteInvocationEnabled: true }])).toBe(true);+ });++ it('旧版被控电脑不带这个标记、或目录还没读到:不支持', () => {+ expect(controlledComputerSupportsRemoteAgent([{}, {}])).toBe(false);+ expect(controlledComputerSupportsRemoteAgent([])).toBe(false);+ expect(controlledComputerSupportsRemoteAgent([{ remoteInvocationEnabled: 'yes' }])).toBe(false);+ });+});+describe('controlledTaskSupportsAgentLocation', () => {it('被控电脑投影了 agentDeviceId 字段(含 null)才算支持', () => {expect(controlledTaskSupportsAgentLocation({ id: 's1', agentDeviceId: null })).toBe(true);diff --git a/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts b/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.tsindex 814a208775..414e831653 100644--- a/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts+++ b/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts@@ -4,7 +4,9 @@* (apps/mobile/src/session/remoteAgentCatalogs.ts):模型列表在被控电脑自己的供应商之后,另列同账号* 其他电脑开放了远程调用的供应商;选另一台电脑的模型 = 把 Agent 挪过去,下一条消息生效。*- * 这里只放纯判定,接线在 CCAgentSessionView / ChatInput。+ * 远程控制下新建任务(建到被控电脑上)同样可以选第三台电脑的模型:任务建出来就带 agentDeviceId。+ *+ * 这里只放纯判定,接线在 CCAgentSessionView / NewMakerDraftRoute / ChatInput。*/import { isProviderShareAgentDeviceId } from '../../shared/providerShare';@@ -16,6 +18,17 @@ export function controlledTaskSupportsAgentLocation(session: object | null | undreturn !!session && Object.prototype.hasOwnProperty.call(session, 'agentDeviceId');}+/**+ * 远程控制下新建任务时,被控电脑认不认 `maker:create-session` 的 agentDeviceId(与手机新建任务同一+ * 判据):它的供应商目录带「允许被远程调用」布尔标记(与远程 Agent 同一版加入)。旧版被控电脑不带,+ * 不提供其他电脑的模型。目录还没读到时同样按不支持处理。+ */+export function controlledComputerSupportsRemoteAgent(+ providers: readonly { remoteInvocationEnabled?: unknown }[],+): boolean {+ return providers.some((provider) => typeof provider.remoteInvocationEnabled === 'boolean');+}+/*** 本机能否直接经 device-link 读这台电脑的模型目录。同账号的其他电脑可以;被控电脑收到的分享* (`share:<id>`,凭证只在被控电脑上)与本机自己(device-link 不连自己)读不到。@@ -43,8 +56,9 @@ export function controlledTaskAgentLocationReadable(input: {}/**- * 被控电脑上的任务可以让 Agent 去哪些电脑:本机的可选设备(已排除本机与手机)里去掉被控电脑本身,- * 留下在线的,以及任务当前 / 挂着的 Agent 所在电脑(离线也保留,让用户看得到、换得回来)。+ * 被控电脑上的任务(已建任务或新建任务草稿)可以让 Agent 去哪些电脑:本机的可选设备(已排除本机与+ * 手机)里去掉被控电脑本身,留下在线的,以及任务当前 / 挂着的 Agent 所在电脑(离线也保留,让用户+ * 看得到、换得回来)。* 本机自己收到的分享不列:被控电脑用不了。被控电脑收到的分享本机读不到目录,同样不列。*/export function selectControlledTaskAgentDevices(input: {diff --git a/apps/desktop/src/renderer/state/newMakerDraft.ts b/apps/desktop/src/renderer/state/newMakerDraft.tsindex dccfe345da..affaa9e239 100644--- a/apps/desktop/src/renderer/state/newMakerDraft.ts+++ b/apps/desktop/src/renderer/state/newMakerDraft.ts@@ -107,9 +107,10 @@ export interface NewMakerDraft {/** device-link 目标设备友好名(草稿页横幅展示),与 deviceLinkDeviceId 同源。 */deviceLinkDeviceName: string | null;/**- * Agent 在同账号另一台电脑上运行(任务、项目文件与命令仍在本机):那台电脑的 deviceId。- * 模型目录、Agent 登录与供应商都来自那台。与 remoteHostId / deviceLinkDeviceId 互斥;- * 与 deviceLinkDeviceId 同理**不跨重启持久化**(绑的是一台可能离线的活动设备)。+ * Agent 在同账号另一台电脑上运行(任务、项目文件与命令仍在任务所在电脑:本机,或 deviceLinkDeviceId+ * 那台被控电脑):运行 Agent 的那台电脑的 deviceId。模型目录、Agent 登录与供应商都来自那台。+ * 与 remoteHostId 互斥;换任务所在电脑即清空。与 deviceLinkDeviceId 同理**不跨重启持久化**+ * (绑的是一台可能离线的活动设备)。*/agentDeviceId: string | null;/** agentDeviceId 那台电脑的友好名(展示用)。 */@@ -855,8 +856,10 @@ export function patchDraft(patch: Partial<NewMakerDraft>): void {next.deviceLinkDeviceId = null;next.deviceLinkDeviceName = null;}- // 「Agent 在另一台电脑运行」只用于本机任务:任务本身建到远程设备或 SSH 主机时不成立。- if (next.deviceLinkDeviceId != null || next.remoteHostId != null) {+ // 「Agent 在另一台电脑运行」:本机任务,或远程控制下建到被控电脑的任务(被控电脑是否支持由草稿页+ // 判定)。任务建到 SSH 主机时不成立;换了任务所在电脑(本机 ↔ 被控电脑、被控电脑之间)时上一台的+ // 选择不再适用,除非同一个 patch 显式给了新值。运行 Agent 的电脑不能就是任务所在电脑。+ if (next.remoteHostId != null) {next.agentDeviceId = null;next.agentDeviceName = null;} else if ('agentDeviceId' in normalizedPatch) {@@ -864,6 +867,13 @@ export function patchDraft(patch: Partial<NewMakerDraft>): void {next.agentDeviceId =typeof agentDeviceId === 'string' && agentDeviceId.trim().length > 0 ? agentDeviceId.trim() : null;if (next.agentDeviceId == null) next.agentDeviceName = null;+ } else if (currentDraft.deviceLinkDeviceId !== next.deviceLinkDeviceId) {+ next.agentDeviceId = null;+ next.agentDeviceName = null;+ }+ if (next.agentDeviceId != null && next.agentDeviceId === next.deviceLinkDeviceId) {+ next.agentDeviceId = null;+ next.agentDeviceName = null;}// 换目标设备(含本机 ↔ 被控设备、被控设备 A ↔ B)→ 丢掉 Worker 富配置,只留// enabled + worker。model / providerId / effort / fast 都是**设备作用域**的:被控端diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex c636cdd43a..1cc7a31556 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -566,7 +566,13 @@ handler 无 sender 依赖;不加入共享任务访客白名单,不进入自带 `agentDeviceId`(null = A),换后档位记在控制端为那台电脑单独记的一份(改回 A 时写 A 的镜像)。A 收到的分享与控制端自己作为落点暂不在桌面控制端列出(控制端读不到那份目录);Agent 正在这类位置上时维持原有的 A 目录列表。实现见 `apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts`,回归见- `controlledTaskRemoteAgentPanel.test.tsx` 与 `remoteAgentRelocationWiring.test.ts`。远程控制下的新建任务暂未提供。+ `controlledTaskRemoteAgentPanel.test.tsx` 与 `remoteAgentRelocationWiring.test.ts`。+ 桌面远程控制下新建任务(建到 A 上,2026-10-09)同样开放:判据与手机新建相同(A 的 `maker:provider:list` 带+ `remoteInvocationEnabled` 布尔标记,共享任务访客与 SSH 不开放),模型面板先列 A 的全部供应商、再列其他同账号电脑+ 已开放的供应商;选中后草稿的模型目录改按那台,`maker:create-session` 带 `agentDeviceId`,权限档沿用 A 的草稿值,+ 不把那台的模型写进 A 的新建草稿记忆;默认来源解析、提交的来源与协同 Worker 收窄都只用那台已开放的供应商。+ 落点范围与已建任务相同(A 收到的分享与控制端自己暂不列出);协同草稿与它不互斥(与桌面本机新建一致)。回归见+ `controlledDraftRemoteAgentWiring.test.ts`。Mobile 新建任务(2026-10-08)同样列出这些供应商与分享来的供应商,选中后 `maker:create-session` 带`agentDeviceId`(与桌面新建同一参数,A 已接受);只有 A 的 `maker:provider:list` 带 `remoteInvocationEnabled`布尔标记时才提供(该标记与远程 Agent 同一版加入,旧 A 不列)。手机不按 A 的目录与登录校准这份选择,由运行 Agent