Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(memory): topic notes say where they are, on every turn
milind-sonib7aa7c8864d9
diff --git a/server/memory-entries.test.ts b/server/memory-entries.test.tsindex d57b3e0e01..0865ffd38f 100644--- a/server/memory-entries.test.ts+++ b/server/memory-entries.test.ts@@ -140,7 +140,7 @@ describe("memory with until dates and topics, on disk", () => {writeMemoryTopic(BOT, "dining.md", "---\ntitle: Dining\naliases: [food, lunch, restaurants]\n---\n- Loves pasta\n");writeFileSync(join(WORKSPACES_DIR, BOT, "memory", "notes.md"), "plain topic\n");const prompt = memorySystemPrompt(BOT, { managedWrites: true, fileTools: true });- expect(prompt).toContain("Your topic notes (not loaded; when a request touches one of these topics, read that file with your file tools before you answer):");+ expect(prompt).toContain(`Your topic notes (not loaded; paths are relative to ${JSON.stringify(join(WORKSPACES_DIR, BOT))}, not your working folder; when a request touches one of these topics, read that file with your file tools before you answer):`);expect(prompt).toContain("- memory/dining.md — Dining (also: food, lunch, restaurants)");expect(prompt).toContain("- memory/notes.md");expect(memorySystemPrompt(BOT, { fileTools: false })).toContain("look it up with session_search before you answer");diff --git a/server/workspace.test.ts b/server/workspace.test.tsindex cb1c7ca2ae..b2985a9bb1 100644--- a/server/workspace.test.ts+++ b/server/workspace.test.ts@@ -450,6 +450,21 @@ describe("workspace", () => {expect(loadMemory(BOT)?.truncated).toBe(false);});+ // A teammate's hand-off on a Cloud runs in a task folder, with its writes refused: this was the one prompt with no memory path.+ it("tells a turn whose notes would be refused where its topic notes are, with or without a MEMORY.md", () => {+ writeMemoryTopic(BOT, "regulars.md", "---\ntitle: Regulars\n---\n- Code MOSS-42\n");+ const folder = JSON.stringify(workspaceDir(BOT));+ const withoutMemory = memorySystemPrompt(BOT, { managedWrites: true, fileTools: true, writesRefused: true });+ expect(withoutMemory).toContain("- memory/regulars.md");+ expect(withoutMemory).toContain(`paths are relative to ${folder}, not your working folder`);+ writeMemoryFile(BOT, "- The owner likes figs.");+ const withMemory = memorySystemPrompt(BOT, { managedWrites: true, fileTools: true, writesRefused: true });+ expect(withMemory).toContain("- memory/regulars.md");+ expect(withMemory).toContain(`paths are relative to ${folder}, not your working folder`);+ // With no file tools it can't open a path, so it is told how to look instead.+ expect(memorySystemPrompt(BOT, { managedWrites: true, fileTools: false, writesRefused: true })).toContain("look it up with session_search");+ });+it("tells a turn whose notes would be refused where facts go, and still shows it the memory", () => {const empty = memorySystemPrompt(BOT, { managedWrites: true, fileTools: true, writesRefused: true });expect(empty).toContain("Notes cannot be saved from this conversation");diff --git a/server/workspace.ts b/server/workspace.tsindex 7dae64d20b..367f200978 100644--- a/server/workspace.ts+++ b/server/workspace.ts@@ -573,7 +573,7 @@ export function memorySystemPrompt(botId: string, opts: { managedWrites?: booleaconst topicDir = join(workspaceDir(botId), "memory");if (opts.writesRefused || (opts.fileTools === false && !opts.managedWrites)) {const lead = opts.writesRefused ? NOTES_IN_RESULT : " Your saved memory is supplied as context; this turn has no memory editing tools.";- if (!memory) return opts.writesRefused ? lead : "";+ if (!memory) return opts.writesRefused ? `${lead}${topicIndexBlock(botId, opts.fileTools !== false)}` : "";return `${lead}\n\nYour memory (MEMORY.md):\n${memory.text}${memory.truncated ? " [Only the initial memory excerpt is visible.]" : ""}${topicIndexBlock(botId, opts.fileTools !== false)}`;}const writeGuidance = opts.managedWrites@@ -596,8 +596,9 @@ export function memorySystemPrompt(botId: string, opts: { managedWrites?: booleafunction topicIndexBlock(botId: string, fileTools: boolean): string {const index = memoryTopicIndex(botId);if (!index) return "";+ // Every turn reaches this, including one whose prompt names no other memory path, and a turn runs in a task folder.const how = fileTools- ? "when a request touches one of these topics, read that file with your file tools before you answer"+ ? `paths are relative to ${JSON.stringify(workspaceDir(botId))}, not your working folder; when a request touches one of these topics, read that file with your file tools before you answer`: "when a request touches one of these topics, look it up with session_search before you answer";return `\n\nYour topic notes (not loaded; ${how}):\n${index}`;}