更新memory读取机制,新增前需要先list阅读已有的内容

This commit is contained in:
2026-06-04 15:35:01 +08:00
parent 0188240d62
commit 8a1785c244
7 changed files with 67 additions and 129 deletions
+7 -7
View File
@@ -37,7 +37,7 @@ describe("MemoryStore", () => {
expect(second.detail).toBe("memory already existed");
});
it("rejects rewritten memories that are too similar to an existing one", async () => {
it("allows rewritten memories when the content is not exactly the same", async () => {
await store.upsert("workspace", "project-1", {
content: "保存记忆前先查看当前 workspace memory,避免重复写入相同约束。",
source: "tool",
@@ -48,12 +48,12 @@ describe("MemoryStore", () => {
source: "tool",
});
expect(result.changed).toBe(false);
expect(result.detail).toBe("similar memory already exists");
expect(result.entry?.content).toBe("保存记忆前先查看当前 workspace memory,避免重复写入相同约束。");
expect(result.changed).toBe(true);
expect(result.detail).toBe("memory stored");
expect(result.entry?.content).toBe("写入前先看一遍当前 workspace 记忆,避免把同样的约束重复保存进去。");
});
it("rejects replace when the new content overlaps a similar existing memory", async () => {
it("rejects replace when the new content would become an exact duplicate", async () => {
const first = await store.upsert("user", "actor-1", {
content: "回答时默认使用中文,并保持结论先行。",
source: "tool",
@@ -64,13 +64,13 @@ describe("MemoryStore", () => {
});
const result = await store.replace("user", "actor-1", second.entry?.id ?? "", {
content: "默认使用中文回答,结论放在最前面。",
content: "回答时默认使用中文,并保持结论先行。",
source: "tool",
});
expect(first.changed).toBe(true);
expect(second.changed).toBe(true);
expect(result.changed).toBe(false);
expect(result.detail).toBe("replacement would overlap with a similar existing memory");
expect(result.detail).toBe("replacement would duplicate an existing memory");
});
});