Skip to content

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

fix: keep memory continuation lines with their entry

Afloat487bb5841788
diff --git a/server/memory-entries.ts b/server/memory-entries.ts
index 63a201837b..94f295ad9f 100644
--- a/server/memory-entries.ts
+++ b/server/memory-entries.ts
@@ -68,9 +68,11 @@ export function isExpired(entry: Pick<MemoryEntryLine, "until" | "struck">, toda
}
export function withoutExpired(text: string, today: string): { text: string; hidden: number } {
- const expired = new Set(parseMemoryEntries(text).filter((e) => isExpired(e, today)).map((e) => e.line));
- if (!expired.size) return { text, hidden: 0 };
- return { text: text.split("\n").filter((_, index) => !expired.has(index)).join("\n"), hidden: expired.size };
+ const expired = parseMemoryEntries(text).filter((e) => isExpired(e, today));
+ if (!expired.length) return { text, hidden: 0 };
+ const dropped = new Set<number>();
+ for (const entry of expired) for (let line = entry.line; line < entry.end; line++) dropped.add(line);
+ return { text: text.split("\n").filter((_, index) => !dropped.has(index)).join("\n"), hidden: expired.length };
}
/** Deliberately narrow: `-10` and `10`, `C++` and `C`, `API_KEY` and `api_key` stay different facts. */
diff --git a/server/memory-entry-continuations.test.ts b/server/memory-entry-continuations.test.ts
new file mode 100644
index 0000000000..0d81f25dcf
--- /dev/null
+++ b/server/memory-entry-continuations.test.ts
@@ -0,0 +1,50 @@
+import { describe, expect, it } from "vitest";
+
+import { parseMemoryEntries, withoutExpired } from "./memory-entries.ts";
+import { applyMoves } from "./memory-organize.ts";
+
+const expired = [
+ "- 2026-10-01 · Temporary deployment · until 2026-10-31",
+ " ```sh",
+ " deploy --temporary",
+ "",
+ " ```",
+ " Remove this deployment after the deadline.",
+];
+const live = "- 2026-11-01 · Current deployment";
+
+describe("whole memory entry boundaries", () => {
+ it("removes an expired entry and all of its continuation lines", () => {
+ const text = ["# Memory", ...expired, live, " Keep this detail.", ""].join("\n");
+ expect(withoutExpired(text, "2026-11-01")).toEqual({
+ text: ["# Memory", live, " Keep this detail.", ""].join("\n"),
+ hidden: 1,
+ });
+ });
+
+ it("counts expired entries rather than removed physical lines", () => {
+ const second = ["- 2026-10-02 · Temporary endpoint · until 2026-10-30", " endpoint.example"];
+ expect(withoutExpired([...expired, ...second, live].join("\n"), "2026-11-01"))
+ .toEqual({ text: live, hidden: 2 });
+ });
+
+ it("keeps an entry through its final day", () => {
+ const text = [...expired, live].join("\n");
+ expect(withoutExpired(text, "2026-10-31")).toEqual({ text, hidden: 0 });
+ });
+
+ it("moves the full source entry into its topic without orphaning details", () => {
+ const entry = ["- 2026-10-01 · Deploy project Cedar:", ...expired.slice(1)];
+ const text = ["# Memory", ...entry, live, " Keep this detail.", ""].join("\n");
+ const moved = applyMoves(text, [{ entry: parseMemoryEntries(text)[0]!, topic: "cedar.md", aliases: ["deploy"] }]);
+ expect(moved.text).toBe(["# Memory", live, " Keep this detail.", ""].join("\n"));
+ expect(moved.byTopic.get("cedar.md"))
+ .toEqual({ lines: [entry.join("\n")], aliases: ["deploy"] });
+ });
+
+ it("keeps handwritten text outside the recognized entry", () => {
+ const text = [expired[0], "## Manual notes", "keep this text", live].join("\n");
+ expect(withoutExpired(text, "2026-11-01").text)
+ .toBe(["## Manual notes", "keep this text", live].join("\n"));
+ });
+});
diff --git a/server/memory-organize.ts b/server/memory-organize.ts
index f766a56cbb..527a18a798 100644
--- a/server/memory-organize.ts
+++ b/server/memory-organize.ts
@@ -76,13 +76,15 @@ export function parseMoves(text: string, candidates: readonly MemoryEntryLine[])
}
export function applyMoves(text: string, moves: readonly TopicMove[]): { text: string; byTopic: Map<string, { lines: string[]; aliases: string[] }> } {
- const drop = new Set(moves.map((move) => move.entry.line));
+ const lines = text.split("\n");
+ const drop = new Set<number>();
const byTopic = new Map<string, { lines: string[]; aliases: string[] }>();
for (const move of moves) {
+ for (let line = move.entry.line; line < move.entry.end; line++) drop.add(line);
const group = byTopic.get(move.topic) ?? { lines: [], aliases: [] };
- group.lines.push(move.entry.raw);
+ group.lines.push(lines.slice(move.entry.line, move.entry.end).join("\n"));
for (const alias of move.aliases) if (!group.aliases.includes(alias)) group.aliases.push(alias);
byTopic.set(move.topic, group);
}
- return { text: text.split("\n").filter((_, index) => !drop.has(index)).join("\n"), byTopic };
+ return { text: lines.filter((_, index) => !drop.has(index)).join("\n"), byTopic };
}