Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(devs-reports): a @devs only inside a quote no longer sends a report
AdityaUmale613cdba33dc2
diff --git a/server/devs-report.test.ts b/server/devs-report.test.tsindex 859eacde67..c0713e9e6a 100644--- a/server/devs-report.test.ts+++ b/server/devs-report.test.ts@@ -19,6 +19,13 @@ function input(overrides: Partial<DevsReportInput> = {}): DevsReportInput {}describe("a @devs report's redaction", () => {+ it("drops a quote's encoded copy, which it cannot read, from every field, and keeps the readable quote", () => {+ const marker = `<!--omb-citation-v1:${Buffer.from(JSON.stringify({ comment: GITHUB })).toString("base64url")}-->`;+ expect(redactReportText(`${marker}\n> Quoted message:\n> hi\n\nthe bot said ${marker} here`)).toBe("> Quoted message:\n> hi\n\nthe bot said here");+ const sent = JSON.stringify(buildDevsReport(input({ message: `${marker}\n@devs it broke`, summary: { by: "Scout", text: { wentWrong: `see ${marker}` } } })));+ expect(sent).not.toContain("omb-citation");+ });+it("masks key shapes, bearer and basic authorization, cookies, URL credentials and parameters, and private keys", () => {const text = [`key ${ANTHROPIC} and ${GITHUB} and ${SLACK}`,diff --git a/server/devs-report.ts b/server/devs-report.tsindex 5e27f270ab..f64a54fc43 100644--- a/server/devs-report.ts+++ b/server/devs-report.ts@@ -1,6 +1,7 @@// What one @devs report carries to the MausBot team's endpoint (POST /api/bug-reports on the Cloud origin): the person's// message, the bot's summary when it wrote one, and facts the server gathers itself. Never the conversation, never a// file. Everything passes redactReportText, and every field stays inside the endpoint's limits.+import { withoutCitationMarkers } from "../src/lib/citations.ts";import { isSecretName, mask, redactSecretsInText } from "./redact.ts";import { clip, oneLine } from "./host/text-clip.ts";@@ -89,7 +90,8 @@ export function environmentSecrets(env: NodeJS.ProcessEnv = process.env): string/** The app's own redaction (key shapes, Bearer tokens, secret-named values, private keys, URL passwords, held secrets),* then any authorization or cookie header, URL credentials and parameters, and the server's own secret values. */export function redactReportText(text: string, secrets: readonly string[] = environmentSecrets()): string {- let out = text;+ // A quote's encoded copy goes first: redaction cannot read inside it, and its readable fallback stays.+ let out = withoutCitationMarkers(text);for (const secret of secrets) if (out.includes(secret)) out = out.split(secret).join(mask(secret));out = out.replace(URL_IN_TEXT, (url: string, at: number, whole: string) => (whole.startsWith(URL_MASK, at + url.length) ? url : redactUrl(url)));out = out.replace(AUTHORIZATION, (_m, key: string, sep: string, value: string) => `${key}${sep}${mask(value)}`);diff --git a/server/host/devs-reports.test.ts b/server/host/devs-reports.test.tsindex 990b87ec1f..1e7fb45a89 100644--- a/server/host/devs-reports.test.ts+++ b/server/host/devs-reports.test.ts@@ -222,6 +222,35 @@ describe("a message that tags @devs", () => {fx.stop();});+ it("does not send for a @devs that is only inside a quote; the person's own @devs beside the same quote sends one", async () => {+ const fx = fixture();+ const said = fx.bot("scout-main", "I only send a report when your message tags @devs.");+ const quote = (comment: string) => citationAttachment({ ownerType: "bot", ownerId: "scout", threadId: "scout-main", messageId: said.id },+ createCitationTextSelector(said.text!, 0, said.text!.length)!, comment);+ fx.person("scout-main", composeMessage("what does this mean?", [quote("really?")]));+ fx.advance(NO_ANSWER_MS);+ await fx.settle();+ expect(fx.sent).toHaveLength(0);+ fx.person("scout-main", composeMessage("@devs this is wrong", [quote("")]));+ fx.advance(NO_ANSWER_MS);+ await fx.settle();+ expect(fx.sent).toHaveLength(1);+ expect(fx.sent[0]!.description.split("\n")[0]).toBe("this is wrong");+ fx.stop();+ });++ it("reads each part on its own: a code span the quote cuts in half does not hide the person's own @devs", async () => {+ const fx = fixture();+ const said = fx.bot("scout-main", "Try: run `npm i` first.");+ const quote = citationAttachment({ ownerType: "bot", ownerId: "scout", threadId: "scout-main", messageId: said.id },+ createCitationTextSelector(said.text!, 0, 12)!, "@devs it fails at `install`");+ fx.person("scout-main", composeMessage("", [quote]));+ fx.advance(NO_ANSWER_MS);+ await fx.settle();+ expect(fx.sent).toHaveLength(1);+ fx.stop();+ });+it("drops a marker it cannot read too, so nothing encoded slips past redaction", async () => {const fx = fixture();const token = `ghp_${"t".repeat(36)}`;diff --git a/server/host/devs-reports.ts b/server/host/devs-reports.tsindex 8e03cc1335..ec9c8bb02c 100644--- a/server/host/devs-reports.ts+++ b/server/host/devs-reports.ts@@ -20,7 +20,7 @@ import { tagsDevs, withoutDevsTags } from "../../shared/devs-mention.ts";import { versionAtLeast, type BugReportStatus } from "../../shared/devs-report-status.ts";import { failedTurnCause } from "../../shared/failed-turn.ts";import type { ResolvedSender } from "../../shared/wire.ts";-import { splitTranscriptCitations, withoutCitationMarkers } from "../../src/lib/citations.ts";+import { splitTranscriptCitations } from "../../src/lib/citations.ts";import { writeFileAtomic } from "../atomic.ts";import type { ProviderSnapshot } from "../contracts.ts";import { buildDevsReport, contactAddress, environmentSecrets, redactReportText, type BotSummary, type DevsReportPayload, type ReportedBot } from "../devs-report.ts";@@ -152,12 +152,11 @@ const droppedLine = (language: string | undefined) => serverLine(language, "serv/** A failure line names MausBot in every language: a bot reply that does has passed it on. */const FAILED_MARKER = "MausBot";-/** A quote's encoded copy never goes: redaction cannot read inside it. */-function asWritten(message: string, botNames: readonly string[]): { text: string; words: string } {+/** The person's own words: the text outside quotes and each quote's comment. Only a @devs there tags the message,+ * never one inside a message they quoted. */+function ownWords(message: string): string[] {const { display, citations } = splitTranscriptCitations(message);- const own = [display, ...citations.map((citation) => citation.comment ?? "")];- const words = own.map((part) => withoutDevsTags(withoutCitationMarkers(part), botNames)).filter(Boolean).join("\n\n");- return { text: withoutCitationMarkers(message), words };+ return [display, ...citations.map((citation) => citation.comment ?? "")];}/** Rides on the turn that answers a @devs message. */@@ -455,13 +454,14 @@ export function createDevsReports(deps: DevsReportsDeps) {function personWrote(threadId: string, line: Message): void {if (seen.has(line.id) || !line.text || now() - line.at > FRESH_MS) return;if (!line.sendId && deps.automated(threadId)) return;- if (!tagsDevs(line.text, botNames())) return;+ const names = botNames();+ const own = ownWords(line.text);+ if (!own.some((part) => tagsDevs(part, names))) return;seen.add(line.id);if (seen.size > 1_000) seen.delete(seen.values().next().value!);if (waiting.length >= MAX_WAITING) return notice(threadId, { ok: false, line: fullLine(languageFor(line.sender?.id)), marker: "" });const redact = (text: string) => clip(redactReportText(text, secrets()), 3_000);- const { text, words } = asWritten(line.text, botNames());- waiting.push({ messageId: line.id, threadId, at: line.at, text: redact(text), words: redact(words),+ waiting.push({ messageId: line.id, threadId, at: line.at, text: redact(line.text), words: redact(own.map((part) => withoutDevsTags(part, names)).filter(Boolean).join("\n\n")),...(line.sender ? { sender: { name: line.sender.name, ...(line.sender.id ? { id: line.sender.id } : {}) } } : {}) });save();}