Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge upstream/main into fix/mail-1a19186-citation-devs-report
AdityaUmale23803569d400
diff --cc server/host/devs-reports.test.tsindex 1e7fb45a89,376515205a..456d3062a1--- a/server/host/devs-reports.test.ts+++ b/server/host/devs-reports.test.ts@@@ -201,68 -200,17 +202,80 @@@ describe("a message that tags @devs", (expect(fx.sent).toHaveLength(1);fx.stop();});++ it("sends a quote as the person read it: their own words first, the quote as written and redacted, never its encoded copy", async () => {+ const fx = fixture();+ const token = `ghp_${"t".repeat(36)}`;+ const said = fx.bot("scout-main", "The relay failed.\nI only send a report when your message tags @devs.");+ const quote = citationAttachment({ ownerType: "bot", ownerId: "scout", threadId: "scout-main", messageId: said.id },+ createCitationTextSelector(said.text!, 0, said.text!.length)!, `@devs help me send on it, my token is ${token}`);+ fx.person("scout-main", composeMessage("", [quote]));+ fx.advance(NO_ANSWER_MS);+ await fx.settle();+ expect(fx.sent).toHaveLength(1);+ const { description } = fx.sent[0]!;+ const [words, rest] = description.split("\n\nWhat they wrote: ");+ expect(words).toBe(`help me send on it, my token is «redacted ${token.length} chars»`);+ expect(rest).toMatch(/^> Quoted message:\n> The relay failed\.\n> I only send a report when your message tags @devs\.\n/);+ expect(JSON.stringify(fx.sent[0])).not.toContain("omb-citation");+ expect(JSON.stringify(fx.sent[0])).not.toContain(token);+ expect(readFileSync(join(fx.dataDir, DEVS_REPORTS_FILE), "utf8")).not.toContain("omb-citation");+ 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)}`;+ fx.person("scout-main", `<!--omb-citation-v1:${Buffer.from(JSON.stringify({ comment: token })).toString("base64url")}-->\n@devs it broke`);+ fx.advance(NO_ANSWER_MS);+ await fx.settle();+ expect(fx.sent).toHaveLength(1);+ expect(fx.sent[0]!.description.split("\n")[0]).toBe("it broke");+ expect(JSON.stringify(fx.sent[0])).not.toContain("omb-citation");+ expect(readFileSync(join(fx.dataDir, DEVS_REPORTS_FILE), "utf8")).not.toContain("omb-citation");+ fx.stop();+ });+++ it("is never a message that tags a department named devs", async () => {+ const fx = fixture({ sections: ["Devs"] });+ fx.person("scout-main", "I added Rover to the @devs department, notify Scout");+ fx.busy.add("scout-main");+ expect(fx.reports.note("scout-main", true)).toBe("");+ fx.advance(NO_ANSWER_MS);+ await fx.settle();+ expect(fx.sent).toEqual([]);+ expect((await fx.call("scout", "scout-main", { went_wrong: "x" })).status).toBe(409);+ fx.stop();+ });});describe("what the person is told, in their language", () => {diff --cc server/host/devs-reports.tsindex ec9c8bb02c,d7f9d99f62..ea3d4ce08f--- a/server/host/devs-reports.ts+++ b/server/host/devs-reports.ts@@@ -20,8 -20,8 +20,9 @@@ import { tagsDevs, withoutDevsTags } frimport { 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 } from "../../src/lib/citations.ts";import { writeFileAtomic } from "../atomic.ts";+ import { startDueTimer } from "../due-timer.ts";import type { ProviderSnapshot } from "../contracts.ts";import { buildDevsReport, contactAddress, environmentSecrets, redactReportText, type BotSummary, type DevsReportPayload, type ReportedBot } from "../devs-report.ts";import { BUG_REPORT_STATUS_MAX_IDS, type ReportStatusAnswer, type ReportStatusQuestion, type SendOutcome } from "../devs-report-send.ts";@@@ -454,16 -450,17 +458,18 @@@ export function createDevsReports(depsfunction 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;- const names = botNames();- if (!tagsDevs(line.text)) return;+ const own = ownWords(line.text);++ if (!own.some((part) => tagsDevs(part))) return;+ const names = namesBeforeDevs();- if (!tagsDevs(line.text, names)) return;+ 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);- waiting.push({ messageId: line.id, threadId, at: line.at, text: redact(line.text), words: redact(withoutDevsTags(line.text, names)),+ 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();+ timer?.poke();}const unsubscribe = store.onChange((change: StoreChange) => {