Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(prompt): a new thread on a bot reads the bot's cached prompt
milind-soni684b68417d3b
diff --git a/server/prompt-cache-prefix.e2e.test.ts b/server/prompt-cache-prefix.e2e.test.tsnew file mode 100644index 0000000000..8cf225d29e--- /dev/null+++ b/server/prompt-cache-prefix.e2e.test.ts@@ -0,0 +1,38 @@+// Providers cache a prompt from its start: tools, then the system prompt. Anything in there that differs between two threads+// of one bot makes each new thread write the rest again at the cache-write rate.+import { readFileSync } from "node:fs";+import { join } from "node:path";+import { expect, it } from "vitest";+import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";++it("launches two threads of one bot with the same system prompt, each with its own folder in its first message", async () => {+ const fixture = await launchVerificationServer();+ const control = (args: string[]) => runControlOmb([...args, "--url", fixture.info.url]) as Promise<any>;+ const api = async (method: string, path: string, body: unknown) => {+ const response = await fetch(`${fixture.info.url}${path}`, { method, headers: { "content-type": "application/json" }, body: JSON.stringify(body) });+ expect(response.ok).toBe(true);+ return await response.json() as any;+ };+ // systemPromptFile is the file the CLI is launched with; the fixture's systemPrompt adds what the first message carries.+ const turn = async (botId: string, threadId: string) => {+ await control(["send", "--bot", botId, "--task", threadId, "--text", "hi"]);+ expect((await control(["wait", "--bot", botId, "--task", threadId, "--timeout", "30"])).status).toBe("settled");+ const dump = JSON.parse(readFileSync(fixture.fixtureDumpPath, "utf8"));+ return { launched: dump.systemPromptFile as string, message: JSON.stringify(dump.prompt) };+ };+ // A path as the first message holds it: JSON in the prompt, inside the JSON of the message.+ const folder = (botId: string, threadId: string) => JSON.stringify(JSON.stringify(join(fixture.info.dataDir, "task-workspaces", botId, threadId))).slice(1, -1);+ try {+ const { bot } = await api("POST", "/api/bots", { name: "Garden helper" });+ const { task: second } = await api("POST", `/api/bots/${bot.id}/tasks`, { title: "Second", select: false });+ const first = await turn(bot.id, bot.threadId);+ const other = await turn(bot.id, second.threadId);+ expect(first.launched).toContain("You are Garden helper");+ expect(other.launched).toBe(first.launched);+ expect(first.launched).not.toContain(bot.threadId);+ expect(first.message).toContain(folder(bot.id, bot.threadId));+ expect(other.message).toContain(folder(bot.id, second.threadId));+ } finally {+ await fixture.close();+ }+}, 120_000);diff --git a/server/system-prompt.test.ts b/server/system-prompt.test.tsindex 5e4a48196f..dd48a5161e 100644--- a/server/system-prompt.test.ts+++ b/server/system-prompt.test.ts@@ -31,6 +31,15 @@ import {import { loginPlace } from "../shared/logins.ts";import { REPLY_HABITS_PROMPT } from "./reply-habits.ts";+describe("the stable half", () => {+ it("leaves out a conversation's folder, so a new thread can read the bot's cached prompt", () => {+ const built = buildSystemPrompt("You are Kiwi.", "", [{ id: "files", label: "File locations", text: "folder: /tasks/thread-1" }]);+ expect(built.stable).not.toContain("thread-1");+ expect(built.volatile).toContain("thread-1");+ expect(built.text).toContain("thread-1");+ });+});+describe("resolveComputerPromptKind", () => {// Rows the mounts already refuse are pinned here because no dispatchable engine in the test fleet lacks the capability.it.each([diff --git a/server/system-prompt.ts b/server/system-prompt.tsindex 050b09b5e3..bc99ae4c1a 100644--- a/server/system-prompt.ts+++ b/server/system-prompt.ts@@ -27,7 +27,7 @@ export function userProfileSystemPrompt(profile?: { aboutMe?: string; person?: s// Two per-turn sections stay stable on purpose: "setup" sits right after the standing instructions it overrides,// and "webhook" keeps its untrusted-data rule in the system prompt, out of reach of the payload it guards.const VOLATILE_SECTIONS = new Set(["memory", "mentions", "outstanding", "teammate-questions", "long-waits", "recent", "availability", "active-routines",- "plan", "assignment", "routine-execution", "skill-instructions", "playbooks", "device-place"]);+ "plan", "assignment", "routine-execution", "skill-instructions", "playbooks", "device-place", "files"]);/** Its id is what puts it in the volatile half. */export function teamAvailabilityPart(team: readonly RosterMember[]): PromptPart {