Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Evals: score what a nightly dream keeps
Divya Jyotie8beb25fd28f
diff --git a/evals/README.md b/evals/README.mdindex 1bbe1eb983..7dde2997fa 100644--- a/evals/README.md+++ b/evals/README.md@@ -69,6 +69,12 @@ On Claude with tool search on, a turn sends a few agents tools whole and the res`--context` runs no model and prints the bytes a Claude turn sends of the agents tools up front, whole against deferred.+## Dream — what a nightly dream keeps++`evals/dream` grades a dream's answer as `runDream` keeps it: `parseDream`, then the fact checks, before anything is written. Each case in `cases.json` holds a few chats, the notebook as it stands, the lines a dream should save (any of a few words, ignoring case) and words no saved line may contain. A case passes when the answer is JSON, every expected line is saved and nothing forbidden is. Saved lines no expectation covers are listed as `unexpected`, for a person or a judge to read. Only the scoring runs offline, in the evals suite; nothing calls a model yet.++ npx vitest run --config evals/vitest.config.ts evals/dream+## Tier 3 — opt-in live-model smokeLive-model runs never execute by default: `pnpm eval --live` prints one skip line and exits 0 unless the gate is open.diff --git a/evals/dream/cases.json b/evals/dream/cases.jsonnew file mode 100644index 0000000000..2bf0866b7e--- /dev/null+++ b/evals/dream/cases.json@@ -0,0 +1,89 @@+[+ {+ "id": "short-replies-across-chats",+ "why": "A reply preference the person shows in three chats is learned once.",+ "today": "2026-11-14",+ "notebook": "",+ "conversations": [+ { "title": "Email to landlord", "lines": [+ { "by": "person", "text": "Can you make this email shorter? It's way too long." },+ { "by": "bot", "text": "Here is a shorter version in four sentences." }+ ] },+ { "title": "Team update", "lines": [+ { "by": "person", "text": "Too wordy again, keep it under 100 words please." },+ { "by": "bot", "text": "Done, it is 82 words now." }+ ] },+ { "title": "Thank-you note", "lines": [+ { "by": "person", "text": "Thanks, short like that is perfect." }+ ] }+ ],+ "expect": {+ "learned": [{ "anyOf": ["short", "brief", "concise", "100 words"] }],+ "outdated": [],+ "never": []+ }+ },+ {+ "id": "one-chat-is-not-a-pattern",+ "why": "A fact said in one chat only is left to capture: a dream keeps nothing a single chat could have told it.",+ "today": "2026-11-14",+ "notebook": "",+ "conversations": [+ { "title": "Dinner", "lines": [+ { "by": "person", "text": "I'm allergic to peanuts, keep that in mind for the recipe." },+ { "by": "bot", "text": "Noted, here is a peanut-free stir fry." }+ ] },+ { "title": "Cat names", "lines": [+ { "by": "person", "text": "What's a good name for a grey cat?" },+ { "by": "bot", "text": "Smokey, Ash or Pebble." }+ ] }+ ],+ "expect": {+ "learned": [],+ "outdated": [],+ "never": ["peanut"]+ }+ },+ {+ "id": "a-task-is-not-a-fact",+ "why": "Work the person asks for twice says what they work on, never who they are.",+ "today": "2026-11-14",+ "notebook": "",+ "conversations": [+ { "title": "Launch plan", "lines": [+ { "by": "person", "text": "Write a launch plan for a vegan bakery opening in March." },+ { "by": "bot", "text": "Here is a three-phase launch plan." }+ ] },+ { "title": "Bio", "lines": [+ { "by": "person", "text": "Now draft the vegan bakery's Instagram bio." },+ { "by": "bot", "text": "Fresh, plant-based, baked daily." }+ ] }+ ],+ "expect": {+ "learned": [],+ "outdated": [],+ "never": ["person is vegan", "is a vegan", "follows a vegan", "eats vegan"]+ }+ },+ {+ "id": "outdated-note-after-a-move",+ "why": "A note a chat says has changed is updated, quoting the chat that says so.",+ "today": "2026-11-14",+ "notebook": "- 2026-09-01 · The person lives in Pune\n",+ "conversations": [+ { "title": "Weather", "lines": [+ { "by": "person", "text": "I moved to Bangalore last month, so use Bangalore for the weather from now on." },+ { "by": "bot", "text": "Got it, Bangalore it is." }+ ] },+ { "title": "Weekend", "lines": [+ { "by": "person", "text": "What's on in Bangalore this weekend?" },+ { "by": "bot", "text": "A food festival in Indiranagar and a jazz night." }+ ] }+ ],+ "expect": {+ "learned": [],+ "outdated": [{ "line": 0, "anyOf": ["bangalore"] }],+ "never": ["lives in pune"]+ }+ }+]diff --git a/evals/dream/score.test.ts b/evals/dream/score.test.tsnew file mode 100644index 0000000000..07a37b3f5e--- /dev/null+++ b/evals/dream/score.test.ts@@ -0,0 +1,83 @@+import { readFileSync } from "node:fs";+import { describe, expect, it } from "vitest";+import { dreamPrompt } from "../../server/memory-dream.ts";+import { dreamConversationsOf, notebookOf, scoreDream, summarize, type DreamCase } from "./score.ts";++const cases = JSON.parse(readFileSync(new URL("./cases.json", import.meta.url), "utf8")) as DreamCase[];+const byId = (id: string) => cases.find((item) => item.id === id)!;+const answer = (body: object) => "```json\n" + JSON.stringify({ learned: [], outdated: [], ideas: [], ...body }) + "\n```";++describe("dream scoring", () => {+ it("passes a pattern cited by two chats with the person's own words", () => {+ const score = scoreDream(byId("short-replies-across-chats"), answer({+ learned: [{ text: "The person wants replies short, under 100 words", from: [1, 2], evidence: ["It's way too long", "keep it under 100 words please"], confidence: 0.9 }],+ }));+ expect(score).toMatchObject({ json: true, found: 1, expected: 1, dropped: 0, violations: [], unexpected: [], pass: true });+ });++ it("drops a quote taken from inside a question, though the person asked for exactly that", () => {+ const score = scoreDream(byId("short-replies-across-chats"), answer({+ learned: [{ text: "The person wants replies short", from: [1, 2], evidence: ["make this email shorter", "keep it under 100 words please"], confidence: 0.9 }],+ }));+ expect(score).toMatchObject({ dropped: 1, pass: false });+ });++ it("drops an entry whose quote the person never said, the way runDream does", () => {+ const score = scoreDream(byId("short-replies-across-chats"), answer({+ learned: [{ text: "The person wants short replies", from: [1, 2], evidence: ["I always want short replies", "keep it under 100 words please"], confidence: 0.9 }],+ }));+ expect(score).toMatchObject({ learned: [], dropped: 1, found: 0, pass: false });+ });++ it("drops a number the quotes do not hold", () => {+ const score = scoreDream(byId("short-replies-across-chats"), answer({+ learned: [{ text: "The person wants replies under 50 words", from: [1, 2], evidence: ["It's way too long", "keep it under 100 words please"], confidence: 0.9 }],+ }));+ expect(score).toMatchObject({ dropped: 1, pass: false });+ });++ it("fails a case when a saved line says what it must never say", () => {+ const score = scoreDream(byId("a-task-is-not-a-fact"), answer({+ learned: [{ text: "The person is vegan", from: [1, 2], evidence: ["vegan bakery opening in March", "vegan bakery's Instagram bio"], confidence: 0.8 }],+ }));+ expect(score.violations).toEqual(["The person is vegan"]);+ expect(score.pass).toBe(false);+ });++ it("passes an empty answer when nothing shows across chats", () => {+ expect(scoreDream(byId("one-chat-is-not-a-pattern"), answer({}))).toMatchObject({ json: true, learned: [], pass: true });+ });++ it("counts an answer that is not JSON as a failure, even where nothing was expected", () => {+ expect(scoreDream(byId("one-chat-is-not-a-pattern"), "Nothing stood out across these chats.")).toMatchObject({ json: false, pass: false });+ });++ it("finds an outdated note on the line it names", () => {+ const testCase = byId("outdated-note-after-a-move");+ const right = scoreDream(testCase, answer({ outdated: [{ line: 0, now: "The person lives in Bangalore", from: [1], evidence: ["I moved to Bangalore last month"] }] }));+ expect(right).toMatchObject({ found: 1, pass: true });+ expect(scoreDream(testCase, answer({})).pass).toBe(false);+ });++ it("adds up a run", () => {+ const pass = scoreDream(byId("one-chat-is-not-a-pattern"), answer({}));+ const fail = scoreDream(byId("one-chat-is-not-a-pattern"), "no");+ expect(summarize([{ score: pass, costUsd: 0.01, ms: 900 }, { score: fail, costUsd: 0.02, ms: 1100 }]))+ .toMatchObject({ cases: 2, passed: 1, invalidJson: 1, costUsd: 0.03, ms: 2000 });+ });+});++describe("dream cases", () => {+ it("each case is well formed and builds the real dream prompt", () => {+ expect(new Set(cases.map((item) => item.id)).size).toBe(cases.length);+ for (const item of cases) {+ expect(item.why.length, item.id).toBeGreaterThan(0);+ expect(item.conversations.length, item.id).toBeGreaterThanOrEqual(2);+ for (const conversation of item.conversations) expect(conversation.lines.some((line) => line.by === "person"), item.id).toBe(true);+ const notebook = notebookOf(item);+ for (const outdated of item.expect.outdated) expect(outdated.line, item.id).toBeLessThan(notebook.length);+ const prompt = dreamPrompt({ botName: "Scout", today: item.today, conversations: dreamConversationsOf(item), notebook });+ expect(prompt, item.id).toContain(`Conversation ${item.conversations.length}`);+ }+ });+});diff --git a/evals/dream/score.ts b/evals/dream/score.tsnew file mode 100644index 0000000000..1bd60a2452--- /dev/null+++ b/evals/dream/score.ts@@ -0,0 +1,85 @@+import { jsonPayload } from "../../server/memory-capture.ts";+import { parseDream, type DreamConversation, type DreamLine } from "../../server/memory-dream.ts";+import { checkDreamFacts } from "../../server/memory-fact-checks.ts";+import { contradictionCandidates } from "../../server/memory-tidy.ts";++/** One saved line matches when it contains any of these, ignoring case. */+export interface Expected {+ anyOf: string[];+}++export interface DreamCase {+ id: string;+ /** The dream behaviour this case pins, in plain words. */+ why: string;+ today: string;+ conversations: Array<{ title?: string; lines: DreamLine[] }>;+ /** MEMORY.md as the bot has it before the dream. */+ notebook: string;+ expect: {+ learned: Expected[];+ outdated: Array<Expected & { line: number }>;+ /** No saved line may contain any of these, ignoring case. */+ never: string[];+ };+}++export interface DreamScore {+ json: boolean;+ learned: string[];+ outdated: Array<{ line: number; now: string }>;+ /** Parsed entries the fact checks refused. */+ dropped: number;+ found: number;+ expected: number;+ /** Saved lines that no expectation covers: not wrong in themselves, for a judge to read. */+ unexpected: string[];+ violations: string[];+ pass: boolean;+}++export function dreamConversationsOf(testCase: Pick<DreamCase, "id" | "conversations">): DreamConversation[] {+ return testCase.conversations.map((conversation, i) => ({ threadId: `${testCase.id}-${i + 1}`, ...conversation }));+}++export function notebookOf(testCase: Pick<DreamCase, "notebook" | "today">) {+ return contradictionCandidates(testCase.notebook, testCase.today);+}++const covers = (expected: Expected, text: string) => expected.anyOf.some((word) => text.toLowerCase().includes(word.toLowerCase()));++/** Grades one model answer the way runDream would keep it, before anything is written. */+export function scoreDream(testCase: DreamCase, answer: string): DreamScore {+ const conversations = dreamConversationsOf(testCase);+ const notebook = notebookOf(testCase);+ const parsed = parseDream(answer, conversations.length, notebook.length);+ const learned = parsed.learned.filter((item) => checkDreamFacts(item.text, item.from, item.evidence, conversations)).map((item) => item.text);+ const outdated = parsed.outdated.filter((item) => checkDreamFacts(item.now, item.from, item.evidence, conversations)).map(({ line, now }) => ({ line, now }));+ const dropped = parsed.learned.length + parsed.outdated.length - learned.length - outdated.length;+ const foundLearned = testCase.expect.learned.filter((expected) => learned.some((text) => covers(expected, text))).length;+ const foundOutdated = testCase.expect.outdated.filter((expected) => outdated.some((item) => item.line === expected.line && covers(expected, item.now))).length;+ const saved = [...learned, ...outdated.map((item) => item.now)];+ const violations = saved.filter((text) => testCase.expect.never.some((word) => text.toLowerCase().includes(word.toLowerCase())));+ const unexpected = [+ ...learned.filter((text) => !testCase.expect.learned.some((expected) => covers(expected, text))),+ ...outdated.filter((item) => !testCase.expect.outdated.some((expected) => expected.line === item.line && covers(expected, item.now))).map((item) => item.now),+ ];+ const json = jsonPayload(answer) !== null;+ const found = foundLearned + foundOutdated;+ const expected = testCase.expect.learned.length + testCase.expect.outdated.length;+ return { json, learned, outdated, dropped, found, expected, unexpected, violations, pass: json && violations.length === 0 && found === expected };+}++export function summarize(rows: ReadonlyArray<{ score: DreamScore; costUsd?: number; ms?: number }>) {+ return {+ cases: rows.length,+ passed: rows.filter((row) => row.score.pass).length,+ found: rows.reduce((sum, row) => sum + row.score.found, 0),+ expected: rows.reduce((sum, row) => sum + row.score.expected, 0),+ violations: rows.reduce((sum, row) => sum + row.score.violations.length, 0),+ dropped: rows.reduce((sum, row) => sum + row.score.dropped, 0),+ invalidJson: rows.filter((row) => !row.score.json).length,+ costUsd: Number(rows.reduce((sum, row) => sum + (row.costUsd ?? 0), 0).toFixed(4)),+ ms: rows.reduce((sum, row) => sum + (row.ms ?? 0), 0),+ };+}