Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Bot box: let bots read the files a person attaches (#4375)
Aditya Umale352313dff842
diff --git a/server/attachments.test.ts b/server/attachments.test.tsindex 4ed207137f..d4bcbb21bb 100644--- a/server/attachments.test.ts+++ b/server/attachments.test.ts@@ -12,7 +12,7 @@ import {writeFileSync,} from "node:fs";import { tmpdir } from "node:os";-import { join } from "node:path";+import { dirname, join } from "node:path";import { link, unlink } from "node:fs/promises";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";@@ -687,6 +687,37 @@ describe("clearing attachments from Settings", () => {expect(() => saveImage(Buffer.from("x".repeat(100)), "image/png")).not.toThrow();});+ it("removes a deleted or cleared upload from every conversation's box uploads folder too, so no box can still read it", () => {+ const deleted = saveImage(Buffer.from("deleted"), "image/png");+ const cleared = saveImage(Buffer.from("cleared"), "image/png");+ const kept = saveImage(Buffer.from("kept"), "image/png");+ const boxUploads = join(dirname(ATTACHMENTS_DIR), "box-uploads");+ const shown = [join(boxUploads, "bot-a", "thread-1"), join(boxUploads, "bot-b", "thread-2")];+ for (const dir of shown) {+ mkdirSync(dir, { recursive: true });+ for (const upload of [deleted, cleared, kept]) writeFileSync(join(dir, nameOf(upload.path)), "copy");+ }+ deleteAttachment(deleted.path);+ age(cleared.path, ATTACHMENT_CLEAR_MIN_AGE_MS + 1_000);+ clearAttachments(new Set([nameOf(kept.path)]));+ for (const dir of shown) expect(readdirSync(dir)).toEqual([nameOf(kept.path)]);+ rmSync(boxUploads, { recursive: true, force: true });+ });++ it("keeps an upload's box copies while the upload itself could not be deleted", () => {+ const busy = saveImage(Buffer.from("busy"), "image/png");+ const dir = join(dirname(ATTACHMENTS_DIR), "box-uploads", "bot-a", "thread-1");+ mkdirSync(dir, { recursive: true });+ writeFileSync(join(dir, nameOf(busy.path)), "copy");+ vi.mocked(unlinkSync).mockImplementationOnce(() => {+ throw Object.assign(new Error("resource busy"), { code: "EBUSY" });+ });+ deleteAttachment(busy.path);+ expect(existsSync(busy.path)).toBe(true);+ expect(readdirSync(dir)).toEqual([nameOf(busy.path)]);+ rmSync(join(dirname(ATTACHMENTS_DIR), "box-uploads"), { recursive: true, force: true });+ });+it("does not point a Team Cloud, which has no clear, to Settings", () => {const full = saveImage(Buffer.from("x"), "image/png");truncateSync(full.path, ATTACHMENTS_MAX_BYTES);diff --git a/server/attachments.ts b/server/attachments.tsindex eba2100026..69bc67cc27 100644--- a/server/attachments.ts+++ b/server/attachments.ts@@ -5,14 +5,16 @@ import {mkdirSync,readFileSync,readdirSync,+ rmSync,statSync,unlinkSync,writeFileSync,} from "node:fs";import { link, open, unlink } from "node:fs/promises";-import { join, extname } from "node:path";+import { basename, dirname, extname, join, resolve } from "node:path";import { FILE_MAX_BYTES } from "../shared/upload-limits.ts";import { DATA_DIR } from "./config.ts";+import { boxUploadsDir } from "./bot-box/plan.ts";export { FILE_MAX_BYTES } from "../shared/upload-limits.ts";export const ATTACHMENTS_DIR = join(DATA_DIR, "attachments");@@ -169,6 +171,21 @@ export function cleanupStaleAttachmentPartials(now = Date.now()): number {return removed;}+/** A removed upload also goes from every conversation's box uploads folder, where box-attachments.ts linked it, so no box+ * can still read it and its space comes back. */+function dropBoxUploadCopies(names: readonly string[], dataDir = DATA_DIR): void {+ if (!names.length) return;+ const root = join(dataDir, "box-uploads");+ const dirs = (path: string) => { try { return readdirSync(path); } catch { return []; } };+ for (const bot of dirs(root)) {+ for (const thread of dirs(join(root, bot))) {+ for (const name of names) {+ try { rmSync(join(boxUploadsDir(dataDir, bot, thread), name), { force: true }); } catch { /* best effort: a file still in use stays */ }+ }+ }+ }+}+/** Every removal of a file saveImage/saveFile created must come through here, or the cache overcounts and rejects uploads. */export function deleteAttachment(path: string): void {try {@@ -177,8 +194,11 @@ export function deleteAttachment(path: string): void {if (committedAttachmentBytes !== null) {committedAttachmentBytes = Math.max(0, committedAttachmentBytes - size);}- } catch {+ } catch (error) {+ // An upload still on disk (a busy file on Windows) keeps its box copies; one already gone loses them.+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") return;}+ if (resolve(dirname(path)) === resolve(ATTACHMENTS_DIR)) dropBoxUploadCopies([basename(path)]);}/** Settings → General: what the store holds against its ceiling, rescanned so files removed outside the app count. */@@ -215,6 +235,7 @@ export function clearAttachments(kept: ReadonlySet<string>, now = Date.now()): {let removed = 0;let freedBytes = 0;let failed = 0;+ const gone: string[] = [];for (const entry of readdirSync(ATTACHMENTS_DIR, { withFileTypes: true })) {if (!entry.isFile() || PARTIAL_NAME.test(entry.name) || kept.has(entry.name)) continue;const path = join(ATTACHMENTS_DIR, entry.name);@@ -222,6 +243,7 @@ export function clearAttachments(kept: ReadonlySet<string>, now = Date.now()): {const { mtimeMs, size } = statSync(path);if (now - mtimeMs < ATTACHMENT_CLEAR_MIN_AGE_MS) continue;unlinkSync(path);+ gone.push(entry.name);removed += 1;freedBytes += size;} catch (error) {@@ -229,6 +251,7 @@ export function clearAttachments(kept: ReadonlySet<string>, now = Date.now()): {if ((error as NodeJS.ErrnoException).code !== "ENOENT") failed += 1;}}+ dropBoxUploadCopies(gone);invalidateAttachmentAccounting();return { removed, freedBytes, failed };}diff --git a/server/bot-box/box.ts b/server/bot-box/box.tsindex 782817df24..57fc9f23a1 100644--- a/server/bot-box/box.ts+++ b/server/bot-box/box.ts@@ -15,7 +15,7 @@ import { openBoxEgressGate, type BoxEgressGate } from "./egress-gate.ts";import { boxEnvironment } from "./env.ts";import { openHarnessGate, type HarnessGate } from "./harness-gate.ts";import { DENIED_SYSCALLS, seccompBytes, seccompSupported } from "./seccomp.ts";-import { bwrapArgs, planBox, taskWorkspaceIds, type BoxBridge, type BoxPlan, type BoxRequest, type BoxSetup } from "./plan.ts";+import { boxUploadsDir, bwrapArgs, planBox, taskWorkspaceIds, type BoxBridge, type BoxPlan, type BoxRequest, type BoxSetup } from "./plan.ts";/** The loopback port inside a box that reaches the egress gate. The harness gate sits at the server's own port. */export const BOX_EGRESS_PORT = 3128;@@ -84,6 +84,11 @@ export class BoxRunner {wrap(given: BoxRequest): WrappedSpawn {const ids = given.cwd ? taskWorkspaceIds(given.cwd, this.options.setup.dataDir) : null;const lent = ids ? this.lentTo(ids.botId, ids.threadId) : [];+ // Made before the box starts, so an upload a later turn adds shows up in a box that is still running.+ if (ids) try { mkdirSync(boxUploadsDir(this.options.setup.dataDir, ids.botId, ids.threadId), { recursive: true, mode: 0o700 }); } catch (error) {+ // The bind stays optional, but an upload named later would then be unreadable in this box: say so.+ console.error(`bot box: could not make the uploads folder, so uploads stay unreadable in this box: ${error instanceof Error ? error.message : String(error)}`);+ }const request: BoxRequest = lent.length ? { ...given, rw: [...(given.rw ?? []), ...lent] } : given;const extraFds: number[] = [];const seccomp = this.options.seccompFile && !this.options.setup.mutate?.has("no-seccomp") ? this.options.seccompFile : null;diff --git a/server/bot-box/plan.ts b/server/bot-box/plan.tsindex 7cd260c4b0..2ebd081bcf 100644--- a/server/bot-box/plan.ts+++ b/server/bot-box/plan.ts@@ -99,6 +99,11 @@ export function taskWorkspaceIds(cwd: string, dataDir: string): { botId: string;return { botId: rel[0]!, threadId: rel[1]! };}+/** The server-owned folder holding a conversation's uploads for its boxes (server/box-attachments.ts), bound read-only. */+export function boxUploadsDir(dataDir: string, botId: string, threadId: string): string {+ return join(dataDir, "box-uploads", botId, threadId);+}+/** Absolute paths on the command line (`/x/y` or `--flag=/x/y`), which the engine must be able to read. */export function argvPaths(args: readonly string[]): string[] {const paths: string[] = [];@@ -187,6 +192,11 @@ export function planBox(setup: BoxSetup, request: BoxRequest): BoxPlan {const engines = resolve(root);mounts.push({ kind: mutate.has("engines-rw") ? "bind" : "ro", source: engines, target: engines, optional: true });}+ // The person's uploads for this conversation, after every read-write line: readable, but never writable or swappable.+ if (ids) {+ const shown = boxUploadsDir(dataDir, ids.botId, ids.threadId);+ mounts.push({ kind: "ro", source: shown, target: shown, optional: true });+ }const readOnly = new Set<string>();for (const path of [...(request.ro ?? []), ...argvPaths(request.args), ...(botId && ID.test(botId) ? [join(dataDir, "bots", botId, "SOUL.md")] : [])]) {const full = resolve(path);diff --git a/server/box-attachments.linux.test.ts b/server/box-attachments.linux.test.tsnew file mode 100644index 0000000000..561c812ab9--- /dev/null+++ b/server/box-attachments.linux.test.ts@@ -0,0 +1,50 @@+// A file the person attached, read from inside a real box (Linux with an unprivileged bubblewrap, like a Cloud home).+// Elsewhere the suite says so and skips, like the box's own self-check.+import { spawnSync } from "node:child_process";+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { afterAll, describe, expect, it } from "vitest";++import { defaultCodeRoots } from "./bot-box/box.ts";+import { detectBox } from "./bot-box/detect.ts";+import { boxUploadsDir, bwrapArgs, planBox } from "./bot-box/plan.ts";+import { attachmentsForBox } from "./box-attachments.ts";++const detection = detectBox({ env: { ...process.env, OMB_BOT_BOX: "1" } });+const available = detection.box === "bwrap" && detection.tools !== null;+const root = mkdtempSync(join(tmpdir(), "omb-box-attach-"));+afterAll(() => rmSync(root, { recursive: true, force: true }));++const home = join(root, "home"), dataDir = join(home, ".openmausbot"), uploads = join(dataDir, "attachments");+const cwd = join(dataDir, "task-workspaces", "bot-a", "t-1");+const env = { PATH: "/usr/bin:/bin", HOME: home };++/** What `cat` prints for the tag's path inside a box for this conversation, or null when it can't read it. */+function readInBox(tag: string): string | null {+ const path = /path="([^"]*)"/.exec(tag)![1]!;+ const run = runInBox(["/usr/bin/cat", path]);+ return run.status === 0 ? run.stdout : null;+}++function runInBox(argv: string[]): { status: number | null; stdout: string } {+ const plan = planBox({ dataDir, home, codeRoots: defaultCodeRoots(), engineRoots: [], bridges: [] }, { command: argv[0]!, args: [], cwd, env });+ return spawnSync(detection.tools!.bwrap, [...bwrapArgs(plan), "--", ...argv], { env, encoding: "utf8" });+}++describe.skipIf(!available)(`an attached file inside a real box (${available ? "bubblewrap works here" : `skipped: ${detection.reason}`})`, () => {+ it("is unreadable at its upload path, and readable but never writable at the path the engine is given", () => {+ mkdirSync(uploads, { recursive: true });+ mkdirSync(cwd, { recursive: true });+ const upload = join(uploads, "5c1e0d2a.md");+ writeFileSync(upload, "quarterly notes\n");+ const tag = `<attached-file path="${upload}" name="notes.md" />`;++ expect(readInBox(tag)).toBeNull();+ expect(readInBox(attachmentsForBox(tag, cwd, true, dataDir, uploads))).toBe("quarterly notes\n");+ // Read-only: the bot can neither change the upload nor swap the folder for a link.+ const shown = boxUploadsDir(dataDir, "bot-a", "t-1");+ expect(runInBox(["/usr/bin/sh", "-c", `echo x > ${join(shown, "5c1e0d2a.md")}`]).status).not.toBe(0);+ expect(runInBox(["/usr/bin/sh", "-c", `rm -rf ${shown} && ln -s /tmp ${shown}`]).status).not.toBe(0);+ });+});diff --git a/server/box-attachments.test.ts b/server/box-attachments.test.tsnew file mode 100644index 0000000000..73dc1175cb--- /dev/null+++ b/server/box-attachments.test.ts@@ -0,0 +1,85 @@+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { afterEach, beforeEach, describe, expect, it } from "vitest";+import { boxUploadsDir, planBox } from "./bot-box/plan.ts";+import { attachmentsForBox } from "./box-attachments.ts";++describe("attachmentsForBox", () => {+ let root: string, dataDir: string, uploads: string, cwd: string, shown: string;+ beforeEach(() => {+ root = mkdtempSync(join(tmpdir(), "box-attachments-"));+ dataDir = join(root, "data");+ uploads = join(dataDir, "attachments");+ cwd = join(dataDir, "task-workspaces", "bot", "thread");+ shown = boxUploadsDir(dataDir, "bot", "thread");+ mkdirSync(uploads, { recursive: true });+ mkdirSync(cwd, { recursive: true });+ });+ afterEach(() => rmSync(root, { recursive: true, force: true }));+ const run = (text: string, at: string | undefined = cwd, boxed = true) => attachmentsForBox(text, at, boxed, dataDir, uploads);++ it("puts each upload in the conversation's read-only uploads folder and points the engine there", () => {+ const upload = join(uploads, "1f0c2a.md");+ writeFileSync(upload, "# notes\n");+ writeFileSync(join(uploads, "9b7e.png"), "png");+ const text = `Read this\n<attached-file path="${upload}" name="notes.md" />\n<attached-image path="${join(uploads, "9b7e.png")}" name="shot.png" />`;++ const out = run(text);++ expect(out).toBe(`Read this\n<attached-file path="${join(shown, "1f0c2a.md")}" name="notes.md" />\n<attached-image path="${join(shown, "9b7e.png")}" name="shot.png" />`);+ expect(readFileSync(join(shown, "1f0c2a.md"), "utf8")).toBe("# notes\n");+ // Nothing is written into the working folder, which the bot controls.+ expect(existsSync(join(cwd, ".attachments"))).toBe(false);+ expect(run(text)).toBe(out);+ });++ it("finds an upload whose path the tag escaped", () => {+ const dir = join(root, "a&b", "attachments");+ mkdirSync(dir, { recursive: true });+ writeFileSync(join(dir, "x.md"), "x");+ const out = attachmentsForBox(`<attached-file path="${join(root, "a&b", "attachments", "x.md")}" name="x.md" />`, cwd, true, dataDir, dir);+ expect(out).toBe(`<attached-file path="${join(shown, "x.md")}" name="x.md" />`);+ });++ it("does not point at an upload that was deleted, even if an earlier turn linked it", () => {+ const upload = join(uploads, "gone.md");+ writeFileSync(upload, "x");+ const text = `<attached-file path="${upload}" name="g.md" />`;+ expect(run(text)).not.toBe(text);+ rmSync(upload);+ expect(run(text)).toBe(text);+ });++ it("changes nothing with the box off, without a working folder, or outside a conversation's own folder", () => {+ const upload = join(uploads, "a.md");+ writeFileSync(upload, "x");+ const text = `<attached-file path="${upload}" name="a.md" />`;+ expect(run(text, cwd, false)).toBe(text);+ expect(attachmentsForBox(text, undefined, true, dataDir, uploads)).toBe(text);+ expect(run(text, join(dataDir, "workspaces", "bot"))).toBe(text);+ expect(existsSync(shown)).toBe(false);+ });++ it("leaves paths outside the uploads folder, odd names and missing files as they are", () => {+ writeFileSync(join(root, "elsewhere.md"), "x");+ writeFileSync(join(dataDir, "secret.md"), "x");+ const text = [+ `<attached-file path="${join(root, "elsewhere.md")}" name="e.md" />`,+ `<attached-file path="${uploads}/../secret.md" name="s.md" />`,+ `<attached-file path="${join(uploads, "missing.md")}" name="m.md" />`,+ `<attached-file path="${join(uploads, ".openmaus-upload-x.partial")}" name="p" />`,+ ].join("\n");+ expect(run(text)).toBe(text);+ });++ it("is bound read-only into that conversation's boxes only, after its working folder", () => {+ const setup = { dataDir, home: root, codeRoots: [], engineRoots: [], bridges: [] };+ const targets = (at: string) => planBox(setup, { command: "/usr/bin/true", args: [], cwd: at, env: {} }).mounts.map((mount) => ("target" in mount ? mount.target : null));+ const plan = planBox(setup, { command: "/usr/bin/true", args: [], cwd, env: {} });+ const at = targets(cwd).indexOf(shown);+ expect(plan.mounts[at]).toEqual({ kind: "ro", source: shown, target: shown, optional: true });+ expect(at).toBeGreaterThan(targets(cwd).indexOf(cwd));+ expect(targets(join(dataDir, "task-workspaces", "bot", "other"))).not.toContain(shown);+ });+});diff --git a/server/box-attachments.ts b/server/box-attachments.tsnew file mode 100644index 0000000000..9199cec731--- /dev/null+++ b/server/box-attachments.ts@@ -0,0 +1,50 @@+import { constants, copyFileSync, existsSync, linkSync, mkdirSync, renameSync, rmSync } from "node:fs";+import { basename, dirname, join, resolve } from "node:path";+import { decodeAttachmentAttribute, escapeAttribute } from "../src/lib/composer-attachments.ts";+import { ATTACHMENTS_DIR } from "./attachments.ts";+import { botBox } from "./bot-box/box.ts";+import { boxUploadsDir, taskWorkspaceIds } from "./bot-box/plan.ts";+import { DATA_DIR } from "./config.ts";++const TAG = /(<attached-(?:file|image)[\t ]+path=")([^"\r\n]*)(")/g;+const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;++/**+ * The bot box hides the data folder, uploads included, so an `<attached-file>` path would be unreadable there.+ * Each upload the text names is linked into the conversation's uploads folder (plan.ts boxUploadsDir), which the server+ * owns and every box of the conversation sees read-only, and the path is rewritten to it. The bot can read the upload but+ * never write it or swap the folder for a link. Only the text sent to the engine changes; with the box off, or a working+ * folder that is not a conversation's own, nothing does.+ */+export function attachmentsForBox(text: string, cwd: string | undefined, boxed = botBox.enabled(), dataDir = DATA_DIR, attachmentsDir = ATTACHMENTS_DIR): string {+ if (!boxed || !cwd || !text.includes("<attached-")) return text;+ const ids = taskWorkspaceIds(resolve(cwd), resolve(dataDir));+ if (!ids) return text;+ const uploads = resolve(attachmentsDir), shown = boxUploadsDir(resolve(dataDir), ids.botId, ids.threadId);+ return text.replace(TAG, (tag, open: string, raw: string, close: string) => {+ const path = decodeAttachmentAttribute(raw), name = basename(path);+ if (resolve(dirname(path)) !== uploads || !NAME.test(name) || !existsSync(path)) return tag;+ const target = join(shown, name);+ try {+ // Uploads never change under their name, so one an earlier turn put here is kept.+ if (!existsSync(target)) {+ mkdirSync(shown, { recursive: true, mode: 0o700 });+ try {+ linkSync(path, target);+ } catch {+ // Another file system: a copy, renamed into place so one cut short never passes for a whole one.+ const partial = `${target}.${process.pid}.partial`;+ try {+ copyFileSync(path, partial, constants.COPYFILE_FICLONE);+ renameSync(partial, target);+ } finally {+ rmSync(partial, { force: true });+ }+ }+ }+ } catch {+ return tag;+ }+ return `${open}${escapeAttribute(target)}${close}`;+ });+}diff --git a/server/index.ts b/server/index.tsindex 799f453446..e31156b78c 100644--- a/server/index.ts+++ b/server/index.ts@@ -268,7 +268,7 @@ import { mainThread, wasOldestThread } from "./main-thread.ts";import { computerKindForResource, ManagedDesktopPolicy, type ComputerKind } from "./managed-policy.ts"; import { nudgeCloudTeamPolicy, remoteAccessPaths, startCloudTeamPolicy, stopCloudTeamPolicy } from "./cloud-team-policy.ts";import { hostedModelPolicy, HOSTED_MODEL_POLICY_HEADER } from "./hosted-models.ts";import { CLOUD_HOME_SECRET_KEYS, CLOUD_IGNORED_KEYS, cloudHomeConfiguration, cloudHomeOffersPlace, cloudHomePlaceRefusal, firstCloudTurnPatch } from "./cloud-home.ts";-import { botBox, startBotBoxAtBoot } from "./bot-box/boot.ts"; import { brokerPath } from "./bot-box/broker-probe.ts";+import { botBox, startBotBoxAtBoot } from "./bot-box/boot.ts"; import { attachmentsForBox } from "./box-attachments.ts"; import { brokerPath } from "./bot-box/broker-probe.ts";import { createCloudSignedHost } from "./host/cloud-signed-host.ts"; import { createBotNameClash } from "./host/bot-name-clash.ts"; import { hiddenThreadRefusal, hideOthersSyncFolders } from "./host/team-private.ts"; import { createTeamMemberLeft } from "./host/team-member-left.ts"; import { createUploadOwners, uploadsFor } from "./host/member-uploads.ts"; import { createMemberOwnBot } from "./host/member-own-bot.ts"; import { createVisibilityHost } from "./host/visibility-host.ts"; import { createBotAccessHost, relayedSendRefusal } from "./host/bot-access-gate.ts"; import { createBotAccessRoutes, writeAccess } from "./routes/bot-access.ts"; import { createAccessRequests } from "./host/access-requests.ts";import { createCloudPower, registerCloudPower, wokeFromSleep, type CloudPower } from "./cloud-power.ts"; import { createSharedComputerRoutes } from "./routes/shared-computers.ts";import { lentCopies, noteSyncBotTurn } from "./routes/cloud-sync.ts"; import { mcpReconnectLine, retryBrokeredMcp } from "./bot-box/broker-mcp.ts";@@ -8556,7 +8556,7 @@ async function beginTurn(threadId,botId: bot.id,startupRecovery,- text: withTurnClock(clock, withRecalled(recalled, dispatchContext.turnText + shareNote.text + devsReports.note(threadId, Boolean(integrations.agents)))),+ text: withTurnClock(clock, withRecalled(recalled, attachmentsForBox(dispatchContext.turnText, cwd) + shareNote.text + devsReports.note(threadId, Boolean(integrations.agents)))),...(recalled ? { recalled } : {}),images: dispatchContext.images,approvalMode: approvalModeForTurn(bot, commsDepth > 0, threadId),@@ -8568,7 +8568,7 @@ async function beginTurn(variant,resumeCursor: dispatchContext.resumeCursor,sessionReset: dispatchContext.sessionReset,- ...(dispatchContext.recoveryText !== undefined ? { recoveryText: withTurnClock(clock, dispatchContext.recoveryText + shareNote.text) } : {}),+ ...(dispatchContext.recoveryText !== undefined ? { recoveryText: withTurnClock(clock, attachmentsForBox(dispatchContext.recoveryText, cwd) + shareNote.text) } : {}),transcript,system: prompt.text,systemStable: prompt.stable,@@ -10454,7 +10454,7 @@ async function runClaimedGroupMemberTurn(threadId, botId: readyBot.id, claimId: internalGeneration, instance, guestConfined: roomGuestConfined, reset: Boolean(roomReset), hooks: Boolean(integrations.hooks),context: () => ({ ...roomMemberContexts.forThread(threadId)?.[readyBot.id], compactAt: nativeCompactTokens(instance) }),config: [roomSystem.stable, cwd, readyBot.modelSelection, turnApprovalMode, roomToolScope, roomUserMcp, integrations],- window: roomWindow, tail: roomTail, wrap: (body) => withTurnClock(clock, withRecalled(roomRecalled, body + roomShareNote.text + devsReports.note(threadId, Boolean(integrations.agents)))),+ window: roomWindow, tail: roomTail, wrap: (body) => withTurnClock(clock, withRecalled(roomRecalled, attachmentsForBox(body, cwd) + roomShareNote.text + devsReports.note(threadId, Boolean(integrations.agents)))),});guardTurnDispatch(roomShareNote.after(instance.adapter.sendTurn({...roomSession.send,diff --git a/src/lib/composer-attachments.ts b/src/lib/composer-attachments.tsindex 3fa8aedccc..b7c042bf0c 100644--- a/src/lib/composer-attachments.ts+++ b/src/lib/composer-attachments.ts@@ -460,7 +460,7 @@ export type TranscriptAttachments = {};/** A second encoded pass stays encoded rather than turning attacker-controlled text into markup. */-function decodeAttachmentAttribute(value: string): string {+export function decodeAttachmentAttribute(value: string): string {return value.replace(/&(quot|lt|gt|amp);|&#(9|10|13);/g, (entity, named: string | undefined, numeric: string | undefined) => {if (numeric === "9") return "\t";if (numeric === "10") return "\n";