Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 补种后同一轮对账就收进留着的手改 USER.md
Claude9f33e2efd508
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.tsindex 92fd9423c8..6e20bbac15 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts@@ -899,6 +899,25 @@ describe('Bot canonical Session lifecycle', () => {expect(loaded.identitySource).toContain('Identity written again');});+ it('adopts a kept hand-edited USER.md in the same reconcile that re-seeds a missing SOUL.md', async () => {+ const created = await invoke('local-db:bots:create', {+ id: 'partial-home', name: 'Partial Home', identitySource: 'Stored identity',+ userContextSource: 'Stored user context',+ });+ const home = join(h.userDataDir, createHash('sha256').update(h.ownerScopeKey).digest('hex'), 'bots', created.id);+ rmSync(join(home, 'SOUL.md'));+ writeFileSync(join(home, 'memories', 'USER.md'), 'User context written in an editor');+ const canonical = await invoke('local-db:bots:create-canonical-session', {+ botId: created.id, expectedCanonicalSessionId: null, expectedProfileVersion: 1,+ });+ expect(canonical.canonicalSessionId).toBeTruthy();+ const loaded = await invoke('local-db:bots:get', created.id);+ expect(loaded).toMatchObject({+ currentVersion: 2, identitySource: 'Stored identity', userContextSource: 'User context written in an editor',+ });+ expect(readFileSync(join(home, 'SOUL.md'), 'utf8')).toBe('Stored identity');+ });+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',diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolderSync.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolderSync.test.tsindex f5aac13a3e..7efc544083 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolderSync.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolderSync.test.ts@@ -123,6 +123,23 @@ describe('对账', () => {expect(h.deriveVersion).not.toHaveBeenCalled();});+ it('只缺 SOUL.md 时补种后立刻收进留着的手改 USER.md,不等下一次对账', async () => {+ const h = harness();+ const reads = [+ folder({ identitySource: '', userContextSource: '手改的用户画像' }),+ folder({ userContextSource: '手改的用户画像' }),+ ];+ h.deps.readFolder = async () => reads.shift()!;+ expect(await syncBotProfileFromFolder('bot-a', h.deps)).toBe('derived');+ expect(h.seedFolder).toHaveBeenCalledOnce();+ expect(h.deriveVersion).toHaveBeenCalledWith({+ botId: 'bot-a',+ identitySource: '你是纸老虎,一个爱做菜的厨子。',+ config: { model: 'claude-sonnet-4-6', harness: 'claude', userContextSource: '手改的用户画像' },+ expectedCurrentVersion: 3,+ });+ });+it('数据库里没有这个伙伴时不碰磁盘', async () => {const h = harness({ snapshot: null });expect(await syncBotProfileFromFolder('bot-a', h.deps)).toBe('missing');diff --git a/apps/desktop/src/main/maker-ipc/botProfileFolderSync.ts b/apps/desktop/src/main/maker-ipc/botProfileFolderSync.tsindex dd692e0573..a12129b2c4 100644--- a/apps/desktop/src/main/maker-ipc/botProfileFolderSync.ts+++ b/apps/desktop/src/main/maker-ipc/botProfileFolderSync.ts@@ -93,11 +93,28 @@ export async function syncBotProfileFromFolder(: '',config: stripUserContext(snapshot.config),});- return 'seeded';+ // 播种只补缺失的文件:旁边留着的手改 USER.md 要在这一轮就收进来,而不是等下一次。+ // 重读后身份仍为空(例如空的 SOUL.md 还在)时绝不派生,不能把人格抹成空。+ const seeded = await deps.readFolder(botId);+ if (!seeded.identitySource.trim() || botProfileFolderMatchesSnapshot(seeded, snapshot)) {+ return 'seeded';+ }+ await deriveFromFolder(botId, seeded, snapshot, deps);+ return 'derived';}if (botProfileFolderMatchesSnapshot(folder, snapshot)) return 'unchanged';+ await deriveFromFolder(botId, folder, snapshot, deps);+ return 'derived';+}++async function deriveFromFolder(+ botId: string,+ folder: BotProfileFolderContent,+ snapshot: BotProfileSnapshot,+ deps: BotProfileFolderSyncDeps,+): Promise<void> {await deps.deriveVersion({botId,identitySource: folder.identitySource,@@ -105,7 +122,6 @@ export async function syncBotProfileFromFolder(config: { ...snapshot.config, userContextSource: folder.userContextSource },expectedCurrentVersion: snapshot.currentVersion,});- return 'derived';}function stripUserContext(config: Record<string, unknown>): Record<string, unknown> {