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。

CR11: 主力电脑关闭远控时横幅按实时设备列表判断

nana7aca70c6078e
diff --git a/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx b/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx
index aae6c83f98..8488bedbf1 100644
--- a/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx
+++ b/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx
@@ -13,7 +13,8 @@ import { parseRemoteBots, type RemoteBot } from './remoteBotRoster';
import { markRemoteBotRead, useRemoteBots } from './useRemoteBots';
import { useBotIslandVisibleSession } from './useBotIslandVisibleSession';
import { useCompanionCloud } from './companionCloudStore';
-import { cloudCompanionAt } from './companionCloudPresentation';
+import { cloudCompanionAt, homeControlOff } from './companionCloudPresentation';
+import { useDeviceLinkDeviceList } from '@/features/device-link/useDeviceLinkDeviceList';
import { useDelayedFlag } from '@/features/cc-agent/workdir-browse/hooks/useDelayedFlag';
// Loaded only when a main computer is offline; keeps the live remote path light.
const CloudCompanionOfflineView = lazy(() => import('./CloudCompanionOfflineView')
@@ -29,6 +30,7 @@ export function RemoteBotSessionView() {
const bots = useRemoteBots();
const bot = bots.find((row) => row.id === botId && row.deviceId === deviceId);
const cloud = useCompanionCloud();
+ const deviceList = useDeviceLinkDeviceList();
const cloudActor = cloudCompanionAt(cloud, deviceId, botId);
const [ready, setReady] = useState<(RemoteBot & { sessionId: string; canonicalChat: true }) | null>(null);
const [validatedSessionId, setValidatedSessionId] = useState<string | null | undefined>(null);
@@ -119,7 +121,7 @@ export function RemoteBotSessionView() {
avatar={bot?.avatar || cloudActor.avatar}
avatarColor={bot?.avatarColor}
deviceName={bot?.deviceName || cloudActor.homeDevice?.name || ''}
- controlOff={!bot && cloudActor.homeDevice?.online === true && cloudActor.homeDevice.remoteControlEnabled === false}
+ controlOff={!bot && homeControlOff(cloudActor, deviceList)}
/>
</Suspense>
);
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx
index 3cf10245c6..9621c3e574 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx
@@ -13,10 +13,12 @@ const h = vi.hoisted(() => ({
online: true,
listed: true,
lastReplyAt: 0,
+ devices: null as Array<{ deviceId: string; online: boolean; remoteControlEnabled: boolean }> | null,
cloud: { enabled: false, selfDeviceId: null, humanActorId: null, actors: [], demotedBotIds: [] } as import('../../../../shared/companionCloud').CompanionCloudSnapshot,
cloudView: vi.fn(),
}));
vi.mock('../companionCloudStore', () => ({ useCompanionCloud: () => h.cloud }));
+vi.mock('@/features/device-link/useDeviceLinkDeviceList', () => ({ useDeviceLinkDeviceList: () => h.devices }));
vi.mock('../CloudCompanionOfflineView', () => ({
CloudCompanionOfflineView: (props: unknown) => { h.cloudView(props); return <div>cloud-offline-view</div>; },
}));
@@ -60,6 +62,7 @@ beforeEach(() => {
h.listed = true;
h.lastReplyAt = 0;
h.cloud = { enabled: false, selfDeviceId: null, humanActorId: null, actors: [], demotedBotIds: [] };
+ h.devices = null;
h.cloudView.mockReset();
h.pin.mockReset();
h.merge.mockReset();
@@ -172,3 +175,23 @@ it('calls a main computer that is not listed offline, and "control off" only whe
rerender(<RemoteBotSessionView />);
expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: true }));
});
+
+it('reads "control off" from the live device list, so a stale snapshot neither hides it nor invents it', async () => {
+ h.listed = false;
+ const home = { deviceId: 'home', name: 'Home', online: false, isSelf: false };
+ const actor = { id: 'a-writer', externalId: 'writer', name: 'Writer', avatar: null, homeDeviceId: 'home', homeDevice: home };
+ h.cloud = { enabled: true, selfDeviceId: 'desk', humanActorId: 'human', demotedBotIds: [], actors: [actor] };
+ const { rerender } = render(<RemoteBotSessionView />);
+ await screen.findByText('cloud-offline-view');
+ // The snapshot still says offline, but the device list shows it online with remote control off.
+ h.devices = [{ deviceId: 'home', online: true, remoteControlEnabled: false }];
+ rerender(<RemoteBotSessionView />);
+ expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: true }));
+ // Switched on again, and a computer that is simply offline (it reports off too) stays "offline".
+ h.devices = [{ deviceId: 'home', online: true, remoteControlEnabled: true }];
+ rerender(<RemoteBotSessionView />);
+ expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: false }));
+ h.devices = [{ deviceId: 'home', online: false, remoteControlEnabled: false }];
+ rerender(<RemoteBotSessionView />);
+ expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: false }));
+});
diff --git a/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts b/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts
index 9485b810f8..c8902940ad 100644
--- a/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts
+++ b/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts
@@ -91,3 +91,18 @@ export function companionRunsHere(cloud: CompanionCloudSnapshot, localBotIds: re
const home = cloud.enabled ? cloud.actors.find((actor) => actor.externalId === botId)?.homeDeviceId : undefined;
return !home || home === cloud.selfDeviceId;
}
+
+/**
+ * The main computer is online but has not allowed remote control. Read from the live device list
+ * (what the devices page shows), since the snapshot's copy of the presence is only rebuilt when a
+ * home changes and goes stale; the snapshot answers only for a computer the list does not have.
+ */
+export function homeControlOff(
+ actor: CompanionCloudActor | undefined,
+ devices: ReadonlyArray<{ deviceId: string; online: boolean; remoteControlEnabled: boolean }> | null,
+): boolean {
+ if (!actor?.homeDeviceId) return false;
+ const live = devices?.find((device) => device.deviceId === actor.homeDeviceId);
+ if (live) return live.online && live.remoteControlEnabled === false;
+ return actor.homeDevice?.online === true && actor.homeDevice.remoteControlEnabled === false;
+}
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index bbe1e846f8..35e5d5c23d 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -90,7 +90,7 @@
- 桌面:主力电脑持续连不上超过 15 秒,或打开时就连不上,聊天区改为云端对话(只读)与横幅
「主力电脑「<名字>」离线 · 在这台电脑继续」。
- 这台设备从没列到过主力电脑名下的伙伴(只能从云端补行),点开直接进入云端对话。
- - 横幅只在设备列表明确说主力电脑在线、但它没有开放「允许同账号设备控制本机」时写「没有开放远程控制」;其余情况(进程不在、连不上、在线状态还没刷新)都按离线处理。
+ - 横幅只在设备列表明确说主力电脑在线、但它没有开放「允许同账号设备控制本机」时写「没有开放远程控制」;其余情况(进程不在、连不上、在线状态还没刷新)都按离线处理。这个判断读渲染层实时的设备列表(与设置页「我的设备」同一份数据),只有列表里没有这台电脑时才退回云端快照里的状态——快照里的在线与远控状态只在伙伴主页变化时重建,不随设备上下线或开关远控刷新。
- 云端对话与在线聊天显示同样的消息:主人发的消息(包括主人在主力电脑上直接输入的)都上云;别的来源
(任务、其他伙伴、插件、共享成员、定时任务、IM 渠道、群聊)发进来的消息加「〔来自…〕」前缀;只有不在聊天里
显示的内部续接输入不上云。