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 quotes paired with their chats and paths untouched by dates
Sebastian B229b50c73384
diff --git a/server/memory-dream.test.ts b/server/memory-dream.test.tsindex 43d650c7e8..97f8970c62 100644--- a/server/memory-dream.test.ts+++ b/server/memory-dream.test.ts@@ -212,6 +212,11 @@ describe("the dream prompt and its answer", () => {expect(answer.ideas).toHaveLength(MAX_IDEAS);});+ it("keeps cited conversations in the order their quotes were given", () => {+ const answer = parseDream(JSON.stringify({ learned: [{ text: "The person wants short replies", from: [2, 1], evidence: ["two", "one"], confidence: 0.9 }] }), 2, 0);+ expect(answer.learned[0]).toMatchObject({ from: [2, 1], evidence: ["two", "one"] });+ });+it("reads nothing out of an answer that is not JSON", () => {expect(parseDream("I could not find anything.", 3, 0)).toEqual({ learned: [], outdated: [], ideas: [] });});diff --git a/server/memory-dream.ts b/server/memory-dream.tsindex 21c1382c59..d3167c5a7e 100644--- a/server/memory-dream.ts+++ b/server/memory-dream.ts@@ -142,7 +142,7 @@ export function dreamPrompt(input: {`ideas: at most ${MAX_IDEAS} things ${input.botName} could set up so the Person stops asking by hand, such as an automation for a request they repeat on a schedule or a saved skill for steps they keep walking through. One sentence each, with "from" (at least two conversations). Only for a clear repeat.`,"","Answer with one JSON object and nothing else. Empty lists are the normal answer when the conversations show no lasting pattern:",- '{"learned": [{"text": "...", "from": [1, 3], "aboutUser": false, "topic": "optional", "topicAliases": ["..."], "confidence": 0..1}], "outdated": [{"line": 0, "now": "...", "from": [2]}], "ideas": [{"text": "...", "from": [1, 4]}]}',+ '{"learned": [{"text": "...", "from": [1, 3], "evidence": ["quote from 1", "quote from 3"], "aboutUser": false, "topic": "optional", "topicAliases": ["..."], "confidence": 0..1}], "outdated": [{"line": 0, "now": "...", "from": [2], "evidence": ["quote from 2"]}], "ideas": [{"text": "...", "from": [1, 4]}]}',].join("\n");}@@ -177,11 +177,11 @@ function sentence(raw: unknown): string {return typeof raw === "string" ? raw.replace(/\s+/g, " ").replace(/^\s*(?:[-*•]|\d+[.)])\s+/, "").replace(/~~/g, "").trim().slice(0, TEXT_MAX) : "";}-/** Distinct 1-based conversation numbers that were really given, or null when fewer than `min` remain. */+/** Distinct 1-based conversation numbers that were really given, in the given order, or null when fewer than `min` remain. */function cited(raw: unknown, conversations: number, min: number): number[] | null {if (!Array.isArray(raw)) return null;const numbers = [...new Set(raw.map((n) => (typeof n === "string" && /^\d+$/.test(n.trim()) ? Number(n) : n))- .filter((n): n is number => Number.isInteger(n) && n >= 1 && n <= conversations))].sort((a, b) => a - b);+ .filter((n): n is number => Number.isInteger(n) && n >= 1 && n <= conversations))];return numbers.length >= min ? numbers : null;}diff --git a/server/memory-fact-checks.test.ts b/server/memory-fact-checks.test.tsindex 250802ae49..689598a1df 100644--- a/server/memory-fact-checks.test.ts+++ b/server/memory-fact-checks.test.ts@@ -37,4 +37,10 @@ describe("dream fact checks", () => {expect(checkDreamFacts("Anna today", [1], ["Anna today"], [{ threadId: "x", lines: [{ by: "person", text: "Anna today" }] }])).toBeNull();expect(checkDreamFacts("Anna today", [1, 2], ["Anna today", "Anna today"], [0, 1].map((i) => ({ threadId: String(i), lines: [{ by: "person" as const, text: "Anna today", at: Date.parse(`2026-10-2${i}T12:00:00Z`) }] })))).toBeNull();});+ it("leaves relative-date words inside paths and URLs alone", () => {+ const text = "Anna keeps notes in /notes/today.md and https://example.test/today";+ expect(checkDreamFacts(text, [1], [text], [{ threadId: "p", lines: [{ by: "person", text }] }])).toBe(text);+ const dated = "Anna wrote /notes/today.md today";+ expect(checkDreamFacts(dated, [1], [dated], [{ threadId: "p", lines: [{ by: "person", text: dated, at: Date.parse("2026-03-01T12:00:00Z") }] }])).toBe("Anna wrote /notes/today.md 2026-03-01");+ });});diff --git a/server/memory-fact-checks.ts b/server/memory-fact-checks.tsindex ddbb09739a..58955fd023 100644--- a/server/memory-fact-checks.ts+++ b/server/memory-fact-checks.ts@@ -12,11 +12,14 @@ const NAME = /(?<!\p{L})\p{Lu}[\p{L}\p{M}]+(?!\p{L})/gu;const SENTENCE_WORDS = new Set("The A An I User Owner Person Client Prefers Keep New Old Uses Use Run Note Remember Works My Her His Their They He She It Shorter Too Also".toLowerCase().split(" "));const matches = (text: string, pattern: RegExp) => [...text.matchAll(pattern)].map((m) => m[0].toLowerCase());const subset = (a: readonly string[], b: readonly string[]) => a.every((value) => b.includes(value));+const relativeWords = (text: string) => matches(text.replace(LOCATION, " "), RELATIVE);+const RELATIVE_OUTSIDE_LOCATIONS = new RegExp(`${LOCATION.source}|${RELATIVE.source}`, "giu");function absolute(text: string, at?: number): string | null {- if (!matches(text, RELATIVE).length) return text;+ if (!relativeWords(text).length) return text;if (at === undefined || !Number.isFinite(at)) return null;- return text.replace(RELATIVE, (word) => {+ return text.replace(RELATIVE_OUTSIDE_LOCATIONS, (match, word?: string) => {+ if (!word) return match;const date = new Date(at);const lower = word.toLowerCase();const shift = ["yesterday", "wczoraj"].includes(lower) ? -1 : ["tomorrow", "jutro"].includes(lower) ? 1 : 0;@@ -36,8 +39,8 @@ export function checkDreamFacts(text: string, from: readonly number[], evidence:if (!lines?.length) return null;sources.push(...lines.map((line) => ({ text: quote, at: line.at })));}- const relative = matches(text, RELATIVE);- const anchors = relative.length ? sources.filter((source) => subset(relative, matches(source.text, RELATIVE))) : sources;+ const relative = relativeWords(text);+ const anchors = relative.length ? sources.filter((source) => subset(relative, relativeWords(source.text))) : sources;const prepared = anchors.map((source) => absolute(text, source.at));if (!prepared.length || prepared.some((value) => value === null || value !== prepared[0])) return null;const entry = prepared[0]!;