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): 补种伙伴 Home 时只补缺失的文件

Claudef57762f20c93
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 c5e4192e32..92fd9423c8 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -911,6 +911,13 @@ describe('Bot canonical Session lifecycle', () => {
await invoke('local-db:bots:update', { id: created.id, pinned: true });
expect(readFileSync(join(home, 'SOUL.md'), 'utf8').trim()).toBe('Stored identity');
expect(readFileSync(join(home, 'memories', 'USER.md'), 'utf8').trim()).toBe('Stored user context');
+
+ // Only SOUL.md missing: seeding fills it without resetting a hand-edited USER.md.
+ rmSync(join(home, 'SOUL.md'));
+ writeFileSync(join(home, 'memories', 'USER.md'), 'User context written in an editor\n');
+ await invoke('local-db:bots:update', { id: created.id, pinned: false });
+ expect(readFileSync(join(home, 'SOUL.md'), 'utf8').trim()).toBe('Stored identity');
+ expect(readFileSync(join(home, 'memories', 'USER.md'), 'utf8')).toBe('User context written in an editor\n');
});
it('keeps hand-edited SOUL.md and USER.md through unrelated profile saves', async () => {
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts
index 80e7bce8e4..0dd8c0dbd3 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts
@@ -241,6 +241,16 @@ describe('搬家', () => {
expect((await readBotProfileFolder(root, 'bot-a')).identitySource).toBe('用户自己改过的');
});
+ it('缺 SOUL.md 时只补缺失的文件,留着的用户档案不被重置', async () => {
+ await writeBotProfileFolder(root, 'bot-a', { userContextSource: '用户手改的档案' });
+ const result = await migrateBotProfileFolder(root, 'bot-a', SEED);
+ expect(result.seeded).toBe(true);
+ const content = await readBotProfileFolder(root, 'bot-a');
+ expect(content.identitySource).toBe(SEED.identitySource);
+ expect(content.userContextSource).toBe('用户手改的档案');
+ expect(content.config).toEqual(SEED.config);
+ });
+
it('技能从旧目录整体搬进新家,内容与 slug 都不变', async () => {
const legacy = path.join(root, 'bot-skills', 'bot-a');
await fs.mkdir(path.join(legacy, 'skills', 'weekly-report'), { recursive: true });
diff --git a/apps/desktop/src/main/maker-ipc/botProfileFolder.ts b/apps/desktop/src/main/maker-ipc/botProfileFolder.ts
index a03da52f6e..232be019c9 100644
--- a/apps/desktop/src/main/maker-ipc/botProfileFolder.ts
+++ b/apps/desktop/src/main/maker-ipc/botProfileFolder.ts
@@ -328,7 +328,7 @@ export interface BotProfileFolderMigration {
* 两件事:
*
* 1. 用数据库里的当前值播种 `SOUL.md` / `memories/USER.md` / `config.json`。
- * **只在没有 SOUL.md 时做**,绝不覆盖用户已经改过的文件。
+ * **只在没有 SOUL.md 时做**,且只补缺失的那几个文件,绝不覆盖用户已经改过的文件。
* 2. 把 `<userData>/bot-skills/<botId>/` 整个搬成 `<家>/skills` 的邻居
* (`.claude-plugin/` 一并带走)。一个伙伴一个家,不该散在两处。
*
@@ -347,10 +347,14 @@ export async function migrateBotProfileFolder(
try {
await fs.access(soulPath);
} catch {
+ // Seed only what is missing: a hand-edited USER.md or config.json left next to
+ // a missing SOUL.md is still the user's content and must not be reset.
+ const exists = (relative: string) =>
+ fs.access(resolveInside(userDataDir, botId, relative)).then(() => true, () => false);
await writeBotProfileFolder(userDataDir, botId, {
identitySource: seed.identitySource,
- userContextSource: seed.userContextSource,
- config: seed.config,
+ ...((await exists(SLOT.userContext)) ? {} : { userContextSource: seed.userContextSource }),
+ ...((await exists(SLOT.config)) ? {} : { config: seed.config }),
});
seeded = true;
}