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(teammates): preserve supplied roles in default identities

zqchrisfb4f9491de39
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index 05c7832849..d120e8f293 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -2560,6 +2560,45 @@ describe('Bot canonical Session lifecycle', () => {
expect(identity).toContain('intelligent AI assistant running as a Cindy Bot');
});
+ it.each([
+ { identitySource: undefined, description: '负责财务分析,使用用户提供的数据,不编造账目。' },
+ { identitySource: ' ', description: '负责财务分析,使用用户提供的数据,不编造账目。' },
+ { identitySource: undefined, description: '财'.repeat(12000) },
+ { identitySource: '只使用用户明确指定的独立身份。', description: '列表中的简短介绍' },
+ ])('preserves description-only roles through creation and runtime (identity=$identitySource)', async ({ identitySource, description }) => {
+ const created = await invoke('local-db:bots:create', {
+ id: 'finance-role', name: 'Finance', avatar: '🤖', description, identitySource,
+ });
+ const expected = identitySource?.trim() || description;
+ expect(created.identitySource).toBe(expected);
+ const home = join(h.userDataDir, createHash('sha256').update(h.ownerScopeKey).digest('hex'), 'bots', created.id);
+ expect(readFileSync(join(home, 'SOUL.md'), 'utf8').trim()).toBe(expected);
+ const canonical = await invoke('local-db:bots:create-canonical-session', {
+ botId: created.id, expectedCanonicalSessionId: null, expectedProfileVersion: 1,
+ });
+ const opts: MakerSessionCreateOpts = {
+ id: canonical.session.id, agentKind: 'pi', workingDir: canonical.session.workingDir,
+ workspaceKind: 'dialogue', model: canonical.session.model, permissionMode: 'ask',
+ };
+ await hydrateBotProfileRuntime(opts, {}, { persistSnapshot: false });
+ expect(opts.botProfilePrompt).toBe(expected);
+ // The derived identity must still be accepted by the same API, including
+ // maximum-length descriptions copied back by editing/duplication clients.
+ const copy = await invoke('local-db:bots:create', {
+ id: 'finance-role-copy', name: 'Finance copy', avatar: '🤖', description,
+ identitySource: created.identitySource,
+ });
+ expect(copy.identitySource).toBe(expected);
+ });
+
+ it('uses the current description when an identity is explicitly cleared', async () => {
+ const description = '负责核对财务数据和解释预算差异。';
+ const updated = await invoke('local-db:bots:update', {
+ id: 'bot-1', description, identitySource: ' ',
+ });
+ expect(updated.identitySource).toBe(description);
+ });
+
it('restores the persisted default SOUL when an identity is explicitly cleared', async () => {
await invoke('local-db:bots:update', {
id: 'bot-1',
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index 39a03b2821..3685b46dbd 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -921,7 +921,7 @@ export async function createBotProfile(raw: unknown) {
const avatarImage = decodeBotAvatarImage(body.avatarImageBase64);
const avatarColor = readText(body.avatarColor, 'avatarColor', 32) || 'violet';
const identitySource =
- (draftEntry ? `${draftEntry.draft.background}\n\n${draftEntry.draft.conversationStyle}\n\nCurrent profile:\n${name}\n${description}` : readText(body.identitySource, 'identitySource', 12000)) || buildDefaultBotIdentity(name);
+ (draftEntry ? `${draftEntry.draft.background}\n\n${draftEntry.draft.conversationStyle}\n\nCurrent profile:\n${name}\n${description}` : readText(body.identitySource, 'identitySource', 12000)) || buildDefaultBotIdentity(name, description);
const skills = draftEntry ? draftEntry.draft.skillRefs : Array.isArray(body.skills)
? body.skills.filter((item): item is string => typeof item === 'string').slice(0, 100)
: [];
@@ -1155,7 +1155,7 @@ export async function updateBotProfile(raw: unknown, expectedVersion?: number,
const nextIdentitySource =
body.identitySource !== undefined
? readText(body.identitySource, 'identitySource', 12000) ||
- buildDefaultBotIdentity(patch.displayName ?? current.displayName)
+ buildDefaultBotIdentity(patch.displayName ?? current.displayName, patch.description ?? current.description)
: (version?.identitySource ?? '');
const profileContentChanged = botProfileContentChanged({
previousCapabilities: previous,
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botProfileRuntime.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botProfileRuntime.test.ts
index 3d944059c2..72f0a88ad5 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botProfileRuntime.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botProfileRuntime.test.ts
@@ -35,6 +35,12 @@ describe('Bot Profile runtime prompt', () => {
expect(prompt).toContain('You are Research helper');
});
+ it('uses a legacy empty identity’s role without replacing an explicit SOUL', () => {
+ const description = '负责财务分析。';
+ expect(buildBotProfilePrompt({ displayName: 'Finance', identitySource: ' ', description })).toBe(description);
+ expect(buildBotProfilePrompt({ displayName: 'Finance', identitySource: 'User-authored SOUL', description })).toBe('User-authored SOUL');
+ });
+
it('uses the same persisted default SOUL as the runtime fallback', () => {
const soul = buildDefaultBotIdentity('Research helper');
expect(
diff --git a/apps/desktop/src/main/maker-ipc/botProfileRuntime.ts b/apps/desktop/src/main/maker-ipc/botProfileRuntime.ts
index 26a2132dcf..bd0b89c155 100644
--- a/apps/desktop/src/main/maker-ipc/botProfileRuntime.ts
+++ b/apps/desktop/src/main/maker-ipc/botProfileRuntime.ts
@@ -265,9 +265,10 @@ function readStringList(value: unknown): string[] {
export function buildBotProfilePrompt(input: {
displayName: string;
identitySource: string;
+ description?: string;
}): string {
const displayName = input.displayName.trim();
- return input.identitySource.trim() || buildDefaultBotIdentity(displayName);
+ return input.identitySource.trim() || buildDefaultBotIdentity(displayName, input.description);
}
/**
@@ -783,6 +784,7 @@ export async function hydrateBotProfileRuntime(
opts.botProfilePrompt = buildBotProfilePrompt({
displayName: profile.displayName,
identitySource: identity,
+ description: profile.description,
});
const helperAvailable = !opts.remoteHostId || opts.agentKind === 'pi'
|| toolsetCatalog.some((item) => item.id === 'xdt_helper' && item.available !== false);
diff --git a/apps/desktop/src/shared/botProfileDefaults.ts b/apps/desktop/src/shared/botProfileDefaults.ts
index d246e62be9..4009be84f3 100644
--- a/apps/desktop/src/shared/botProfileDefaults.ts
+++ b/apps/desktop/src/shared/botProfileDefaults.ts
@@ -1,4 +1,8 @@
-export function buildDefaultBotIdentity(displayName: string): string {
+export function buildDefaultBotIdentity(displayName: string, description = ''): string {
+ // Preserve the user's supplied role verbatim when no separate SOUL was given.
+ // It has the same size limit as identitySource; adding a wrapper could make a
+ // valid description impossible to edit or duplicate through the profile API.
+ if (description.trim()) return description.trim();
const name = displayName.trim() || 'Cindy Bot';
return [
`You are ${name}, an intelligent AI assistant running as a Cindy Bot.`,
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 13c4606bc5..38a71258d6 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -140,7 +140,9 @@ harness + provider + model + effort + fastMode
已有“跟随默认”的伙伴继续读取当前有效链,不把历史创建时的型号当作显式覆盖。
未连接或没有可用默认组合时保持空值,不写入 GLM / Gateway 占位;伙伴创建和打开入口
复用客户端现有连接引导,配置完成后重新解析,不能创建没有模型的主任务。
-已有连接但推荐候选为空时,在创建前提供标准模型选择器;存量空模型伙伴打开后同样可直接选择模型恢复,不能只提供无效重试。
+创建只收名字和头像,不设置独立模型或推荐候选链。已有连接但应用默认不可用时,明确提示并保留配置入口,
+由用户恢复应用默认后重试,不在创建表单恢复伙伴模型选择器。已创建伙伴的设置仍保留统一模型选择器,
+用户可显式配置自己的候选链;跟随默认的伙伴仍等待应用默认恢复,不能偷偷替换型号。
全局伙伴设置保存用户自定义的默认候选链。单个伙伴没有显式覆盖时跟随全局链;一旦用户在伙伴设置里调整,
该伙伴保存自己的链。全局链由主进程按当前数据 owner 持久化,并由所有 Session 创建与 fallback
@@ -312,6 +314,8 @@ Session 任务遵守同一套机制与呈现契约:
- 创建只必填名字,头像可从图库选择或上传;工具等入口未提供头像时,同样从现有图库保存真实图片,
不回落已退役角色头像。创建后直接进入伙伴自身的对话。身份细节未提供时不编造,
不先调用辅助模型生成资料,也不按固定数量创建 Skill。已有生成草稿和自有 Skill 继续兼容。
+ 工具创建传入职责 description、未提供独立 identitySource 时,使用职责原文作为缺省身份并保存到 SOUL;
+ 已明确提供的身份优先,只有名字时才使用通用缺省身份,不编造额外背景或性格。
- Dash / LiZi 等旧角色模板已移除,只有默认 Cindy 保留内置身份。已有伙伴按持久 Profile 运行;
保留历史头像地址与模板标识的读取,未完成邀请使用已保存身份,不重建旧模板或补装角色 Skill。
- 新建与改名不能产生同名伙伴(NFKC、去首尾空格、不区分大小写)。头像可复用,姓名必须可区分。