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(bots): D11 leave demoted teammates out of the send-or-delegate choices

nanafb6b56236bb3
diff --git a/apps/desktop/src/renderer/features/bots/BotSessionView.tsx b/apps/desktop/src/renderer/features/bots/BotSessionView.tsx
index d4a6df0aa9..e326c9c056 100644
--- a/apps/desktop/src/renderer/features/bots/BotSessionView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotSessionView.tsx
@@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next';
import { Spinner } from '@/components/ui/spinner';
import { CCAgentSessionView } from '@/features/cc-agent/CCAgentSessionView';
import { useCompanionCloud } from './companionCloudStore';
+import { withoutShadowedBots } from './companionCloudPresentation';
import { useCompanionArrivalNotice } from './useCompanionArrivalNotice';
import { CompanionShadowBanner } from './CompanionShadowBanner';
import type { ComposerBotMention } from '@/lib/fileTypes';
@@ -87,7 +88,12 @@ function BotSessionGateView() {
const [reloadVersion, setReloadVersion] = useState(0);
const [gate, setGate] = useState<BotSessionGate>({ kind: 'loading' });
// The companion now runs on its main computer: this copy's main task is read only.
- const shadowed = useCompanionCloud().demotedBotIds.includes(botId ?? '');
+ const cloud = useCompanionCloud();
+ const shadowed = cloud.demotedBotIds.includes(botId ?? '');
+ // The send / delegate choices leave out copies that run on another computer or were retired
+ // there, like the roster (cloud-companions.md §6); read live, the gate's list is a one-off.
+ const readyMentions = gate.kind === 'ready' ? gate.mentions : null;
+ const mentions = useMemo(() => (readyMentions ? withoutShadowedBots(readyMentions, cloud) : []), [readyMentions, cloud]);
useBotIslandVisibleSession(gate.kind === 'ready' ? sessionId ?? null : null);
// The gate proves ownership once; name and avatar edited in settings must
// still reach the open chat's header and composer.
@@ -265,11 +271,11 @@ function BotSessionGateView() {
<main className="relative flex h-full min-w-0 overflow-hidden bg-[var(--surface)]">
{/* 私聊话题只属于本机的伙伴主对话;只读副本没有话题。 */}
<BotDmThreadHost enabled={gate.isCanonical && !readOnly} bot={identity ?? gate.identity}
- rootSessionId={sessionId} mentions={gate.mentions}>
+ rootSessionId={sessionId} mentions={mentions}>
{readOnly && botId ? <CompanionShadowBanner botId={botId} name={(identity ?? gate.identity).name} /> : null}
<div className="min-h-0 flex-1">
<CCAgentSessionView
- botMentions={gate.mentions}
+ botMentions={mentions}
botIdentity={chatIdentity ?? gate.identity}
botInvitationStage={gate.isCanonical ? liveInvitationStage : undefined}
botUnreadBoundaryAt={gate.unreadBoundaryAt}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx
index b5144666cb..f4f54d6f5c 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx
@@ -9,7 +9,12 @@ const h = vi.hoisted(() => ({
get: vi.fn(), list: vi.fn(), history: vi.fn(), invoke: vi.fn(),
profiles: [] as Array<{ id: string; name: string; avatar: string; avatarColor: string; invitation?: { stage: string } }>,
profileListeners: new Set<() => void>(),
+ cloud: null as null | import('../../../../shared/companionCloud').CompanionCloudSnapshot,
}));
+vi.mock('../companionCloudStore', async (importOriginal) => {
+ const original = await importOriginal<typeof import('../companionCloudStore')>();
+ return { ...original, useCompanionCloud: () => h.cloud ?? original.useCompanionCloud() };
+});
// 工作台在右侧栏里有自己的数据订阅,这里只验证伙伴对话的挂载与读位。
vi.mock('../botStore', async () => {
const { useSyncExternalStore } = await import('react');
@@ -31,13 +36,13 @@ vi.mock('../useBotIslandVisibleSession', () => ({ useBotIslandVisibleSession: ()
// The private-chat topic host belongs to the chat surface these tests isolate.
vi.mock('../BotDmThreadHost', () => ({ BotDmThreadHost: ({ children }: { children: import('react').ReactNode }) => <>{children}</> }));
vi.mock('@/features/cc-agent/CCAgentSessionView', () => ({
- CCAgentSessionView: ({ botIdentity, botInvitationStage, readOnly }: { botIdentity?: BotChatBinding; botInvitationStage?: string; readOnly?: boolean }) => {
+ CCAgentSessionView: ({ botIdentity, botInvitationStage, readOnly, botMentions }: { botIdentity?: BotChatBinding; botInvitationStage?: string; readOnly?: boolean; botMentions?: Array<{ id: string }> }) => {
const sessions = useRemoteProjectSessions();
const identity = resolveBotChatIdentity(botIdentity, h.params.sessionId);
// The real chat header requires session metadata from this mirror. Keep the
// production gate/store path; omit the unrelated editor and transcript tree.
if (h.params.deviceId && !sessions.some(row => row.id === h.params.sessionId)) return <div>metadata-loading</div>;
- return <div data-name={identity?.name} data-avatar={identity?.avatar} data-device-id={identity?.deviceId} data-read-only={readOnly} data-invitation-stage={botInvitationStage ?? ''}>{identity ? `companion:${identity.id}` : 'task controls'}</div>;
+ return <div data-name={identity?.name} data-avatar={identity?.avatar} data-device-id={identity?.deviceId} data-read-only={readOnly} data-invitation-stage={botInvitationStage ?? ''} data-mentions={(botMentions ?? []).map(item => item.id).join(',')}>{identity ? `companion:${identity.id}` : 'task controls'}</div>;
},
}));
import { BotSessionView } from '../BotSessionView';
@@ -47,7 +52,7 @@ beforeEach(() => {
h.params = { botId: 'bot', sessionId: 'chat', deviceId: undefined };
h.get.mockReset(); h.list.mockReset().mockResolvedValue([]); h.history.mockReset();
h.invoke.mockReset(); remoteProjectsStore.clear(); remoteProjectsStore.__resetPinnedOriginsForTest();
- h.profiles = []; h.profileListeners.clear();
+ h.profiles = []; h.profileListeners.clear(); h.cloud = null;
window.electronAPI = { localDb: { bots: { get: h.get, list: h.list, history: h.history } }, deviceLink: { invoke: h.invoke } } as unknown as Window['electronAPI'];
});
afterEach(() => { cleanup(); remoteProjectsStore.clear(); remoteProjectsStore.__resetPinnedOriginsForTest(); });
@@ -165,3 +170,12 @@ it.each(['history', 'channel'])('checks remote %s links before displaying a sear
expect(h.invoke).toHaveBeenCalledTimes(1);
}
});
+it('offers only teammates that run here to send to or delegate to, not copies that run elsewhere or were retired there', async () => {
+ h.get.mockResolvedValue({ id: 'bot', name: 'Melody', status: 'active', sessions: [{ id: 'chat', kind: 'chat', status: 'active', role: 'canonical' }] });
+ h.list.mockResolvedValue([{ id: 'bot', name: 'Melody' }, { id: 'kept', name: 'Kept' }, { id: 'retired', name: 'Retired' }, { id: 'away', name: 'Away' }]);
+ h.cloud = { enabled: true, selfDeviceId: 'desk', humanActorId: 'human', demotedBotIds: ['retired'], actors: [
+ { id: 'a-away', externalId: 'away', name: 'Away', avatar: null, homeDeviceId: 'laptop' }] };
+ render(<BotSessionView />);
+ const chat = await screen.findByText('companion:bot');
+ expect(chat.getAttribute('data-mentions')).toBe('kept');
+});
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index a637fdd364..c35249e0a8 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -177,7 +177,7 @@
- 导入的伙伴回复(`cloud-history:` 行)在本机和别的伙伴回复一样存为纯文本。早期版本把它存成文本块数组,聊天里会显示成原始 JSON;这些存量行不迁移数据库,读取时(`messageToCamel`)把全是文本块的数组还原成文本,所有读者(聊天、手机、搜索)看到的一致。
- 降级名单变化(接管开始时隐藏、完成时解除,或被交走)立即通知伙伴自主跟进层重读伙伴归属,换电脑后内置「跟进」例行任务马上补建,不再等下一次定时重读或伙伴资料变化。
- 已降级的本机副本:不领取执行、不上传、不导入对话,不同步名字与头像,不出现在伙伴列表、主入口选择、
- Cindy 多设备合并、本机 `list_agents` 和远程资源 `teammates` 列表(因此也不出现在其他设备的 `list_agents`),
+ Cindy 多设备合并、伙伴聊天「+ → 发消息或委派」的候选(按当前降级名单实时过滤,另一台电脑上运行或在那里被永久删除的伙伴不再出现)、本机 `list_agents` 和远程资源 `teammates` 列表(因此也不出现在其他设备的 `list_agents`),
例行任务跳过但定义保留。主任务的所有发送通路(界面、内部派发、插件、队列出队)都在真正发送前拒绝。降级名单另存于账号隔离的 `companion-cloud/shadowed.json`,切换账号后的第一次读取就换成新账号的名单(不沿用上一个账号的主力电脑与降级状态),启动后、服务器不可达
或功能关闭时同样生效;写盘失败时本次运行照样隐藏,并在之后每轮登记时重试写入,直到写入成功。打开它的主任务时只读(本机的设置抽屉不打开,设置从主力电脑上的伙伴进入):横幅「这个伙伴已在「X」上运行」,可打开主力电脑上的伙伴或
「在这台电脑继续」;主进程向降级副本主任务的发送一律拒绝。