Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(memory): forget matching details in multiline notes

Afloat827ba816aa07
diff --git a/server/memory-forget-details.test.ts b/server/memory-forget-details.test.ts
new file mode 100644
index 0000000000..55faab3480
--- /dev/null
+++ b/server/memory-forget-details.test.ts
@@ -0,0 +1,40 @@
+import { readFileSync, rmSync } from "node:fs";
+import { join } from "node:path";
+import { beforeEach, expect, it } from "vitest";
+
+import { DATA_DIR } from "./config.ts";
+import { passageMatcher } from "./memory-entries.ts";
+import { botMemoryUpdate, withoutMentions } from "./memory-forget.ts";
+import { closeMessageDb } from "./message-db.ts";
+import { workspaceDir, WORKSPACES_DIR, writeMemoryFile, writeMemoryTopic } from "./workspace.ts";
+
+beforeEach(() => {
+ closeMessageDb();
+ rmSync(DATA_DIR, { recursive: true, force: true });
+ rmSync(WORKSPACES_DIR, { recursive: true, force: true });
+});
+
+const kept = '- 2026-10-27 · from chat "Oak Street" · Likes tea\n With milk.\n';
+const address = "- 2026-10-27 · Home address:\n 14 Oak Street\n Second floor.\n";
+
+it("forgets a passage in a continuation across the notebook, topics and archive", () => {
+ const bot = "forget-note-details";
+ writeMemoryFile(bot, address + kept);
+ writeMemoryTopic(bot, "home.md", address + kept);
+ writeMemoryTopic(bot, "archive.md", address + kept);
+ expect(botMemoryUpdate(bot, { action: "forget", oldText: "Oak Street" }, { source: "chat", aboutMe: null }))
+ .toEqual({ ok: true, forgotten: ["Home address:", "Home address:", "Home address:"], aboutMe: [] });
+ for (const name of ["MEMORY.md", "memory/home.md", "memory/archive.md"]) {
+ expect(readFileSync(join(workspaceDir(bot), name), "utf8")).toBe(kept);
+ }
+});
+
+it("matches a passage across wrapped detail lines and removes its whole entry", () => {
+ const note = "- 2026-10-27 · Home address:\n 14 Oak\n Street\n";
+ expect(withoutMentions(note + kept, passageMatcher("Oak Street")!))
+ .toEqual({ text: kept, removed: ["Home address:"] });
+});
+
+it("keeps continuation details when only the source chat names the passage", () => {
+ expect(withoutMentions(kept, passageMatcher("Oak Street")!)).toEqual({ text: kept, removed: [] });
+});
diff --git a/server/memory-forget.ts b/server/memory-forget.ts
index 99a31ed42a..f6540d14d6 100644
--- a/server/memory-forget.ts
+++ b/server/memory-forget.ts
@@ -17,7 +17,7 @@ export function withoutMentions(text: string, mentions: (text: string) => boolea
const removed: string[] = [];
for (const entry of parseMemoryEntries(text)) {
for (let line = entry.line; line < entry.end; line += 1) entryLines.add(line);
- if (!mentions(entry.body)) continue;
+ if (!mentions([entry.body, ...lines.slice(entry.line + 1, entry.end)].join("\n"))) continue;
for (let line = entry.line; line < entry.end; line += 1) drop.add(line);
removed.push(entry.body);
}