Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(memory): keep newly appended CRLF entries out of eviction
Afloatd734dfb857b5
diff --git a/server/workspace.test.ts b/server/workspace.test.tsindex ddff6c692c..e11dea2fd4 100644--- a/server/workspace.test.ts+++ b/server/workspace.test.ts@@ -386,6 +386,21 @@ describe("workspace", () => {expect(archive()).toBe("");});+ it.each(["\n", "\r\n"])("keeps a newly appended %j code block when the remaining space is too small", (newline) => {+ const now = new Date(2026, 9, 3, 12);+ const hand = Array.from({ length: MEMORY_MAX_LINES - 1 }, (_, i) => `- project note ${i}`).join("\n") + "\n";+ writeMemoryFile(BOT, hand);+ const text = ["Deploy command:", "```sh", "pnpm deploy --prod", "```"].join(newline);+ expect(updateMemory(BOT, { action: "append", text }, { now }))+ .toMatchObject({ ok: true, truncated: true, moved: [] });+ const saved = readMemoryFile(BOT).text;+ expect(saved.startsWith(hand)).toBe(true);+ expect(saved).toContain("- 2026-10-03 · Deploy command:");+ expect(saved).toContain(" pnpm deploy --prod");+ expect(memoryLineCount(saved)).toBe(MEMORY_MAX_LINES + 3);+ expect(archive()).toBe("");+ });+// Permissions do not stop root or Windows from reading the file.it.skipIf(process.platform === "win32" || process.getuid?.() === 0)("fails the write, changing nothing, when the archive exists but cannot be read", () => {const full = Array.from({ length: MEMORY_MAX_LINES }, (_, i) => `- 2026-09-01 · old ${i}\n`).join("");diff --git a/server/workspace.ts b/server/workspace.tsindex 3df4ebcae3..347642a480 100644--- a/server/workspace.ts+++ b/server/workspace.ts@@ -405,7 +405,7 @@ export function updateMemory(botId: string, update: MemoryUpdate, opts: MemoryUpfunction makeRoom(text: string, today: string, keep: string | undefined): { text: string; moved: string[] } {if (!memoryOverBudget(text)) return { text, moved: [] };const all = text.split("\n");- const kept = keep?.split("\n")[0];+ const kept = keep?.split("\n")[0]?.replace(/\r$/, "");const group = (e: MemoryEntryLine) => (e.struck ? 0 : isExpired(e, today) ? 1 : 2);const order = parseMemoryEntries(text).filter((e) => e.raw !== kept && (group(e) < 2 || !alwaysCore(e.body)))