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

Claude3082257c1e1e
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 009ea94222..c5e4192e32 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -899,10 +899,24 @@ describe('Bot canonical Session lifecycle', () => {
expect(loaded.identitySource).toContain('Identity written again');
});
+ it('seeds a never-created Bot Home on an unrelated save without touching an existing one', async () => {
+ const created = await invoke('local-db:bots:create', {
+ id: 'legacy-home', name: 'Legacy Home', identitySource: 'Stored identity',
+ userContextSource: 'Stored user context',
+ });
+ const home = join(h.userDataDir, createHash('sha256').update(h.ownerScopeKey).digest('hex'), 'bots', created.id);
+ // A profile from before the Home existed: no editable files yet.
+ rmSync(join(home, 'SOUL.md'));
+ rmSync(join(home, 'memories', 'USER.md'));
+ 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');
+ });
+
it('keeps hand-edited SOUL.md and USER.md through unrelated profile saves', async () => {
const created = await invoke('local-db:bots:create', {
id: 'hand-edited', name: 'Hand Edited', identitySource: 'Original identity',
- capabilities: { userContextSource: 'Original user context' },
+ userContextSource: 'Original user context',
});
const home = join(h.userDataDir, createHash('sha256').update(h.ownerScopeKey).digest('hex'), 'bots', created.id);
writeFileSync(join(home, 'SOUL.md'), 'Identity written in an editor\n');
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index d45fd75a9d..90a6cfa98c 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -167,6 +167,28 @@ function botUserContextSource(config: Record<string, unknown>): string {
return typeof config.userContextSource === 'string' ? config.userContextSource : '';
}
+/**
+ * Seed a Bot Home that was never created (profiles from before the folder existed)
+ * so any save leaves editable SOUL.md / USER.md. Idempotent: an existing SOUL.md
+ * means the Home exists and nothing is touched.
+ */
+async function ensureBotProfileFolderSeeded(
+ botId: string,
+ identitySource: string,
+ config: Record<string, unknown>,
+ userDataDir = ownerScopedUserDataPath(),
+): Promise<void> {
+ try {
+ await migrateBotProfileFolder(userDataDir, botId, {
+ identitySource,
+ userContextSource: botUserContextSource(config),
+ config: Object.fromEntries(Object.entries(config).filter(([key]) => key !== 'userContextSource')),
+ }, app.getPath('userData'));
+ } catch (cause) {
+ log.warn('seed bot profile folder failed', { botId, error: String(cause) });
+ }
+}
+
async function syncBotProfileFolder(
botId: string,
patch: { identitySource?: string; userContextSource?: string },
@@ -1361,6 +1383,8 @@ export async function updateBotProfile(raw: unknown, expectedVersion?: number,
...(nextIdentitySource !== (version?.identitySource ?? '') ? { identitySource: nextIdentitySource } : {}),
...(nextUserContextSource !== botUserContextSource(previous) ? { userContextSource: nextUserContextSource } : {}),
};
+ await ensureBotProfileFolderSeeded(id, nextIdentitySource, normalizedNextConfig, owner.userDataDir);
+ owner.assertCurrent();
if (Object.keys(folderPatch).length > 0) {
await syncBotProfileFolder(id, folderPatch, owner.userDataDir);
owner.assertCurrent();