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。

fix(remote-agent): 远控任务换 Agent 位置的入口按被控电脑的能力判定

Lizi5c9d8919ea69
diff --git a/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
index 994f4083ca..e33f9a5671 100644
--- a/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
@@ -79,6 +79,8 @@ const catalogs = vi.hoisted(() => {
...extra,
});
return {
+ /** 读不到目录的电脑(离线)。 */
+ offline: new Set<string>(),
/** A:本机(控制端)自己的目录。 */
local: [provider('a-local', 'A Local', [['a-model', 'A Model']])] as unknown[],
byDevice: {
@@ -106,19 +108,24 @@ vi.mock('@/hooks/useProviders', () => ({
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,
- }),
+ useDeviceProviders: (deviceId?: string) =>
+ deviceId && catalogs.offline.has(deviceId)
+ ? { providers: [], loading: false, error: 'DEVICE_LINK_UNREACHABLE', unsupported: false }
+ : {
+ 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 },
+ catalogs.offline.has(deviceId)
+ ? { providers: [], loading: false, error: 'DEVICE_LINK_UNREACHABLE' }
+ : { providers: catalogs.byDevice[deviceId] ?? [], loading: false, error: null },
]),
),
}));
@@ -240,6 +247,30 @@ describe('被控电脑上的任务:模型面板列出第三台电脑的远程供
expect(screen.getByRole('button', { name: 'B Main' })).toBeTruthy();
expect(screen.queryByRole('button', { name: 'A Local' })).toBeNull();
});
+
+ it('Agent 所在的第三台电脑离线:仍能回到被控电脑的目录,选中即改回被控电脑运行', async () => {
+ catalogs.offline.add('device-c');
+ try {
+ const { onRelocate } = renderControlledTaskPanel(
+ { selectedDeviceId: 'device-c' },
+ { deviceId: 'device-c', modelId: 'c-model', currentProviderId: 'c-open' },
+ );
+ // 那台的目录读不到:它的供应商格不出现,但被控电脑那一格还在。
+ expect(screen.queryByRole('button', { name: 'C Open · Studio' })).toBeNull();
+ 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(onRelocate).toHaveBeenCalledWith(
+ expect.objectContaining({ providerId: 'b-main', modelId: 'b-model', agentDevice: null }),
+ );
+ } finally {
+ catalogs.offline.clear();
+ }
+ });
});
describe('本机任务不受影响', () => {
diff --git a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
index 3342276d21..1f69418ed1 100644
--- a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
@@ -870,10 +870,21 @@ describe('ChatInput 的入口门控与调用路由', () => {
expect(source).toMatch(
/!unifiedPanelActive &&\s*\n\s*sessionId &&\s*\n\s*vendorKey &&\s*\n\s*!remoteHostId &&\s*\n\s*sessionAgentSwitchSupported/,
);
- expect(source).toContain('ccCaps.capabilities?.supportsSessionAgentSwitch === true');
- expect(source).toContain('ccCaps.capabilities.supportsSessionAgentSwitchCas === true');
- expect(source).toContain('codexCaps.capabilities?.supportsSessionAgentSwitch === true');
- expect(source).toContain('codexCaps.capabilities.supportsSessionAgentSwitchCas === true');
+ expect(source).toContain('hostCcCaps.capabilities?.supportsSessionAgentSwitch === true');
+ expect(source).toContain('hostCcCaps.capabilities.supportsSessionAgentSwitchCas === true');
+ expect(source).toContain('hostCodexCaps.capabilities?.supportsSessionAgentSwitch === true');
+ expect(source).toContain('hostCodexCaps.capabilities.supportsSessionAgentSwitchCas === true');
+ // 能力位读**任务所在的被控电脑**,不跟模型目录走(2026-10-09 review P1):Agent 在离线的
+ // 第三台电脑时目录读不到,入口不能因此消失,否则改不回被控电脑。
+ expect(source).toMatch(
+ /const hostCcCaps = useAgentCapabilities\(\s*deviceLinkDeviceId \? 'claude-code' : null,\s*deviceLinkDeviceId \?\? undefined,\s*\);/,
+ );
+ expect(source).toMatch(
+ /const hostCodexCaps = useAgentCapabilities\(\s*deviceLinkDeviceId \? 'codex' : null,\s*deviceLinkDeviceId \?\? undefined,\s*\);/,
+ );
+ expect(source).toContain(
+ "hostCcCaps.capabilities?.supportsSessionAgentSwitchCas === true ||\n hostCodexCaps.capabilities?.supportsSessionAgentSwitchCas === true;",
+ );
const hostSource = readFileSync(
resolve(process.cwd(), 'src/main/maker-ipc/register.ts'),
'utf8',
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index f7ad1d8cca..002e9f614e 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -1850,18 +1850,29 @@ export function ChatInput({
// SSH 远程(remoteHostId)是另一套引擎生命周期,继续不支持,由调用点单独排除。
// Orca 会话(lead / worker)同样排除:被控端 handler 对带 orcaRole 的会话一律拒
// UNSUPPORTED_CAPABILITY。角色未加载(undefined)也 fail-closed,避免冷启动短暂露出入口。
+ // 切换事务与 SET_MODEL 都由**任务所在的被控电脑**执行,这两个能力位按它判定,不跟着模型目录
+ // 走:Agent 在第三台电脑(目录读那台)且那台离线时,仍要能在这里把 Agent 改回被控电脑。
+ // 目录本就在被控电脑时与上面同一份缓存;本机会话不读(下面 !deviceLinkDeviceId 直接放行)。
+ const hostCcCaps = useAgentCapabilities(
+ deviceLinkDeviceId ? 'claude-code' : null,
+ deviceLinkDeviceId ?? undefined,
+ );
+ const hostCodexCaps = useAgentCapabilities(
+ deviceLinkDeviceId ? 'codex' : null,
+ deviceLinkDeviceId ?? undefined,
+ );
const ccSupportsSessionAgentSwitch =
- ccCaps.capabilities?.supportsSessionAgentSwitch === true &&
- ccCaps.capabilities.supportsSessionAgentSwitchCas === true;
+ hostCcCaps.capabilities?.supportsSessionAgentSwitch === true &&
+ hostCcCaps.capabilities.supportsSessionAgentSwitchCas === true;
const codexSupportsSessionAgentSwitch =
- codexCaps.capabilities?.supportsSessionAgentSwitch === true &&
- codexCaps.capabilities.supportsSessionAgentSwitchCas === true;
+ hostCodexCaps.capabilities?.supportsSessionAgentSwitch === true &&
+ hostCodexCaps.capabilities.supportsSessionAgentSwitchCas === true;
// 此能力与原子 model-selection payload 同版发布。旧被控端会忽略 SET_MODEL 第 5 参,
// 因此缺能力位时保留原来的 SET_MODEL → SET_EFFORT → SET_FAST 兼容链;同引擎
// reselect 入口本就要求 CAS=true,不会退回这条非原子路径。
const remoteAtomicModelSelectionSupported =
- ccCaps.capabilities?.supportsSessionAgentSwitchCas === true ||
- codexCaps.capabilities?.supportsSessionAgentSwitchCas === true;
+ hostCcCaps.capabilities?.supportsSessionAgentSwitchCas === true ||
+ hostCodexCaps.capabilities?.supportsSessionAgentSwitchCas === true;
const sessionAgentSwitchSupported =
sessionOrcaRole === null &&
(!deviceLinkDeviceId || ccSupportsSessionAgentSwitch || codexSupportsSessionAgentSwitch);