Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(remote-agent): 远程控制另一台电脑的任务时也能选到第三台电脑的远程供应商

Lizi2a6f9126dd8d
diff --git a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts
index bcae6897fb..4dd9226321 100644
--- a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts
+++ b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts
@@ -377,12 +377,12 @@ describe('ChatInput model source switching wiring', () => {
// device-link 老被控端 capabilities-only:联合列表的数据源是供应商目录,没有目录
// 就是一张空列表。判据必须是结构化的 unsupported,不是 providers.length===0
// (后者在加载中恒成立,会让面板每次打开先闪一下旧布局)。
- // 目录所在电脑 = 远程任务的被控端,或 Agent 在另一台电脑运行时的那台。
+ // 目录所在电脑 = Agent 在另一台电脑运行时的那台,否则远程任务的被控端。
expect(chatInputSource).toContain(
'const unifiedModelPanelEnabled = !catalogDeviceId || !remoteProviders.unsupported;',
);
// 已建任务换电脑的意图期内,目录跟随意图里的电脑(effectiveAgentDeviceId)。
- expect(chatInputSource).toContain('const catalogDeviceId = deviceLinkDeviceId ?? effectiveAgentDeviceId ?? undefined;');
+ expect(chatInputSource).toContain('const catalogDeviceId = effectiveAgentDeviceId ?? deviceLinkDeviceId ?? undefined;');
});
/**
diff --git a/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
new file mode 100644
index 0000000000..994f4083ca
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
@@ -0,0 +1,256 @@
+// @vitest-environment jsdom
+/**
+ * 远程控制的被控电脑上的任务也能选到第三台电脑的远程供应商(2026-10-09 用户反馈:A 远控 B 的
+ * 任务时选不到 C 的远程供应商,而手机远控 B 能选到)。
+ *
+ * 场景:同账号 A(本机,控制端)、B(被控电脑,任务在这台)、C(开了「允许被远程调用」的电脑)。
+ * 锁住模型面板的几件事:
+ * 1. 任务所在电脑那一格列 B 的目录(照远程控制列全部供应商),不拿 A 本机的目录顶替;
+ * 2. 其他电脑一段列 C 开放了远程调用的供应商,没开放的不列;
+ * 3. 点 C 的格浏览 C 的目录,选中那里的模型 = 带着 C 换 Agent 位置;
+ * 4. 不传 homeDeviceId 的本机任务照旧用本机目录。
+ */
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
+import React from 'react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+vi.mock('react-i18next', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('react-i18next')>()),
+ useTranslation: () => ({
+ t: (key: string, options?: Record<string, string>) => {
+ const table: Record<string, string> = {
+ 'newChat.modelSelector.modelListAria': '模型列表',
+ 'newChat.modelSelector.search.placeholderAll': '搜索模型…',
+ 'newChat.modelSelector.unified.favoritesGroup': '收藏',
+ 'newChat.modelSelector.unified.customize': '自定义',
+ 'newChat.modelSelector.unified.railAll': '全部',
+ 'newChat.modelSelector.unified.railRemoteProvider': `${options?.provider ?? ''} · ${options?.device ?? ''}`,
+ 'effortLevels.low': '低',
+ 'effortLevels.high': '高',
+ };
+ return table[key] ?? options?.defaultValue ?? key;
+ },
+ }),
+}));
+
+vi.mock('@/lib/scrollbarAutoHide', () => ({ flashScrollbar: vi.fn() }));
+
+vi.mock('@/hooks/useAgentCapabilities', () => ({
+ evictDeviceCapabilities: vi.fn(),
+ prefetchDeviceCapabilities: vi.fn(async () => {}),
+ useAgentCapabilities: () => ({
+ capabilities: { hasFastMode: false, effortLevels: [], availableModels: [] },
+ loading: false,
+ error: null,
+ }),
+}));
+vi.mock('@/hooks/useApiKey', () => ({ useApiKey: () => ({ hasSavedKey: true }) }));
+vi.mock('@/hooks/useConnectedSource', () => ({
+ useConnectedSource: () => ({ hasConnectedSource: true, loading: false }),
+}));
+vi.mock('@/hooks/useModelPricing', () => ({
+ useGatewayModelPricing: () => null,
+ useReferenceModelPricing: () => null,
+}));
+
+const catalogs = vi.hoisted(() => {
+ const provider = (
+ id: string,
+ name: string,
+ models: readonly (readonly [string, string])[],
+ extra: Record<string, unknown> = {},
+ ) => ({
+ id,
+ name,
+ source: 'user',
+ agents: ['claude-code'],
+ auth: { method: 'api-key' },
+ routing: { 'claude-code': {} },
+ connected: true,
+ models: {
+ 'claude-code': models.map(([modelId, modelName]) => ({
+ id: modelId,
+ name: modelName,
+ contextWindow: 200000,
+ efforts: ['low', 'high'],
+ defaultEffort: 'high',
+ })),
+ },
+ ...extra,
+ });
+ return {
+ /** A:本机(控制端)自己的目录。 */
+ local: [provider('a-local', 'A Local', [['a-model', 'A Model']])] as unknown[],
+ byDevice: {
+ // B:被控电脑。远程控制照常看到全部供应商,有没有开放远程调用都列。
+ 'device-b': [
+ provider('b-main', 'B Main', [['b-model', 'B Model']]),
+ provider('b-closed', 'B Closed', [['b-closed-model', 'B Closed Model']], {
+ remoteInvocationEnabled: false,
+ }),
+ ],
+ // C:开了「允许被远程调用」的电脑,只有一个供应商开放。
+ 'device-c': [
+ provider('c-open', 'C Open', [['c-model', 'C Model']], { remoteInvocationEnabled: true }),
+ provider('c-closed', 'C Closed', [['c-hidden-model', 'C Hidden Model']], {
+ remoteInvocationEnabled: false,
+ }),
+ ],
+ } as Record<string, unknown[]>,
+ };
+});
+
+vi.mock('@/hooks/useProviders', () => ({
+ useProviders: () => ({ providers: catalogs.local, providerOrder: [] }),
+}));
+vi.mock('@/hooks/useDeviceProviders', () => ({
+ evictDeviceProviders: vi.fn(),
+ prefetchDeviceProviders: vi.fn(async () => {}),
+ useDeviceProviders: (deviceId?: string) => ({
+ providers: deviceId ? (catalogs.byDevice[deviceId] ?? []) : [],
+ loading: false,
+ error: null,
+ unsupported: false,
+ }),
+}));
+vi.mock('@/hooks/useDevicesProviders', () => ({
+ useDevicesProviders: (deviceIds: readonly string[]) =>
+ new Map(
+ deviceIds.map((deviceId) => [
+ deviceId,
+ { providers: catalogs.byDevice[deviceId] ?? [], loading: false, error: null },
+ ]),
+ ),
+}));
+vi.mock('@/state/modelVisibilityPrefs', () => ({
+ isModelEnabled: () => true,
+ useModelVisibilityVersion: () => 0,
+}));
+vi.mock('@/state/deviceLinkModelMirror', () => ({
+ useDeviceLinkModelMirrorVersion: () => 0,
+}));
+vi.mock('@/hooks/useRemoteDeviceUsage', () => ({
+ useRemoteCodexAccountUsage: () => null,
+ useRemoteXaiSubscriptionUsage: () => null,
+}));
+vi.mock('@/hooks/useRemoteClaudeSubscriptionUsage', () => ({
+ useRemoteClaudeSubscriptionUsage: () => null,
+}));
+
+import { ModelSelectorContent } from '@/components/new-chat/ModelSelector';
+import { __resetForTest as resetEnginePrefs } from '@/state/modelEnginePrefs';
+import { __resetForTest as resetFavorites } from '@/state/modelFavorites';
+
+const devices = [{ deviceId: 'device-c', name: 'Studio' }];
+
+function renderControlledTaskPanel(
+ remoteAgent: Partial<React.ComponentProps<typeof ModelSelectorContent>['remoteAgent']> = {},
+ props: Partial<React.ComponentProps<typeof ModelSelectorContent>> = {},
+) {
+ const onRelocate = 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: true,
+ vendorKey: 'cc',
+ // 被控电脑上的任务:ChatInput 传的 deviceId 是模型目录所在电脑(此处 Agent 在 B)。
+ deviceId: 'device-b',
+ remoteAgent: {
+ devices,
+ selectedDeviceId: null,
+ homeDeviceId: 'device-b',
+ onRelocate,
+ ...remoteAgent,
+ },
+ ...props,
+ }),
+ );
+ return { onRelocate, onProviderChange };
+}
+
+const list = () => screen.getByRole('listbox');
+
+beforeEach(() => {
+ resetEnginePrefs();
+ resetFavorites();
+});
+
+afterEach(() => {
+ cleanup();
+});
+
+describe('被控电脑上的任务:模型面板列出第三台电脑的远程供应商', () => {
+ it('任务所在电脑那一格列被控电脑的全部供应商,不拿本机目录顶替', () => {
+ renderControlledTaskPanel();
+ 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(within(list()).getByText('B Model')).toBeTruthy();
+ expect(within(list()).queryByText('A Model')).toBeNull();
+ });
+
+ it('其他电脑一段只列开放了远程调用的供应商', () => {
+ renderControlledTaskPanel();
+ const remote = screen.getByRole('button', { name: 'C Open · Studio' });
+ expect(remote.querySelector('[data-remote-source-mark]')).not.toBeNull();
+ expect(screen.queryByRole('button', { name: 'C Closed · Studio' })).toBeNull();
+ });
+
+ it('浏览第三台电脑的目录,选中那里的模型 = 带着那台电脑换 Agent 位置', async () => {
+ const { onRelocate, onProviderChange } = renderControlledTaskPanel();
+ await act(async () => {
+ fireEvent.click(screen.getByRole('button', { name: 'C Open · Studio' }));
+ });
+ expect(within(list()).getByText('C Model')).toBeTruthy();
+ expect(within(list()).queryByText('C Hidden Model')).toBeNull();
+ expect(within(list()).queryByText('B Model')).toBeNull();
+
+ const row = within(list()).getByText('C Model').closest('[data-unified-anchor]') as HTMLElement;
+ await act(async () => {
+ fireEvent.click(row);
+ });
+ expect(onRelocate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ providerId: 'c-open',
+ modelId: 'c-model',
+ agent: 'claude-code',
+ agentDevice: { deviceId: 'device-c', name: 'Studio' },
+ }),
+ );
+ // 不经同一台电脑内换模型的链路(那条会把 C 的模型塞给被控电脑)。
+ expect(onProviderChange).not.toHaveBeenCalled();
+ });
+
+ it('Agent 已在第三台电脑:打开时停在那台的目录,任务所在电脑一格仍是被控电脑', () => {
+ renderControlledTaskPanel(
+ { selectedDeviceId: 'device-c' },
+ { deviceId: 'device-c', modelId: 'c-model', currentProviderId: 'c-open' },
+ );
+ expect(within(list()).getByText('C Model')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'C Open · Studio' }).getAttribute('aria-pressed')).toBe(
+ 'true',
+ );
+ expect(screen.getByRole('button', { name: 'B Main' })).toBeTruthy();
+ expect(screen.queryByRole('button', { name: 'A Local' })).toBeNull();
+ });
+});
+
+describe('本机任务不受影响', () => {
+ it('不传 homeDeviceId 时任务所在电脑一格仍是本机目录', () => {
+ renderControlledTaskPanel(
+ { homeDeviceId: undefined },
+ { deviceId: undefined, modelId: 'a-model', currentProviderId: 'a-local' },
+ );
+ expect(screen.getByRole('button', { name: 'A Local' })).toBeTruthy();
+ expect(screen.queryByRole('button', { name: 'B Main' })).toBeNull();
+ expect(within(list()).getByText('A Model')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'C Open · Studio' })).toBeTruthy();
+ });
+});
diff --git a/apps/desktop/src/renderer/__tests__/remoteAgentModelMemoryWiring.test.ts b/apps/desktop/src/renderer/__tests__/remoteAgentModelMemoryWiring.test.ts
index 031b42a0fc..af3af85c3e 100644
--- a/apps/desktop/src/renderer/__tests__/remoteAgentModelMemoryWiring.test.ts
+++ b/apps/desktop/src/renderer/__tests__/remoteAgentModelMemoryWiring.test.ts
@@ -23,16 +23,27 @@ const draftRouteSource = read('../features/cc-agent/NewMakerDraftRoute.tsx');
const authSource = read('../contexts/AuthContext.tsx');
describe('ChatInput:远程 Agent 的模型记忆', () => {
- it('远程控制不掺本机记忆;Agent 在另一台电脑时用那台电脑的记忆', () => {
+ it('Agent 在另一台电脑时用那台电脑的记忆(被控电脑上的任务也是);远程控制不掺本机记忆', () => {
const memo = chatInputSource.indexOf('const modelMemory = useMemo<ModelMemoryAccessors | undefined>');
expect(memo).toBeGreaterThan(0);
- const deviceLink = chatInputSource.indexOf('if (deviceLinkDeviceId) return undefined;', memo);
const agentDevice = chatInputSource.indexOf(
- 'if (catalogDeviceId) return agentDeviceModelMemoryAccessors(catalogDeviceId);',
+ 'if (effectiveAgentDeviceId) return agentDeviceModelMemoryAccessors(effectiveAgentDeviceId);',
memo,
);
- expect(deviceLink).toBeGreaterThan(memo);
- expect(agentDevice).toBeGreaterThan(deviceLink);
+ const mirror = chatInputSource.indexOf('if (modelMemoryOverride) return modelMemoryOverride;', memo);
+ const deviceLink = chatInputSource.indexOf('if (deviceLinkDeviceId) return undefined;', memo);
+ const local = chatInputSource.indexOf('return LOCAL_MODEL_MEMORY;', memo);
+ expect(agentDevice).toBeGreaterThan(memo);
+ // 那台电脑的来源 id 与被控电脑的不是一回事:先于被控电脑镜像判定。
+ expect(mirror).toBeGreaterThan(agentDevice);
+ expect(deviceLink).toBeGreaterThan(mirror);
+ expect(local).toBeGreaterThan(deviceLink);
+ });
+
+ it('任务所在电脑那份记忆:被控电脑上的任务用它的镜像,本机任务用本机预设', () => {
+ expect(chatInputSource).toContain(
+ 'const taskComputerModelMemory = deviceLinkDeviceId ? modelMemoryOverride : LOCAL_MODEL_MEMORY;',
+ );
});
it('草稿与已建任务的面板都拿到按电脑取记忆的入口', () => {
@@ -49,40 +60,43 @@ describe('ChatInput:远程 Agent 的模型记忆', () => {
expect(chatInputSource).toContain('useAgentDeviceModelMemoryVersion();');
});
- it('按模型所在目录写档位:另一台电脑写那台的一份,本机写本机预设', () => {
+ it('按模型所在目录写档位:另一台电脑写那台的一份,任务所在电脑写那份(没有就不写)', () => {
const helper = chatInputSource.indexOf('function rememberCatalogModelPrefs(');
expect(helper).toBeGreaterThan(0);
const body = chatInputSource.slice(helper, chatInputSource.indexOf('\n}\n', helper));
expect(body).toContain(
- 'const memory = deviceId ? agentDeviceModelMemoryAccessors(deviceId) : LOCAL_MODEL_MEMORY;',
+ 'const memory = deviceId ? agentDeviceModelMemoryAccessors(deviceId) : taskComputerMemory;',
);
+ expect(body).toContain('if (!memory) return;');
expect(body).toContain('memory.setEffort(agent, providerId, modelId, patch.effort)');
expect(body).toContain('memory.setFast(agent, providerId, modelId, patch.fast)');
});
- it('Agent 在另一台电脑的任务:换模后意图期调档记进那台的记忆,不写本机新建任务记忆', () => {
+ it('Agent 在另一台电脑的任务:换模后意图期调档记进那台的记忆,不写新建任务记忆', () => {
const start = chatInputSource.indexOf('const syncSessionDraftModelPrefs = useCallback(');
expect(start).toBeGreaterThan(0);
const agentDeviceBranch = chatInputSource.indexOf('if (agentDeviceId) {', start);
- const remember = chatInputSource.indexOf(
- 'rememberCatalogModelPrefs(agentDeviceId, agentKind, memoryProviderId, modelId, patch);',
- agentDeviceBranch,
+ const remember = chatInputSource.slice(agentDeviceBranch).search(
+ /rememberCatalogModelPrefs\(\s*agentDeviceId,\s*agentKind,\s*memoryProviderId,\s*modelId,\s*patch,\s*taskComputerModelMemory,\s*\);/,
);
const localWrites = chatInputSource.indexOf('setProviderModelChoice(agentKind,', start);
+ const remoteWrites = chatInputSource.indexOf("'maker:apply-new-maker-draft-pref'", start);
expect(agentDeviceBranch).toBeGreaterThan(start);
- expect(remember).toBeGreaterThan(agentDeviceBranch);
- // 分支在本机写入之前 return,不掺本机预设与新建任务记忆。
- const earlyReturn = chatInputSource.indexOf('return;', remember);
- expect(earlyReturn).toBeGreaterThan(remember);
+ expect(remember).toBeGreaterThan(0);
+ // 分支在本机写入、写穿被控电脑之前 return,不掺本机预设与两边的新建任务记忆。
+ const earlyReturn = chatInputSource.indexOf('return;', agentDeviceBranch + remember);
+ expect(earlyReturn).toBeGreaterThan(agentDeviceBranch + remember);
expect(localWrites).toBeGreaterThan(earlyReturn);
+ expect(remoteWrites).toBeGreaterThan(earlyReturn);
});
- it('已有任务换电脑:档位记进目标电脑那份目录的记忆', () => {
+ it('已有任务换电脑:档位记进目标电脑那份目录的记忆(改回任务所在电脑写那份)', () => {
expect(chatInputSource).toContain(
'rememberCatalogModelPrefs(relocateTo, targetAgentKind, providerId, newModelId, {',
);
+ expect(chatInputSource).toContain('}, taskComputerModelMemory);');
expect(chatInputSource).toMatch(
- /rememberCatalogModelPrefs\(\s*relocateTo,\s*targetAgentKind,\s*syncedProviderId,\s*newModelId,\s*syncedPatch,\s*\)/,
+ /rememberCatalogModelPrefs\(\s*relocateTo,\s*targetAgentKind,\s*syncedProviderId,\s*newModelId,\s*syncedPatch,\s*taskComputerModelMemory,\s*\)/,
);
});
});
diff --git a/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts b/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts
index 1415754c6b..3d827ab555 100644
--- a/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts
+++ b/apps/desktop/src/renderer/__tests__/remoteAgentRelocationWiring.test.ts
@@ -6,7 +6,10 @@
* 1. 面板浏览的不是 Agent 落点那台的目录时,同引擎 / 跨引擎两条会话链路都改道给 onRelocate;
* 2. 换位置带着目标电脑进切换事务,意图期内的后续改选沿用意图里的电脑;
* 3. 意图期内模型目录跟随意图里的电脑,选回任务当前所在电脑不带位置;
- * 4. 只有本机任务、且能走切换事务时才开放(SSH / 被控端 / 协同任务不开放)。
+ * 4. 只对本机任务、或支持远程 Agent 的被控电脑上的任务开放,且要能走切换事务(SSH / 旧被控端 /
+ * 共享任务访客 / 协同任务不开放)。
+ *
+ * 2026-10-09 起被控电脑上的任务也开放(用户反馈:A 远控 B 的任务选不到 C 的远程供应商,手机能)。
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
@@ -17,6 +20,7 @@ const read = (relative: string): string =>
const selectorSource = read('../components/new-chat/ModelSelector.tsx');
const chatInputSource = read('../components/new-chat/ChatInput.tsx');
+const sessionViewSource = read('../features/cc-agent/CCAgentSessionView.tsx');
describe('ModelSelector:浏览别的电脑的目录时改道换位置', () => {
it('只在已建任务、且浏览的不是落点目录时改道', () => {
@@ -68,14 +72,84 @@ describe('ChatInput:换位置进切换事务', () => {
it('意图期内目录跟随意图里的电脑', () => {
expect(chatInputSource).toContain(
- 'const catalogDeviceId = deviceLinkDeviceId ?? effectiveAgentDeviceId ?? undefined;',
+ 'const catalogDeviceId = effectiveAgentDeviceId ?? deviceLinkDeviceId ?? undefined;',
);
});
- it('只对本机任务、且能走切换事务时开放', () => {
+ it('只对本机任务、或支持远程 Agent 的被控端任务开放,且要能走切换事务', () => {
expect(chatInputSource).toContain(
- 'if (!sessionId || deviceLinkDeviceId || remoteHostId || !sessionEngineFilter) return undefined;',
+ 'if (!sessionId || !agentLocationAware || remoteHostId || !sessionEngineFilter) return undefined;',
);
expect(chatInputSource).toContain('agentDeviceId: selection.agentDevice?.deviceId ?? null,');
});
});
+
+describe('被控电脑上的任务:换 Agent 所在电脑', () => {
+ it('只在调用方传了候选电脑(被控端支持)、不是草稿 / SSH / 共享任务访客、位置本机读得到时开放', () => {
+ const start = chatInputSource.indexOf('const deviceLinkAgentLocation =');
+ expect(start).toBeGreaterThan(0);
+ const block = chatInputSource.slice(start, chatInputSource.indexOf('});\n', start));
+ for (const guard of [
+ '!!sessionId',
+ '!!deviceLinkDeviceId',
+ '!remoteHostId',
+ '!sharedGuest',
+ 'remoteAgentDevices !== undefined',
+ 'controlledTaskAgentLocationReadable({',
+ ]) {
+ expect(block).toContain(guard);
+ }
+ expect(chatInputSource).toContain(
+ 'const agentLocationAware = !deviceLinkDeviceId || deviceLinkAgentLocation;',
+ );
+ // 不支持时位置一律按被控电脑处理,与改动前相同。
+ expect(chatInputSource).toContain(
+ 'const agentDeviceId = agentLocationAware ? (_agentDeviceId ?? null) : null;',
+ );
+ });
+
+ it('换位置带给被控端的前提与面板入口同一个判定', () => {
+ const start = chatInputSource.indexOf('const relocateTo =');
+ expect(start).toBeGreaterThan(0);
+ expect(chatInputSource.slice(start, start + 200)).toContain('agentLocationAware &&');
+ });
+
+ it('面板不浏览其他电脑时列被控电脑的目录与它的镜像记忆', () => {
+ expect(chatInputSource).toContain(
+ '...(deviceLinkDeviceId ? { homeDeviceId: deviceLinkDeviceId } : {}),',
+ );
+ expect(chatInputSource).toContain(
+ '...(taskComputerModelMemory ? { localModelMemory: taskComputerModelMemory } : {}),',
+ );
+ expect(selectorSource).toContain(
+ 'const deviceId = remoteAgent ? (remoteBrowse?.deviceId ?? homeDeviceId) : deviceIdProp;',
+ );
+ // 只有浏览其他电脑时才按「允许被远程调用」裁剪;被控电脑自己的目录照远程控制列全部。
+ expect(selectorSource).toContain(
+ 'const remoteAgentBrowsing = remoteAgent !== undefined && remoteBrowse !== null;',
+ );
+ });
+
+ it('改回被控电脑的确认标题写那台电脑的名字', () => {
+ expect(chatInputSource).toContain('device: deviceLinkDeviceName || deviceLinkDeviceId,');
+ });
+
+ it('会话视图:候选电脑去掉被控电脑本身,不并入本机收到的分享;目录跟随 Agent 所在电脑', () => {
+ expect(sessionViewSource).toContain('controlledTaskSupportsAgentLocation(session) &&');
+ expect(sessionViewSource).toContain('!isSharedTaskPeer(remoteDeviceId) &&');
+ const branch = sessionViewSource.indexOf(
+ 'if (remoteDeviceId) {\n return controlledAgentLocation',
+ );
+ expect(branch).toBeGreaterThan(0);
+ const remoteBranch = sessionViewSource.slice(
+ branch,
+ sessionViewSource.indexOf(': undefined;', branch),
+ );
+ expect(remoteBranch).toContain('selectControlledTaskAgentDevices({');
+ expect(remoteBranch).not.toContain('providerShareDevices');
+ expect(sessionViewSource).toContain(
+ 'const catalogDeviceId = controlledAgentDeviceId ?? remoteDeviceId ?? agentDeviceId;',
+ );
+ expect(sessionViewSource).toContain('deviceLinkDeviceName={controlledDeviceName}');
+ });
+});
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index 39d4e13799..f7ad1d8cca 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -355,6 +355,8 @@ import {
agentDeviceModelMemoryAccessors,
useAgentDeviceModelMemoryVersion,
} from '@/state/agentDeviceModelMemory';
+import { useOptionalAuthDeviceId } from '@/contexts/AuthContext';
+import { controlledTaskAgentLocationReadable } from '@/lib/controlledTaskAgentLocation';
import {
setSessionFavoriteAnchor as setSessionFavoriteAnchorMemory,
useSessionFavoriteAnchor,
@@ -534,18 +536,22 @@ interface ChatInputProps {
* 由 CCAgentSessionView(reactive remoteDeviceId)/ NewMakerDraftRoute(目标设备)传入;本地会话 undefined。
*/
deviceLinkDeviceId?: string | null;
+ /** deviceLinkDeviceId 那台电脑的名字(换 Agent 所在电脑的确认文案用)。 */
+ deviceLinkDeviceName?: string | null;
/**
- * 本机任务、但 Agent 在同账号另一台电脑上运行:那台电脑的 deviceId。只决定**模型目录**
- * (能力、供应商、可用引擎)从哪台读 —— 任务、文件、命令、斜杠命令、附件仍按本机任务处理,
- * 切换模型也走本机 IPC(由本机转给那台的 Agent)。与 deviceLinkDeviceId 互斥。
+ * Agent 在同账号另一台电脑上运行:那台电脑的 deviceId(null = 任务所在电脑)。只决定**模型目录**
+ * (能力、供应商、可用引擎)从哪台读 —— 任务、文件、命令、斜杠命令、附件仍按任务所在电脑处理,
+ * 切换模型也走任务所在电脑(由它转给那台的 Agent)。被控电脑上的任务传被控电脑投影的值,只在
+ * 传了 remoteAgentDevices 时生效。
*/
agentDeviceId?: string | null;
/** agentDeviceId 那台电脑的名字(模型选择器悬停 / 读屏用);未知时显示「另一台电脑」。 */
agentDeviceName?: string | null;
/**
- * 新任务草稿可选的「Agent 在其他电脑运行」目标(在线的同账号电脑)。传了且非空时,模型面板
- * 左侧栏在本机供应商之后列出这些电脑上的供应商;选中那里的模型会经 onUnifiedDraftSelect 的
- * agentDevice 交给草稿层。已建任务 / 远程任务 / SSH 任务不传。
+ * 「Agent 在其他电脑运行」的可选目标(同账号电脑,不含任务所在电脑)。传了且非空时,模型面板
+ * 左侧栏在任务所在电脑的供应商之后列出这些电脑上的供应商:草稿里选中会经 onUnifiedDraftSelect
+ * 的 agentDevice 交给草稿层;已建任务里选中 = 把 Agent 挪过去。被控电脑上的已建任务只在那台
+ * 支持远程 Agent 时传;SSH 任务不传。
*/
remoteAgentDevices?: readonly { deviceId: string; name: string }[];
/**
@@ -894,8 +900,9 @@ const LOCAL_MODEL_MEMORY: ModelMemoryAccessors = {
};
/**
- * 把已有任务里选定的档位 / Fast 记进**这个模型所在目录**的那份记忆:deviceId = null 写本机预设,
- * 否则写本机为那台电脑单独记的一份。只写模型档位,不碰新建任务记忆。来源缺失时不写。
+ * 把已有任务里选定的档位 / Fast 记进**这个模型所在目录**的那份记忆:deviceId = null 写任务所在电脑
+ * 那份(本机任务 = 本机预设,被控电脑上的任务 = 被控电脑的镜像,没有镜像就不写),否则写本机为
+ * 那台电脑单独记的一份。只写模型档位,不碰新建任务记忆。来源缺失时不写。
*/
function rememberCatalogModelPrefs(
deviceId: string | null,
@@ -903,9 +910,11 @@ function rememberCatalogModelPrefs(
providerId: string | null | undefined,
modelId: string,
patch: { effort?: Effort; fast?: boolean },
+ taskComputerMemory: ModelMemoryAccessors | undefined,
): void {
if (!providerId || !modelId) return;
- const memory = deviceId ? agentDeviceModelMemoryAccessors(deviceId) : LOCAL_MODEL_MEMORY;
+ const memory = deviceId ? agentDeviceModelMemoryAccessors(deviceId) : taskComputerMemory;
+ if (!memory) return;
if (patch.effort !== undefined) memory.setEffort(agent, providerId, modelId, patch.effort);
if (patch.fast !== undefined) memory.setFast(agent, providerId, modelId, patch.fast);
}
@@ -1170,6 +1179,7 @@ export function ChatInput({
initialWorkingDir,
remoteHostId,
deviceLinkDeviceId: _deviceLinkDeviceId,
+ deviceLinkDeviceName = null,
agentDeviceId: _agentDeviceId,
agentDeviceName = null,
remoteAgentDevices,
@@ -1250,22 +1260,41 @@ export function ChatInput({
// device-link 远程会话:null = 已确认本地会话,undefined = 所有权尚未解析,string = 远程会话。
// 预测守卫用原始值区分 null vs undefined,下游通路继续用 ?? undefined 归一化。
const deviceLinkDeviceId = _deviceLinkDeviceId;
- /** Agent 在另一台电脑运行的本机任务(只影响模型目录来源)。 */
- const agentDeviceId = deviceLinkDeviceId ? null : (_agentDeviceId ?? null);
+ const sharedGuest = isSharedTaskPeer(deviceLinkDeviceId ?? '');
+ const selfDeviceId = useOptionalAuthDeviceId();
+ /**
+ * 远程控制的被控电脑上的已建任务,Agent 同样可以在第三台电脑运行(与手机同一套)。调用方只在
+ * 被控电脑支持时才传 remoteAgentDevices;草稿、SSH 任务与共享任务访客不走这条。Agent 现在或
+ * 挂着的位置是本机读不到目录的地方(被控电脑收到的分享 / 本机自己)时,维持原有的被控电脑列表。
+ */
+ const deviceLinkAgentLocation =
+ !!sessionId &&
+ !!deviceLinkDeviceId &&
+ !remoteHostId &&
+ !sharedGuest &&
+ remoteAgentDevices !== undefined &&
+ controlledTaskAgentLocationReadable({
+ agentDeviceId: _agentDeviceId,
+ pendingAgentDeviceId: makerChatStore.getAgentSwitchIntent(sessionId)?.agentDeviceId,
+ selfDeviceId,
+ });
+ /** 这个任务的 Agent 位置由本机呈现与切换:本机任务,或上面那种被控电脑上的任务。 */
+ const agentLocationAware = !deviceLinkDeviceId || deviceLinkAgentLocation;
+ /** Agent 在另一台电脑运行(null = 任务所在电脑);只影响模型目录来源。 */
+ const agentDeviceId = agentLocationAware ? (_agentDeviceId ?? null) : null;
/**
* 已建任务选了换电脑、下一条消息才生效时(意图带位置):模型目录、选中态与 trigger 都按意图里的
* 电脑显示。undefined = 没有换位置的意图。
*/
const intentAgentDeviceId =
- sessionId && !deviceLinkDeviceId && !remoteHostId
+ sessionId && agentLocationAware && !remoteHostId
? makerChatStore.getAgentSwitchIntent(sessionId)?.agentDeviceId
: undefined;
- /** 下一条消息时 Agent 所在的电脑(null = 本机)。 */
+ /** 下一条消息时 Agent 所在的电脑(null = 任务所在电脑)。 */
const effectiveAgentDeviceId =
intentAgentDeviceId !== undefined ? intentAgentDeviceId : agentDeviceId;
- /** 模型目录所在的电脑:远程任务在那台;Agent 在另一台电脑运行时也是那台。 */
- const catalogDeviceId = deviceLinkDeviceId ?? effectiveAgentDeviceId ?? undefined;
- const sharedGuest = isSharedTaskPeer(deviceLinkDeviceId ?? '');
+ /** 模型目录所在的电脑:Agent 在另一台电脑运行时是那台;否则远程任务在被控电脑,本机任务在本机。 */
+ const catalogDeviceId = effectiveAgentDeviceId ?? deviceLinkDeviceId ?? undefined;
const { t } = useTranslation();
const navigate = useNavigate();
const { preference: composerSendShortcutPreference } = useComposerSendShortcutPreference();
@@ -2058,19 +2087,25 @@ export function ChatInput({
// 该会话切走后再切回此模型,才会采用最新全局预设。
// - 首页草稿无 live 会话,NewMakerDraftRoute 会把当前显示模型的 props 也从全局预设派生。
// - device-link 必须使用被控端镜像 override;旧被控端拿不到镜像时宁可无记忆,也不掺控制端本机。
- // - 远程 Agent(Agent 在另一台电脑,任务在本机)用本机为那台电脑单独记的一份(按电脑分开,
- // 跨重启保留),不掺本机目录的记忆。
+ // - 远程 Agent(Agent 在另一台电脑;任务在本机,或在远程控制的被控电脑上)用本机为那台电脑
+ // 单独记的一份(按电脑分开,跨重启保留),不掺本机目录与被控电脑镜像的记忆。
useProviderModelMemoryVersion();
useAgentDeviceModelMemoryVersion();
const modelMemory = useMemo<ModelMemoryAccessors | undefined>(() => {
if (sshCodexHostId) return undefined;
+ // 模型目录在运行 Agent 的另一台电脑(那台的来源 id 与本机、被控电脑的都不是一回事)。
+ if (effectiveAgentDeviceId) return agentDeviceModelMemoryAccessors(effectiveAgentDeviceId);
// device-link 远程草稿 / 会话:用纯显示镜像 override(读被控端全局预设、写穿被控端)。
if (modelMemoryOverride) return modelMemoryOverride;
- // 模型目录在另一台电脑时不掺本机记忆(那台的来源 id 与本机的不是一回事)。
+ // 旧被控端拿不到镜像:宁可无记忆,也不掺控制端本机。
if (deviceLinkDeviceId) return undefined;
- if (catalogDeviceId) return agentDeviceModelMemoryAccessors(catalogDeviceId);
return LOCAL_MODEL_MEMORY;
- }, [catalogDeviceId, deviceLinkDeviceId, modelMemoryOverride, sshCodexHostId]);
+ }, [effectiveAgentDeviceId, deviceLinkDeviceId, modelMemoryOverride, sshCodexHostId]);
+ /**
+ * 任务所在电脑那份目录的档位记忆:本机任务 = 本机预设;被控电脑上的任务 = 被控电脑的镜像
+ * (写穿过去,旧被控端没有镜像时不记)。Agent 在别的电脑时浏览 / 换回任务所在电脑都用它。
+ */
+ const taskComputerModelMemory = deviceLinkDeviceId ? modelMemoryOverride : LOCAL_MODEL_MEMORY;
// 远程 Agent(仅本机新任务草稿):模型面板左侧栏同时列出其他电脑上的供应商。
const remoteAgentOptions = useMemo<RemoteAgentSelectorOptions | undefined>(
@@ -6261,10 +6296,18 @@ export function ChatInput({
opts.activeProviderId !== undefined ? opts.activeProviderId : selectedProviderId;
const memoryProviderId =
opts.memoryProviderId !== undefined ? opts.memoryProviderId : effectiveSourceId;
- // Agent 在另一台电脑运行的任务:模型属于那台的目录,不写回本机的新建任务记忆;
- // 档位与 Fast 只记进本机为那台电脑单独记的一份(换模后意图期调档也走这里)。
+ // Agent 在另一台电脑运行的任务(本机任务,或被控电脑上的任务):模型属于那台的目录,不写回
+ // 本机或被控电脑的新建任务记忆;档位与 Fast 只记进本机为那台电脑单独记的一份(换模后意图期
+ // 调档也走这里)。
if (agentDeviceId) {
- rememberCatalogModelPrefs(agentDeviceId, agentKind, memoryProviderId, modelId, patch);
+ rememberCatalogModelPrefs(
+ agentDeviceId,
+ agentKind,
+ memoryProviderId,
+ modelId,
+ patch,
+ taskComputerModelMemory,
+ );
return;
}
const remoteDeviceId =
@@ -6309,7 +6352,7 @@ export function ChatInput({
log.warn('session draft model preference sync failed:', err);
});
},
- [sessionId, deviceLinkDeviceId, agentDeviceId, currentModelAgentKind, selectedProviderId, effectiveSourceId, sshCodexHostId],
+ [sessionId, deviceLinkDeviceId, agentDeviceId, taskComputerModelMemory, currentModelAgentKind, selectedProviderId, effectiveSourceId, sshCodexHostId],
);
const persistFastModeChange = useCallback(
@@ -6682,13 +6725,14 @@ export function ChatInput({
await exclusiveTurn.ready;
// 远程 Agent:这次选择落在哪台电脑。左侧栏点了另一台电脑的目录就用那台;否则沿用已登记
// 的换位置意图 —— 意图期内在同一份目录里改选,不能被当成原来那台的选择。与任务当前
- // 所在电脑相同 = 位置不变,不带给 main(旧被控端 / 内部调用同样不带)。
+ // 所在电脑相同 = 位置不变,不带给 main(旧被控端 / 内部调用同样不带)。被控电脑上的任务
+ // 只在那台支持远程 Agent 时才带(null = 改回被控电脑)。
const pendingAgentDeviceId =
makerChatStore.getAgentSwitchIntent(sourceSessionId)?.agentDeviceId;
const requestedAgentDeviceId =
overrides?.agentDeviceId !== undefined ? overrides.agentDeviceId : pendingAgentDeviceId;
const relocateTo =
- !deviceLinkDeviceId &&
+ agentLocationAware &&
requestedAgentDeviceId !== undefined &&
requestedAgentDeviceId !== agentDeviceId
? requestedAgentDeviceId
@@ -6866,8 +6910,8 @@ export function ChatInput({
...(syncedEffort ? { effort: syncedEffort } : {}),
...(syncedFast !== undefined ? { fast: syncedFast } : {}),
};
- // 换电脑的选择属于目标电脑的目录:不写进本机的新建任务记忆,档位与 Fast 记进目标
- // 那份目录的记忆(意图期再调档同样落在这里)。
+ // 换电脑的选择属于目标电脑的目录:不写进新建任务记忆,档位与 Fast 记进目标那份目录的
+ // 记忆(意图期再调档同样落在这里;改回被控电脑时记进被控电脑的镜像)。
if (relocateTo !== undefined) {
rememberCatalogModelPrefs(
relocateTo,
@@ -6875,6 +6919,7 @@ export function ChatInput({
syncedProviderId,
newModelId,
syncedPatch,
+ taskComputerModelMemory,
);
} else {
syncSessionDraftModelPrefs(newModelId, syncedPatch, {
@@ -6943,7 +6988,7 @@ export function ChatInput({
rememberCatalogModelPrefs(relocateTo, targetAgentKind, providerId, newModelId, {
effort: newEffort,
fast: targetFast,
- });
+ }, taskComputerModelMemory);
} else {
syncSessionDraftModelPrefs(
newModelId,
@@ -6982,7 +7027,9 @@ export function ChatInput({
t,
providers,
modelMemory,
+ taskComputerModelMemory,
deviceLinkDeviceId,
+ agentLocationAware,
agentDeviceId,
effectiveAgentDeviceId,
remoteProviders.providers,
@@ -7110,7 +7157,8 @@ export function ChatInput({
// ── 远程 Agent · 已建任务:选另一台电脑(或本机)目录里的模型 = 把 Agent 挪过去 ──────────
// 与跨引擎同一套事务(performAgentSwitch:意图在下一条消息发送时落地,交接摘要接续)。换电脑
// 同样续接不了原生会话,复用同一份风险确认与「不再提示」偏好,只换说明文案。选回任务当前
- // 所在电脑(撤销挂着的换位置)或已确认过的同一目标不再问。
+ // 所在电脑(撤销挂着的换位置)或已确认过的同一目标不再问。被控电脑上的任务改回被控电脑时,
+ // 标题写那台电脑的名字(「这台电脑」在控制端看来是本机,会读错)。
const confirmAgentRelocation = useCallback(
(target: UnifiedSelectionAgentDevice) =>
confirmAgentSwitchRisk({
@@ -7121,25 +7169,31 @@ export function ChatInput({
copy: {
title: target
? t('newChat.chatInput.agentRelocation.titleOther', { device: target.name })
- : t('newChat.chatInput.agentRelocation.titleLocal'),
+ : deviceLinkDeviceId
+ ? t('newChat.chatInput.agentRelocation.titleOther', {
+ device: deviceLinkDeviceName || deviceLinkDeviceId,
+ })
+ : t('newChat.chatInput.agentRelocation.titleLocal'),
description: t('newChat.chatInput.agentRelocation.description'),
confirmText: t('newChat.chatInput.agentRelocation.confirm'),
cancelText: t('newChat.chatInput.agentRelocation.cancel'),
dontShowAgainLabel: t('newChat.chatInput.agentSwitch.confirmation.dontShowAgain'),
},
}),
- [agentDeviceId, intentAgentDeviceId, confirmDialog, t],
+ [agentDeviceId, intentAgentDeviceId, deviceLinkDeviceId, deviceLinkDeviceName, confirmDialog, t],
);
const sessionRemoteAgentOptions = useMemo<RemoteAgentSelectorOptions | undefined>(() => {
- // 只有本机任务、且会话内能走切换事务时才开放(SSH / 被控端任务 / 协同任务都不行)。
- if (!sessionId || deviceLinkDeviceId || remoteHostId || !sessionEngineFilter) return undefined;
+ // 本机任务,或被控电脑支持远程 Agent 的被控端任务;且会话内能走切换事务(SSH / 协同任务不行)。
+ if (!sessionId || !agentLocationAware || remoteHostId || !sessionEngineFilter) return undefined;
if (!remoteAgentDevices || (remoteAgentDevices.length === 0 && !effectiveAgentDeviceId)) {
return undefined;
}
return {
devices: remoteAgentDevices,
selectedDeviceId: effectiveAgentDeviceId,
- localModelMemory: LOCAL_MODEL_MEMORY,
+ // 被控电脑上的任务:没在浏览其他电脑时列被控电脑自己的目录与它的镜像记忆。
+ ...(deviceLinkDeviceId ? { homeDeviceId: deviceLinkDeviceId } : {}),
+ ...(taskComputerModelMemory ? { localModelMemory: taskComputerModelMemory } : {}),
deviceModelMemory: agentDeviceModelMemoryAccessors,
onRelocate: async (selection) => {
if (!(await confirmAgentRelocation(selection.agentDevice))) return false;
@@ -7152,7 +7206,9 @@ export function ChatInput({
};
}, [
sessionId,
+ agentLocationAware,
deviceLinkDeviceId,
+ taskComputerModelMemory,
remoteHostId,
sessionEngineFilter,
remoteAgentDevices,
diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
index e8df1f2c18..640cbbabc9 100644
--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
@@ -660,15 +660,21 @@ export interface RemoteAgentRelocation {
}
/**
- * 远程 Agent 的选择入口(本机新任务草稿与本机已建任务传)。模型面板的左侧栏在本机供应商之后
- * 列出这些电脑上的供应商;选中那台电脑上的模型 = Agent 在那台电脑运行,任务和文件仍在本机。
+ * 远程 Agent 的选择入口(本机新任务草稿、本机已建任务,以及远程控制的被控电脑上的已建任务传)。
+ * 模型面板的左侧栏在任务所在电脑的供应商之后列出这些电脑上的供应商;选中那台电脑上的模型 =
+ * Agent 在那台电脑运行,任务和文件仍在任务所在电脑。
*/
export interface RemoteAgentSelectorOptions {
- /** 可以运行 Agent 的其他电脑(已配对、在线)。 */
+ /** 可以运行 Agent 的其他电脑(已配对、在线);不含任务所在电脑。 */
devices: readonly { deviceId: string; name: string }[];
- /** 当前的 Agent 所在电脑(已建任务按下一条消息时的位置);null = 本机。 */
+ /** 当前的 Agent 所在电脑(已建任务按下一条消息时的位置);null = 任务所在电脑。 */
selectedDeviceId: string | null;
- /** 本机目录的模型记忆。Agent 当前在其他电脑时,浏览本机目录用它显示各行的档位。 */
+ /**
+ * 任务所在电脑:远程控制的被控电脑上的任务传那台的 deviceId,它的目录照远程控制列出全部供应商;
+ * 不传 = 本机任务,用本机目录。
+ */
+ homeDeviceId?: string;
+ /** 任务所在电脑目录的模型记忆。Agent 当前在其他电脑时,浏览那份目录用它显示各行的档位。 */
localModelMemory?: ModelMemoryAccessors;
/**
* 本机为某台电脑记的模型记忆。浏览不是 Agent 当前所在的那台电脑的目录时,用它显示 / 记住
@@ -1222,7 +1228,9 @@ function ModelSelectorContentView({
: null,
);
}, [remoteAgentDeviceId]);
- const deviceId = remoteAgent ? remoteBrowse?.deviceId : deviceIdProp;
+ // 没在浏览其他电脑时列任务所在电脑的目录:本机任务是本机,被控电脑上的任务是那台。
+ const homeDeviceId = remoteAgent?.homeDeviceId;
+ const deviceId = remoteAgent ? (remoteBrowse?.deviceId ?? homeDeviceId) : deviceIdProp;
/** 正在浏览的就是草稿当前落点的目录 —— 选中态、档位记忆与引擎集合只对它成立。 */
const browsingSelectedCatalog =
!remoteAgent || (remoteBrowse?.deviceId ?? null) === remoteAgentDeviceId;
@@ -1312,8 +1320,9 @@ function ModelSelectorContentView({
// (useDeviceProviders,隧道 maker:provider:list)。两 hook 都无条件调用(hooks 规则),按 deviceId 取。
const localProviders = useProviders();
const remoteProviders = useDeviceProviders(deviceId);
- // 远程 Agent 只能用那台电脑「允许被远程调用」的供应商(远程控制照常列全部)。
- const remoteAgentBrowsing = remoteAgent !== undefined && !!deviceId;
+ // 远程 Agent 只能用那台电脑「允许被远程调用」的供应商(远程控制照常列全部,被控电脑上的任务
+ // 浏览被控电脑自己的目录时也一样)。
+ const remoteAgentBrowsing = remoteAgent !== undefined && remoteBrowse !== null;
const remoteCatalogProviders = useMemo(
() =>
remoteAgentBrowsing
@@ -1546,23 +1555,38 @@ function ModelSelectorContentView({
});
}, [remoteAgentDevices, remoteDeviceCatalogs]);
const hasRemoteAgent = remoteAgent !== undefined;
+ // 任务所在电脑那一格:本机任务用本机目录与可见性偏好;被控电脑上的任务用被控电脑的目录与它的
+ // 可见性快照(顺序沿用被控端快照,不套本机排序,同远程控制)。
+ const homeDeviceProviders = useDeviceProviders(homeDeviceId);
+ const homeProviders = homeDeviceId ? homeDeviceProviders.providers : localProviders.providers;
+ const homeModelVisibilityOverrides = homeDeviceProviders.modelVisibilityOverrides;
const remoteAgentLocalRailItems = useMemo(() => {
if (!hasRemoteAgent) return undefined;
void visibilityVersion;
const entries = unifiedModelEntries({
- providers: localProviders.providers,
- isVisible: (providerId, model, agent) => isModelEnabled(agent, providerId, model),
+ providers: homeProviders,
+ isVisible: homeDeviceId
+ ? (providerId, model, agent) =>
+ isDeviceModelVisible(homeModelVisibilityOverrides, agent, providerId, model)
+ : (providerId, model, agent) => isModelEnabled(agent, providerId, model),
includePaymentRequired: true,
scope: 'draft',
});
- return buildUnifiedRail(entries, undefined, localProviders.providerOrder);
- }, [hasRemoteAgent, localProviders.providers, localProviders.providerOrder, visibilityVersion]);
+ return buildUnifiedRail(entries, undefined, homeDeviceId ? undefined : localProviders.providerOrder);
+ }, [
+ hasRemoteAgent,
+ homeDeviceId,
+ homeProviders,
+ homeModelVisibilityOverrides,
+ localProviders.providerOrder,
+ visibilityVersion,
+ ]);
const remoteAgentLocalLabel = useCallback(
(providerId: string): string => {
- const provider = localProviders.providers.find((entry) => entry.id === providerId);
+ const provider = homeProviders.find((entry) => entry.id === providerId);
return provider ? providerDisplayName(provider, t) : providerId;
},
- [localProviders.providers, t],
+ [homeProviders, t],
);
const remoteAgentLabelOf = useCallback(
(targetDeviceId: string, providerId: string): string => {
@@ -3210,7 +3234,7 @@ function ModelSelectorContentView({
? {
remoteSources: {
localRailItems: remoteAgentLocalRailItems,
- localProviders: localProviders.providers,
+ localProviders: homeProviders,
localProviderLabel: remoteAgentLocalLabel,
groups: remoteAgentGroups,
labelOf: remoteAgentLabelOf,
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index de20803693..a40bbfbfea 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -166,6 +166,11 @@ import { isDeviceLinkRemotePushCurrent } from '@/lib/remoteDataOwnerPushFence';
import { canAccessBillingSettings } from '@/components/settings/billingVisibility';
import { useDeviceProviders } from '@/hooks/useDeviceProviders';
import { useSelectableDevices } from '@/hooks/useControllableDevices';
+import {
+ controlledTaskAgentLocationReadable,
+ controlledTaskSupportsAgentLocation,
+ selectControlledTaskAgentDevices,
+} from '@/lib/controlledTaskAgentLocation';
import { useProviderShareAgentDevices } from '@/features/provider-share/useProviderShareAgentDevices';
import {
canExposeWritableDirsChange,
@@ -2091,46 +2096,79 @@ export function CCAgentSessionView({
// 与模型选择器同源(见下方 M35 vendor fallback effect)。本地 IPC 极快返回,有模块级缓存。
// device-link 远程会话用被控端经隧道带来的 providers(per-provider,fast 判定与本地同口径)。
const { providers: localProviders } = useProviders();
- const { mode: authMode, user: authUser, dataOwnerId } = useAuth();
+ const { mode: authMode, user: authUser, dataOwnerId, deviceId: selfDeviceId } = useAuth();
// Agent 在另一台电脑运行的任务:模型目录同样以那台为准(任务本身在本机)。
const agentDeviceId = remoteDeviceId ? undefined : (session?.agentDeviceId ?? undefined);
// 远程 Agent:本机任务的模型面板也列出其他电脑的供应商(选中 = 把 Agent 挪过去,下一条消息
// 生效)。Agent 当前所在电脑与挂着的换位置目标即使掉线也保留,让用户看得到、换得回来。
const { devices: selectableDevices } = useSelectableDevices();
const pendingAgentDeviceId = agentSwitchIntent?.agentDeviceId;
- // 供应商分享:别人分享给我的供应商也是远程 Agent 的落点(`share:<id>`),只并进这里,
- // 不进设备切换器。已暂停 / 已不在的分享只在它正是当前或即将使用的位置时保留。
+ // 远程控制的被控电脑上的任务:被控电脑支持远程 Agent 时,同样列出其他电脑的供应商(与手机同一
+ // 套)。共享任务访客读到的是自己账号的设备、与任务无关,SSH 任务不支持;Agent 现在或挂着的位置
+ // 在本机读不到目录的地方(被控电脑收到的分享 / 本机自己)时,维持原有的被控电脑列表。
+ const controlledAgentLocation =
+ !!remoteDeviceId &&
+ !session?.remoteHostId &&
+ !isSharedTaskPeer(remoteDeviceId) &&
+ controlledTaskSupportsAgentLocation(session) &&
+ controlledTaskAgentLocationReadable({
+ agentDeviceId: session?.agentDeviceId,
+ pendingAgentDeviceId,
+ selfDeviceId,
+ });
+ /** 被控电脑上的任务里 Agent 现在所在的电脑(undefined = 被控电脑本身)。 */
+ const controlledAgentDeviceId = controlledAgentLocation
+ ? (session?.agentDeviceId ?? undefined)
+ : undefined;
+ // 供应商分享:别人分享给我的供应商也是远程 Agent 的落点(`share:<id>`),只并进本机任务,
+ // 不进设备切换器(被控电脑上的任务用不了本机收到的分享)。已暂停 / 已不在的分享只在它正是
+ // 当前或即将使用的位置时保留。
const { devices: providerShareDevices, nameFor: providerShareDeviceName } =
useProviderShareAgentDevices([agentDeviceId, pendingAgentDeviceId]);
- const remoteAgentDevices = useMemo(
- () =>
- remoteDeviceId || session?.remoteHostId
- ? undefined
- : [
- ...selectableDevices
- .filter(
- (device) =>
- device.online ||
- device.deviceId === agentDeviceId ||
- device.deviceId === pendingAgentDeviceId,
- )
- .map(({ deviceId, name }) => ({ deviceId, name })),
- ...providerShareDevices,
- ],
- [
- selectableDevices,
- providerShareDevices,
- remoteDeviceId,
- session?.remoteHostId,
- agentDeviceId,
- pendingAgentDeviceId,
- ],
- );
- const agentDeviceName = agentDeviceId
- ? (selectableDevices.find((device) => device.deviceId === agentDeviceId)?.name ??
- providerShareDeviceName(agentDeviceId))
+ const remoteAgentDevices = useMemo(() => {
+ if (session?.remoteHostId) return undefined;
+ if (remoteDeviceId) {
+ return controlledAgentLocation
+ ? selectControlledTaskAgentDevices({
+ devices: selectableDevices,
+ controlledDeviceId: remoteDeviceId,
+ keepDeviceIds: [controlledAgentDeviceId, pendingAgentDeviceId],
+ })
+ : undefined;
+ }
+ return [
+ ...selectableDevices
+ .filter(
+ (device) =>
+ device.online ||
+ device.deviceId === agentDeviceId ||
+ device.deviceId === pendingAgentDeviceId,
+ )
+ .map(({ deviceId, name }) => ({ deviceId, name })),
+ ...providerShareDevices,
+ ];
+ }, [
+ selectableDevices,
+ providerShareDevices,
+ remoteDeviceId,
+ session?.remoteHostId,
+ controlledAgentLocation,
+ controlledAgentDeviceId,
+ agentDeviceId,
+ pendingAgentDeviceId,
+ ]);
+ const shownAgentDeviceId = agentDeviceId ?? controlledAgentDeviceId;
+ const agentDeviceName = shownAgentDeviceId
+ ? (selectableDevices.find((device) => device.deviceId === shownAgentDeviceId)?.name ??
+ providerShareDeviceName(shownAgentDeviceId))
+ : null;
+ /** 被控电脑的名字(换 Agent 所在电脑时「改回那台」的确认文案用)。 */
+ const controlledDeviceName = remoteDeviceId
+ ? (session?.deviceLinkDeviceName ||
+ selectableDevices.find((device) => device.deviceId === remoteDeviceId)?.name ||
+ null)
: null;
- const catalogDeviceId = remoteDeviceId ?? agentDeviceId;
+ const catalogDeviceId = controlledAgentDeviceId ?? remoteDeviceId ?? agentDeviceId;
const { providers: deviceProviders } = useDeviceProviders(catalogDeviceId);
const providers = catalogDeviceId ? deviceProviders : localProviders;
const canSwitchToClaudeSubscription = useMemo(() => {
@@ -5537,6 +5575,7 @@ export function CCAgentSessionView({
initialWorkingDir={session?.workingDir}
remoteHostId={session?.remoteHostId ?? null}
deviceLinkDeviceId={rightSidebarDeviceLinkDeviceId}
+ deviceLinkDeviceName={controlledDeviceName}
agentDeviceId={session?.agentDeviceId ?? null}
agentDeviceName={agentDeviceName}
{...(remoteAgentDevices ? { remoteAgentDevices } : {})}
diff --git a/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.ts b/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.ts
new file mode 100644
index 0000000000..841cb92965
--- /dev/null
+++ b/apps/desktop/src/renderer/lib/__tests__/controlledTaskAgentLocation.test.ts
@@ -0,0 +1,106 @@
+/**
+ * 远程控制的被控电脑上的任务换 Agent 所在电脑的纯判定(场景:同账号 A 远控 B 的任务,C 开了
+ * 「允许被远程调用」)。
+ */
+import { describe, expect, it } from 'vitest';
+
+import {
+ controlledTaskAgentLocationReadable,
+ controlledTaskSupportsAgentLocation,
+ isControllerReadableAgentDevice,
+ selectControlledTaskAgentDevices,
+} from '../controlledTaskAgentLocation';
+
+describe('controlledTaskSupportsAgentLocation', () => {
+ it('被控电脑投影了 agentDeviceId 字段(含 null)才算支持', () => {
+ expect(controlledTaskSupportsAgentLocation({ id: 's1', agentDeviceId: null })).toBe(true);
+ expect(controlledTaskSupportsAgentLocation({ id: 's1', agentDeviceId: 'device-c' })).toBe(true);
+ });
+
+ it('旧版被控电脑不投影这个字段:不支持', () => {
+ expect(controlledTaskSupportsAgentLocation({ id: 's1' })).toBe(false);
+ expect(controlledTaskSupportsAgentLocation(null)).toBe(false);
+ expect(controlledTaskSupportsAgentLocation(undefined)).toBe(false);
+ });
+});
+
+describe('isControllerReadableAgentDevice', () => {
+ it('同账号的其他电脑本机读得到', () => {
+ expect(isControllerReadableAgentDevice('device-c', 'device-a')).toBe(true);
+ });
+
+ it('被控电脑收到的分享、本机自己、空值都读不到', () => {
+ expect(isControllerReadableAgentDevice('share:abc', 'device-a')).toBe(false);
+ expect(isControllerReadableAgentDevice('device-a', 'device-a')).toBe(false);
+ expect(isControllerReadableAgentDevice(null, 'device-a')).toBe(false);
+ expect(isControllerReadableAgentDevice(undefined, 'device-a')).toBe(false);
+ });
+});
+
+describe('controlledTaskAgentLocationReadable', () => {
+ it('Agent 在被控电脑、或在本机读得到的电脑:可以在本机面板里换', () => {
+ expect(
+ controlledTaskAgentLocationReadable({
+ agentDeviceId: null,
+ pendingAgentDeviceId: undefined,
+ selfDeviceId: 'device-a',
+ }),
+ ).toBe(true);
+ expect(
+ controlledTaskAgentLocationReadable({
+ agentDeviceId: 'device-c',
+ pendingAgentDeviceId: null,
+ selfDeviceId: 'device-a',
+ }),
+ ).toBe(true);
+ });
+
+ it('现在或挂着的位置在分享 / 本机上:维持原有的被控电脑列表', () => {
+ expect(
+ controlledTaskAgentLocationReadable({
+ agentDeviceId: 'share:abc',
+ pendingAgentDeviceId: undefined,
+ selfDeviceId: 'device-a',
+ }),
+ ).toBe(false);
+ expect(
+ controlledTaskAgentLocationReadable({
+ agentDeviceId: null,
+ pendingAgentDeviceId: 'device-a',
+ selfDeviceId: 'device-a',
+ }),
+ ).toBe(false);
+ });
+});
+
+describe('selectControlledTaskAgentDevices', () => {
+ const devices = [
+ { deviceId: 'device-b', name: 'Office', online: true },
+ { deviceId: 'device-c', name: 'Studio', online: true },
+ { deviceId: 'device-d', name: 'Laptop', online: false },
+ { deviceId: 'device-e', name: 'Spare', online: false },
+ ];
+
+ it('去掉被控电脑本身,只留在线的电脑', () => {
+ expect(
+ selectControlledTaskAgentDevices({
+ devices,
+ controlledDeviceId: 'device-b',
+ keepDeviceIds: [],
+ }),
+ ).toEqual([{ deviceId: 'device-c', name: 'Studio' }]);
+ });
+
+ it('任务当前 / 挂着的 Agent 所在电脑离线也保留', () => {
+ expect(
+ selectControlledTaskAgentDevices({
+ devices,
+ controlledDeviceId: 'device-b',
+ keepDeviceIds: ['device-d', undefined, null],
+ }),
+ ).toEqual([
+ { deviceId: 'device-c', name: 'Studio' },
+ { deviceId: 'device-d', name: 'Laptop' },
+ ]);
+ });
+});
diff --git a/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts b/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts
new file mode 100644
index 0000000000..814a208775
--- /dev/null
+++ b/apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts
@@ -0,0 +1,63 @@
+/**
+ * 远程控制另一台电脑(被控电脑)上的任务时,任务的 Agent 也可以在同账号的第三台电脑上运行
+ * (远程 Agent,协议见 docs/dev-rules/protocol-compatibility.md「远程 Agent」)。与手机同一套口径
+ * (apps/mobile/src/session/remoteAgentCatalogs.ts):模型列表在被控电脑自己的供应商之后,另列同账号
+ * 其他电脑开放了远程调用的供应商;选另一台电脑的模型 = 把 Agent 挪过去,下一条消息生效。
+ *
+ * 这里只放纯判定,接线在 CCAgentSessionView / ChatInput。
+ */
+import { isProviderShareAgentDeviceId } from '../../shared/providerShare';
+
+/**
+ * 被控电脑支持远程 Agent:它投影的任务带 agentDeviceId 字段(值可以是 null)。旧版被控电脑不投影
+ * 这个字段,也不认换位置参数,维持原有调用与展示。
+ */
+export function controlledTaskSupportsAgentLocation(session: object | null | undefined): boolean {
+ return !!session && Object.prototype.hasOwnProperty.call(session, 'agentDeviceId');
+}
+
+/**
+ * 本机能否直接经 device-link 读这台电脑的模型目录。同账号的其他电脑可以;被控电脑收到的分享
+ * (`share:<id>`,凭证只在被控电脑上)与本机自己(device-link 不连自己)读不到。
+ */
+export function isControllerReadableAgentDevice(
+ deviceId: string | null | undefined,
+ selfDeviceId: string | null,
+): deviceId is string {
+ return !!deviceId && !isProviderShareAgentDeviceId(deviceId) && deviceId !== selfDeviceId;
+}
+
+/**
+ * 被控电脑上的任务能不能在本机的模型面板里换 Agent 所在电脑:任务当前与挂着的换位置意图都得是
+ * 被控电脑本身(null)或本机读得到目录的电脑。Agent 在被控电脑收到的分享上、或就在本机时,本机
+ * 列不出那份目录,维持原有的被控电脑列表与调用。
+ */
+export function controlledTaskAgentLocationReadable(input: {
+ agentDeviceId: string | null | undefined;
+ pendingAgentDeviceId: string | null | undefined;
+ selfDeviceId: string | null;
+}): boolean {
+ return [input.agentDeviceId, input.pendingAgentDeviceId].every(
+ (deviceId) => deviceId == null || isControllerReadableAgentDevice(deviceId, input.selfDeviceId),
+ );
+}
+
+/**
+ * 被控电脑上的任务可以让 Agent 去哪些电脑:本机的可选设备(已排除本机与手机)里去掉被控电脑本身,
+ * 留下在线的,以及任务当前 / 挂着的 Agent 所在电脑(离线也保留,让用户看得到、换得回来)。
+ * 本机自己收到的分享不列:被控电脑用不了。被控电脑收到的分享本机读不到目录,同样不列。
+ */
+export function selectControlledTaskAgentDevices(input: {
+ devices: readonly { deviceId: string; name: string; online: boolean }[];
+ controlledDeviceId: string;
+ keepDeviceIds: readonly (string | null | undefined)[];
+}): { deviceId: string; name: string }[] {
+ const keep = new Set(input.keepDeviceIds.filter((id): id is string => !!id));
+ return input.devices
+ .filter(
+ (device) =>
+ device.deviceId !== input.controlledDeviceId &&
+ (device.online || keep.has(device.deviceId)),
+ )
+ .map(({ deviceId, name }) => ({ deviceId, name }));
+}
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index e3cadd3d06..c636cdd43a 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -561,6 +561,12 @@ handler 无 sender 依赖;不加入共享任务访客白名单,不进入自
模型列表:A 自己的供应商之外,另列其他同账号电脑已开放远程调用的供应商(Mobile 直接经 device-link 读那台的
`maker:provider:list`,不新增 A 侧 channel);同一台电脑内换模型不带位置,换到另一台电脑先二次确认、再带
`agentDeviceId`(null = A)。共享任务访客不能换电脑。
+ 桌面远程控制 A 上的已建任务(2026-10-09)与手机同口径:A 投影的任务带 `agentDeviceId` 字段(含 null)才开放,
+ 控制端直接经 device-link 读第三台电脑的 `maker:provider:list`,A 自己的目录照远程控制列全部供应商,换位置同样
+ 带 `agentDeviceId`(null = A),换后档位记在控制端为那台电脑单独记的一份(改回 A 时写 A 的镜像)。A 收到的分享与
+ 控制端自己作为落点暂不在桌面控制端列出(控制端读不到那份目录);Agent 正在这类位置上时维持原有的 A 目录列表。
+ 实现见 `apps/desktop/src/renderer/lib/controlledTaskAgentLocation.ts`,回归见
+ `controlledTaskRemoteAgentPanel.test.tsx` 与 `remoteAgentRelocationWiring.test.ts`。远程控制下的新建任务暂未提供。
Mobile 新建任务(2026-10-08)同样列出这些供应商与分享来的供应商,选中后 `maker:create-session` 带
`agentDeviceId`(与桌面新建同一参数,A 已接受);只有 A 的 `maker:provider:list` 带 `remoteInvocationEnabled`
布尔标记时才提供(该标记与远程 Agent 同一版加入,旧 A 不列)。手机不按 A 的目录与登录校准这份选择,由运行 Agent