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(companion-cloud): D8 create the built-in follow-up routine as soon as a take-over finishes

nanaa6833f7bf4a2
diff --git a/apps/desktop/src/main/companion-cloud/__tests__/control.test.ts b/apps/desktop/src/main/companion-cloud/__tests__/control.test.ts
index fd11c8dae1..a295578b03 100644
--- a/apps/desktop/src/main/companion-cloud/__tests__/control.test.ts
+++ b/apps/desktop/src/main/companion-cloud/__tests__/control.test.ts
@@ -36,6 +36,7 @@ function setup(options: { home: string | null; handler?: ApiHandler; devices?: D
const { state } = memoryState();
const refresh = vi.fn(async () => undefined);
const publish = vi.fn();
+ const onShadowChanged = vi.fn();
const host: CompanionCloudHost = {
homes: createCompanionHomeRegistry(), openState: () => state,
readValues: options.readValues ?? (async () => options.values ?? [{ key: 'companion.profile.v1', value: { name: 'Mia' } }]),
@@ -50,9 +51,9 @@ function setup(options: { home: string | null; handler?: ApiHandler; devices?: D
};
runtime = startCompanionCloud({ api, host, endpoint: 'https://chat', humanActorId: 'human', selfDeviceId: 'desk', current: () => true,
bots: () => actors.filter(a => a.homeDeviceId === 'desk' && !state.isDemoted(a.externalId)).map(a => ({ botId: a.externalId, actorId: a.id, name: a.name })),
- actors: () => actors, refresh, publish, ...(options.syncProfile ? { syncProfile: options.syncProfile } : {}),
+ actors: () => actors, refresh, publish, onShadowChanged, ...(options.syncProfile ? { syncProfile: options.syncProfile } : {}),
...(options.paused ? { paused: options.paused } : {}) });
- return { runtime, actors, calls, local, state, refresh, publish };
+ return { runtime, actors, calls, local, state, refresh, publish, onShadowChanged };
}
describe('take over', () => {
@@ -65,6 +66,14 @@ describe('take over', () => {
expect(t.publish).toHaveBeenCalled();
});
+ it('tells what depends on the hidden copies when this one is hidden and again when it is lifted', async () => {
+ const t = setup({ home: 'laptop' });
+ expect(await t.runtime.takeOver('bot_mia')).toEqual({ ok: true });
+ // Hidden while it is built, visible once the take-over completes: each change is announced once.
+ expect(t.state.isDemoted('bot_mia')).toBe(false);
+ expect(t.onShadowChanged).toHaveBeenCalledTimes(2);
+ });
+
it('does not move the home while the cloud has no profile snapshot', async () => {
const t = setup({ home: 'laptop', handler: (route, method) => {
if (route === '/preferences' && method === 'GET') return [];
diff --git a/apps/desktop/src/main/companion-cloud/runtime.ts b/apps/desktop/src/main/companion-cloud/runtime.ts
index 1685743b68..d85e414b6b 100644
--- a/apps/desktop/src/main/companion-cloud/runtime.ts
+++ b/apps/desktop/src/main/companion-cloud/runtime.ts
@@ -186,6 +186,8 @@ export function startCompanionCloud(input: {
refresh?: () => Promise<void>;
/** Publish the registry snapshot after a local home change. */
publish?: () => void;
+ /** The set of hidden local copies changed (a copy was demoted or taken over): what depends on it re-reads. */
+ onShadowChanged?: () => void;
/** Publish the companions' actor name and avatar now (they sync outside the preferences). */
syncProfile?: (botId: string) => Promise<void>;
/** Room files (chatServerMedia): the mirror uploads the owner's attachments; readers download them. */
@@ -225,7 +227,13 @@ export function startCompanionCloud(input: {
const pick = (only: Set<string> | null) => input.bots()
.filter(bot => (!only || only.has(bot.botId)) && installOwner(bot.botId) === 'mine');
const actorOf = (botId: string) => (input.actors?.() ?? []).find(a => a.kind === 'bot' && !a.disabled && (a.externalId === botId || a.id === botId));
- const publish = () => { if (live()) input.publish?.(); };
+ let shadowKey = '';
+ const publish = () => {
+ if (!live()) return;
+ input.publish?.();
+ const key = [...state.demotedBotIds(), ...[...installs].flatMap(([botId, value]) => value.owner === 'other' ? [botId] : [])].sort().join('|');
+ if (key !== shadowKey) { shadowKey = key; input.onShadowChanged?.(); }
+ };
function loop(run: (only: Set<string> | null) => Promise<void>, intervalMs: number, debounceMs: number) {
let busy: Promise<void> | undefined;
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index e579a5c70d..0896af7496 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -4,6 +4,7 @@ import { createConversationListState } from '@cindy/maker-shared/chatConversatio
import { app, net } from 'electron';
import { uploadPublicAsset } from '../ossPublicUpload.js';
import { getClientEndpoint } from '../clientEndpointsService.js';
+import { signalBotAutonomyBotsChanged } from '../bot-autonomy/botsChangedSignal.js';
import { t } from '../i18n.js';
import { readFile as readMedia } from '../cindy-media/blobStore.js';
import { getAccessToken, refresh } from '../authManager.js';
@@ -800,6 +801,8 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
&& !companion?.isShadowed(a.externalId)).map(a => ({ botId: a.externalId, actorId: a.id, name: a.name })),
paused: botId => profiles.find(p => p.id === botId)?.status === 'paused',
actors: () => actors, refresh: refreshHomes, publish: publishHomes, syncProfile: syncActorProfiles,
+ // A copy that stops or starts being hidden changes who can follow tasks (the built-in follow-up routine).
+ onShadowChanged: signalBotAutonomyBotsChanged,
// The owner's attachments go with the conversation; other devices download them from the room.
media: { upload: async (room, source, files, author) => {
// The conversation mirror is not a file backup: large files stay a name in the room.
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index c170d2be70..a637fdd364 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -175,6 +175,7 @@
- 接管时导入房间里的全部对话为本机历史(读到房间第一条为止,读不完整则这次接管失败、稍后重试;合并 Cindy 同样如此;云端对话查看最多读最近约 5 万条),附件一起下载。服务器不回传导入来源 ID,本机按「角色 + 消息时间(毫秒)」
识别这台电脑当初导入上去的消息;已插入的云端历史(`cloud-history:<消息>`)和房间里直接发给伙伴、已投递进本机主任务的消息(`chat-direct:<执行>:<消息>`)按房间消息 ID 识别,都不重复插入(接管中途失败重试时,同一时间的拆分片段不会被误跳过);之后像「重启伙伴」一样从历史重建上下文,伙伴还有一轮在跑时等它结束再重建,期间副本保持降级。
- 导入的伙伴回复(`cloud-history:` 行)在本机和别的伙伴回复一样存为纯文本。早期版本把它存成文本块数组,聊天里会显示成原始 JSON;这些存量行不迁移数据库,读取时(`messageToCamel`)把全是文本块的数组还原成文本,所有读者(聊天、手机、搜索)看到的一致。
+- 降级名单变化(接管开始时隐藏、完成时解除,或被交走)立即通知伙伴自主跟进层重读伙伴归属,换电脑后内置「跟进」例行任务马上补建,不再等下一次定时重读或伙伴资料变化。
- 已降级的本机副本:不领取执行、不上传、不导入对话,不同步名字与头像,不出现在伙伴列表、主入口选择、
Cindy 多设备合并、本机 `list_agents` 和远程资源 `teammates` 列表(因此也不出现在其他设备的 `list_agents`),
例行任务跳过但定义保留。主任务的所有发送通路(界面、内部派发、插件、队列出队)都在真正发送前拒绝。降级名单另存于账号隔离的 `companion-cloud/shadowed.json`,切换账号后的第一次读取就换成新账号的名单(不沿用上一个账号的主力电脑与降级状态),启动后、服务器不可达