Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bot): count post-reply interaction answers in the freshness watermark; never evict old items in additive mode
zqchris53876bc46d4d
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botWorkingMemory.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botWorkingMemory.test.tsindex bc97e3ef8a..bedd86fbac 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botWorkingMemory.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botWorkingMemory.test.ts@@ -155,6 +155,32 @@ describe('applyWorkingMemoryProposal', () => {expect(additive.commitments.map((c) => c.text)).toEqual(['新承诺', '把测试补上', '给设计稿加暗色模式', '周五前改完周报模板']);expect(additive.commitments.find((c) => c.id === 'c1')).toMatchObject({ messageId: 'old', updatedAt: 1 });expect(additive.commitments.find((c) => c.id === 'c1')).not.toHaveProperty('trigger');+ // 只追加模式下分区已满:新条目延后,不把最旧的旧条目挤出去。+ const fullWaiting = Array.from({ length: WORKING_MEMORY_LIMITS.waiting }, (_, i) => ({+ id: `w${i}`, text: `等第${i}个回复`, on: 'user' as const, updatedAt: i + 1,+ }));+ const crowded = applyWorkingMemoryProposal(+ { ...emptyWorkingMemory(), waiting: fullWaiting },+ {+ threads: [], commitments: [], corrections: [], recentlyDone: [], resolved: [],+ waiting: [{ text: '等新的回复', on: 'user', evidence: { messageId: 'a1', quote: '改完发你确认' } }],+ },+ messages,+ { now, coveredThroughRowid: 10, coveredThroughMessageId: 'old', additiveOnly: true },+ );+ expect(crowded.waiting.map((w) => w.id).sort()).toEqual(fullWaiting.map((w) => w.id).sort());+ // 非只追加模式照旧:新条目进账,最旧的被容量裁掉。+ const normal = applyWorkingMemoryProposal(+ { ...emptyWorkingMemory(), waiting: fullWaiting },+ {+ threads: [], commitments: [], corrections: [], recentlyDone: [], resolved: [],+ waiting: [{ text: '等新的回复', on: 'user', evidence: { messageId: 'a1', quote: '改完发你确认' } }],+ },+ messages,+ { now, coveredThroughRowid: 10, coveredThroughMessageId: 'a1' },+ );+ expect(normal.waiting.map((w) => w.text)).toContain('等新的回复');+ expect(normal.waiting.map((w) => w.id)).not.toContain('w0');});it('requires evidence to change a field of an existing item, allows evidenced clearing, and bumps time only on real change', () => {diff --git a/apps/desktop/src/main/maker-ipc/botWorkingMemory.ts b/apps/desktop/src/main/maker-ipc/botWorkingMemory.tsindex 214b1ec9be..99b937287d 100644--- a/apps/desktop/src/main/maker-ipc/botWorkingMemory.ts+++ b/apps/desktop/src/main/maker-ipc/botWorkingMemory.ts@@ -17,7 +17,7 @@import fs from 'node:fs/promises';import path from 'node:path';-import { and, eq, inArray, isNull, ne, sql } from 'drizzle-orm';+import { and, eq, inArray, isNull, ne, or, sql } from 'drizzle-orm';import { getDbClient } from '../localDb/client/current.js';import { botDelegations, botProfiles, botSessionLinks, messages, sessions } from '../localDb/schema.js';@@ -321,6 +321,7 @@ export function applyWorkingMemoryProposal(): T[] {const byText = new Map(existing.map((item) => [item.text, item] as const));const kept = new Map<string, T>();+ let added = 0;for (const item of proposed) {const text = clampText(item.text);if (!text || resolvedTexts.has(text)) continue;@@ -335,6 +336,10 @@ export function applyWorkingMemoryProposal(continue;}if (!evidenced) continue;+ // 只追加模式下新条目不能把旧条目挤出容量:区满了就延后新增(这一轮之后会被完整回补),+ // 否则 rewind 这一轮时来源清理只能删掉新条目,被挤掉的旧承诺回不来。+ if (opts.additiveOnly && existing.length + added >= cap) continue;+ added += 1;kept.set(text, build(null, item, { id: nextId(), text, messageId: item.evidence!.messageId, updatedAt: opts.now }));}// 提案没提到的旧条目保留(漏写 ≠ 完成),除非被 resolved 点名。@@ -708,6 +713,8 @@ export async function isWorkingMemoryFreshForSession(sessionId: string, userData).limit(1);if (typeof covered?.rowid !== 'number') return false;+ // 必须覆盖的水位 = 最近一条完成回复,或更晚落库的交互答复(计划审阅的批准 / 打回、提问卡+ // 答案在回复完成之后才写入):它们承载用户决定,没被复盘过就不能算新鲜。const [row] = await db.select({ rowid: sql<number | null>`MAX(rowid)` }).from(messages)@@ -715,8 +722,13 @@ export async function isWorkingMemoryFreshForSession(sessionId: string, userDataand(eq(messages.sessionId, sessionId),isNull(messages.rewindAt),- eq(messages.role, 'assistant'),- sql`json_valid(${messages.agentMeta}) AND json_extract(${messages.agentMeta}, '$.turnCompleted') = 1`,+ or(+ and(+ eq(messages.role, 'assistant'),+ sql`json_valid(${messages.agentMeta}) AND json_extract(${messages.agentMeta}, '$.turnCompleted') = 1`,+ ),+ inArray(messages.role, ['ask_user', 'plan_review']),+ ),),);const latest = row?.rowid;