Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Name every file a folder page leaves out, and carry map data
milind-soni9ca05ee8c6e1
diff --git a/server/chat-apps.test.ts b/server/chat-apps.test.tsindex 4bc904b626..16c8933a9a 100644--- a/server/chat-apps.test.ts+++ b/server/chat-apps.test.ts@@ -247,7 +247,8 @@ describe("a folder page", () => {writeFileSync(film, "");truncateSync(film, 6 * 1024 * 1024 * 1024);writeFileSync(join(where.mine, "dash", "notes.mkv"), "not a page's video");- expect(await createAppCard({ store, docs, bot: SCOUT, threadId: THREAD, input: { tool: "show_html", path: "dash", title: "Dash" }, folders: where.of })).toEqual({ ok: true, messageId: "m1" });+ expect(await createAppCard({ store, docs, bot: SCOUT, threadId: THREAD, input: { tool: "show_html", path: "dash", title: "Dash" }, folders: where.of }))+ .toEqual({ ok: true, messageId: "m1", leftOut: "Left out notes.mkv (pages can't carry .mkv files)." });const doc = row("m1").app!.doc;const before = statSync(film, { bigint: true });expect(docs.video(doc, "clip.mp4")).toEqual({ file: realpathSync.native(film), bytes: 6 * 1024 * 1024 * 1024, dev: String(before.dev), ino: String(before.ino), mtimeNs: String(before.mtimeNs) });@@ -260,10 +261,28 @@ describe("a folder page", () => {expect(page.files.map((file) => file.path).sort()).toEqual(["app.js", "data.parquet", "index.html"]);const published = await readPageBundle("dash", [where.mine]);- expect(published.skipped.sort()).toEqual(["clip.mp4", "notes.mkv"]);+ expect(published.skipped).toEqual([{ path: "clip.mp4", why: "video" }, { path: "notes.mkv", why: "type" }]);expect(published.videos).toBeUndefined();});+ it("keeps map and table data beside index.html, and tells the bot each file it left out and why", async () => {+ const { docs, store, row } = setup();+ const where = folders();+ const dash = join(where.mine, "dash");+ const data = { "trails.json": "[]", "land.geojson": "{\"type\":\"FeatureCollection\",\"features\":[]}", "world.topojson": "{\"type\":\"Topology\"}",+ "rows.tsv": "a\tb\n1\t2", "events.ndjson": "{\"a\":1}\n" };+ for (const [name, text] of Object.entries({ ...data, "land.foo": "?", ".env": "SECRET=1" })) writeFileSync(join(dash, name), text);+ mkdirSync(join(dash, ".git"));+ writeFileSync(join(dash, ".git", "config"), "x");+ const show = (input: Record<string, unknown>) => createAppCard({ store, docs, bot: SCOUT, threadId: THREAD, input, folders: where.of });+ const note = "Left out land.foo (pages can't carry .foo files) and .env, .git/ (hidden).";+ expect(await show({ tool: "show_html", path: "dash", title: "Trails" })).toEqual({ ok: true, messageId: "m1", leftOut: note });+ for (const [name, text] of Object.entries(data)) expect(docs.readFile(row("m1").app!.doc, name)?.toString()).toBe(text);+ expect(docs.readFile(row("m1").app!.doc, "land.foo")).toBeNull();+ writeFileSync(join(dash, "app.js"), "drawMore()");+ expect(await show({ tool: "update_html", app_id: "m1", path: "dash" })).toEqual({ ok: true, messageId: "m1", leftOut: note });+ });+it("will not record a video reached by a link out of the bot's folders", async () => {const { docs, store, row } = setup();const where = folders();@@ -345,7 +364,7 @@ describe("publish_page in the chat", () => {await createAppCard({ store, docs, bot: SCOUT, threadId: THREAD, input: { tool: "show_html", path: "dash", title: "Dash" }, folders: async () => ({ roots: [base], vmWorkspace: null }) });writeFileSync(join(base, "dash", "index.html"), "<h1>Dash, edited</h1>");const published = await bundle();- expect(published.skipped).toEqual(["clip.webm"]);+ expect(published.skipped).toEqual([{ path: "clip.webm", why: "video" }]);expect(showPublishedPage({ store, docs, threadId: THREAD, card: LIVE, bundle: published })).toBe("m1");expect(row("m1")).toMatchObject({ publishedPage: LIVE, app: { rev: 1 } });expect(docs.read(row("m1").app!.doc)!.html).toBe("<h1>Dash, edited</h1>");diff --git a/server/chat-apps.ts b/server/chat-apps.tsindex 3f7e72f0cb..d26961ade0 100644--- a/server/chat-apps.ts+++ b/server/chat-apps.ts@@ -12,7 +12,7 @@ import type { AgentCardResult, AgentCardStore } from "./chat-widgets.ts";import { compileJsxPage } from "./jsx-compile.ts";import { appDocRefs } from "./message-db.ts";import { createPageFiles } from "./page-files.ts";-import { PageBundleError, readBotPageBundle, type BotFolders, type PageBundle, type PageFile } from "./pages/bundle.ts";+import { PageBundleError, readBotPageBundle, skippedNote, type BotFolders, type PageBundle, type PageFile } from "./pages/bundle.ts";import { redactSecretsInText } from "./redact.ts";import type { Message, StoreChange } from "./store.ts";import { userError, type UserError } from "./user-errors.ts";@@ -48,7 +48,7 @@ function scrubbed(html: string, title: string): { html: string; title: string; m/** A folder page also carries the files beside its index.html and where they were read. */type PageText = { html: string; format?: "jsx"; files?: PageFile[]; folder?: string; videos?: AppDocData["videos"] };-type MadePage = { ok: true; page: PageText; title: string; masked: boolean };+type MadePage = { ok: true; page: PageText; title: string; masked: boolean; leftOut?: string };/** The page's text, scrubbed; a jsx page is transpiled first, so one that cannot run is refused with where. */function pageText(value: { html?: string; jsx?: string }, title: string): MadePage | { ok: false; error: string } {@@ -70,7 +70,9 @@ export function bundlePage(bundle: PageBundle, title: string): MadePage | { ok:}const page = scrubbed(html, title);const videos = bundle.videos && Object.keys(bundle.videos).length ? { videos: bundle.videos } : {};- return { ok: true, page: { html: page.html, files: bundle.files.filter((file) => file !== index), folder: bundle.source, ...videos }, title: page.title, masked: page.masked };+ const leftOut = skippedNote(bundle.skipped);+ return { ok: true, page: { html: page.html, files: bundle.files.filter((file) => file !== index), folder: bundle.source, ...videos }, title: page.title, masked: page.masked,+ ...(leftOut ? { leftOut } : {}) };}async function folderPage(path: string, title: string, folders: BotFolders): Promise<MadePage | { ok: false; status: 400 | 403 | 404; error: string }> {@@ -145,7 +147,7 @@ function placePage(// No `from`: in a direct thread a bot-authored row carrying one is replayed as another bot's line.const message = store.appendMessage(threadId, { role: "bot", kind: "app", text: pageFallback(made.title, page, value.fallbackText), app: payload });args.authored?.(message.id);- return { ok: true, messageId: message.id, ...(made.masked ? { masked: true as const } : {}) };+ return { ok: true, messageId: message.id, ...(made.masked ? { masked: true as const } : {}), ...(made.leftOut ? { leftOut: made.leftOut } : {}) };}const existing = appRow(store, threadId, value.appId);if (!existing || (existing.from && existing.from.botId !== bot.id)) return { ok: false, status: 404, error: NO_SUCH_PAGE };@@ -153,7 +155,7 @@ function placePage(const patched = replacePage(store, docs, threadId, existing, made, value.frameless);if (!patched) return { ok: false, status: 404, error: NO_SUCH_PAGE };args.authored?.(patched.id);- return { ok: true, messageId: patched.id, ...(made.masked ? { masked: true as const } : {}) };+ return { ok: true, messageId: patched.id, ...(made.masked ? { masked: true as const } : {}), ...(made.leftOut ? { leftOut: made.leftOut } : {}) };}/** The next version of a row's page; the row is unchanged when the page is the same document. */diff --git a/server/chat-widgets.ts b/server/chat-widgets.tsindex 591117cee5..483fc03d74 100644--- a/server/chat-widgets.ts+++ b/server/chat-widgets.ts@@ -18,8 +18,9 @@ export interface AgentCardStore {}export type AgentCardResult =- /** `masked`: something in the widget read as a secret and was stored masked. */- | { ok: true; messageId: string; masked?: true }+ /** `masked`: something in the widget read as a secret and was stored masked. `leftOut`: a folder page's sentence naming+ * the files it left out. */+ | { ok: true; messageId: string; masked?: true; leftOut?: string }| { ok: false; status: 400 | 403 | 404 | 409; error: string };const ROOM_REFUSAL = "Widgets are not available in rooms yet. Answer in text.";diff --git a/server/drivers/agents-app-tools.ts b/server/drivers/agents-app-tools.tsindex 791a609d98..8badb9cb91 100644--- a/server/drivers/agents-app-tools.ts+++ b/server/drivers/agents-app-tools.ts@@ -2,7 +2,7 @@ export const APP_TOOL_DEFINITIONS = [{name: "show_html",description:- "Show a small self-contained web page in this chat, where the person watches it appear and can point at a part to change: a mini app, a game, a chart, a calculator, a report. For forms and choices use show_widget instead, and for plain data a markdown table. Send `html`, one HTML document (a fragment is wrapped) with inline style and script, or `jsx`, one React component file with a default export: it can import react, lucide-react icons, echarts, and Chart and useTheme from \"mausbot\", and style with Tailwind classes. Or send `path`, a folder in your working folder with index.html and its files (scripts, data, csv or parquet, images; up to 5 MB). It runs in a locked sandbox: no network requests, cookies, storage, popups or form posts. Scripts, styles and fonts load only from cdnjs.cloudflare.com, cdn.jsdelivr.net, unpkg.com and Google Fonts; images must be data: URLs or come from those CDNs. Embed the data you need. Use the CSS variables --color-text-primary, --color-background-primary, --color-border-primary and --font-sans to match the person's theme. In the page, mausbot.send(text) sends text as the person's next message (only after they click in it), mausbot.open(url) opens a link, and mausbot.setContext(text) tells you what they see, with their next message. At most 256 KB. To replace a page you showed, in place, call this again with the app_id it returned and new html, jsx or path (was update_html); it reloads, so anything the person did in it is lost. Never put secrets in it. Not available in rooms. For a data dashboard, follow the data-dashboards skill.",+ "Show a small self-contained web page in this chat, where the person watches it appear and can point at a part to change: a mini app, a game, a chart, a calculator, a report. For forms and choices use show_widget instead, and for plain data a markdown table. Send `html`, one HTML document (a fragment is wrapped) with inline style and script, or `jsx`, one React component file with a default export: it can import react, lucide-react icons, echarts, and Chart and useTheme from \"mausbot\", and style with Tailwind classes. Or send `path`, a folder in your working folder with index.html and its files (scripts, images, csv, geojson or parquet data; up to 5 MB). It runs in a locked sandbox: no network requests, cookies, storage, popups or form posts. Scripts, styles and fonts load only from cdnjs.cloudflare.com, cdn.jsdelivr.net, unpkg.com and Google Fonts; images must be data: URLs or come from those CDNs. Embed the data you need. Use the CSS variables --color-text-primary, --color-background-primary, --color-border-primary and --font-sans to match the person's theme. In the page, mausbot.send(text) sends text as the person's next message (only after they click in it), mausbot.open(url) opens a link, and mausbot.setContext(text) tells you what they see, with their next message. At most 256 KB. To replace a page you showed, in place, call this again with the app_id it returned and new html, jsx or path (was update_html); it reloads, so anything the person did in it is lost. Never put secrets in it. Not available in rooms. For a data dashboard, follow the data-dashboards skill.",inputSchema: {type: "object",additionalProperties: false,diff --git a/server/drivers/agents-call-cards.test.ts b/server/drivers/agents-call-cards.test.tsindex 5900a1b0e3..e747fbf723 100644--- a/server/drivers/agents-call-cards.test.ts+++ b/server/drivers/agents-call-cards.test.ts@@ -184,6 +184,13 @@ describe("the chat-app tools", () => {expect(JSON.parse(apiResponse.mock.lastCall![1]!.body as string)).toMatchObject({ app_id: "m9", frameless: false });});+ it("passes on the sentence naming the files a folder page left out", async () => {+ const leftOut = "Left out land.foo (pages can't carry .foo files) and .env (hidden).";+ const { context } = harness({ ok: true, status: 201, body: { messageId: "m9", leftOut } });+ expect(await callTool("show_html", { path: "trails", title: "Trails" }, context)).toEqual({ text: `Shown as app m9. To change it, call show_html again with app_id "m9". ${leftOut}` });+ expect(await callTool("show_html", { app_id: "m9", path: "trails" }, context)).toEqual({ text: `Updated app m9. ${leftOut}` });+ });+it("says when something in the page was masked as a secret", async () => {const { context } = harness({ ok: true, status: 201, body: { messageId: "m9", masked: true } });expect((await callTool("show_html", { html: "<p>hi</p>", title: "Hi" }, context)).text).toContain("masked before it was stored");diff --git a/server/drivers/agents-call-cards.ts b/server/drivers/agents-call-cards.tsindex 39849c7eb4..394164d9be 100644--- a/server/drivers/agents-call-cards.ts+++ b/server/drivers/agents-call-cards.ts@@ -32,10 +32,11 @@ async function callAppTool(name: "show_html" | "update_html", args: Json, contexif (!answer.ok) return { text: String(answer.body.error ?? (updating ? "Could not update that page." : "Could not show that page.")), isError: true };const messageId = String(answer.body.messageId ?? "");const masked = answer.body.masked === true ? MASKED : "";+ const leftOut = typeof answer.body.leftOut === "string" && answer.body.leftOut ? ` ${answer.body.leftOut}` : "";return {text: (updating? `Updated app ${messageId}.`- : `Shown as app ${messageId}. To change it, call show_html again with app_id "${messageId}".`) + masked,+ : `Shown as app ${messageId}. To change it, call show_html again with app_id "${messageId}".`) + leftOut + masked,};}diff --git a/server/drivers/agents-catalog-goldens/bridged.profiles.json b/server/drivers/agents-catalog-goldens/bridged.profiles.jsonindex 5061d2904e..26c9bf1bed 100644--- a/server/drivers/agents-catalog-goldens/bridged.profiles.json+++ b/server/drivers/agents-catalog-goldens/bridged.profiles.json@@ -1,7 +1,7 @@{"default": {- "bytes": 17486,- "sha256": "d6c5f68fac5114c9a084906d9dbb41e4acf688dc399af136f646a8dbe09b3a48",+ "bytes": 17473,+ "sha256": "fcebae60f1a1c3c6696f0791a2579359c15b2a87e06f413ec60f49aed267567b","tools": ["tool_result_read","list_room_targets",@@ -22,8 +22,8 @@]},"voice": {- "bytes": 18267,- "sha256": "31adb1164d5ddf9402d3d3f8717e85e461e94536726624f0a131732a5f978a27",+ "bytes": 18254,+ "sha256": "c9fab3e0fd274b565346468c0b7d9a0ccf8fb0af6df4eec7ef10cf3a838b2a2f","tools": ["tool_result_read","list_room_targets",@@ -45,8 +45,8 @@]},"shared": {- "bytes": 17526,- "sha256": "3ee291eef9c7feb02656074d2b7cdb5fb17f521a676dc7de84889a96ade36371",+ "bytes": 17513,+ "sha256": "5558fa84552c82a514623dbbc945e41faa0b27c07ebd32495635f60556e15ff6","tools": ["tool_result_read","list_room_targets",@@ -67,8 +67,8 @@]},"shared+voice": {- "bytes": 18307,- "sha256": "877278bc5c6cc55364f91e2a4681871d7d11984f9ba0718cb16888d6de868e7d",+ "bytes": 18294,+ "sha256": "860b2ac7813743149f7d28003bf7e17d933527d7e49ddd983d8db0a4ac2129b8","tools": ["tool_result_read","list_room_targets",@@ -90,8 +90,8 @@]},"skills": {- "bytes": 17513,- "sha256": "7dc64bf75c552508fecf18299f805eecb49e0614c91ae8a9a34b0fd355be9871",+ "bytes": 17500,+ "sha256": "de4cfed8a5c6ea3d54c183db9a6845481f70ef48a2d8dbcdf7619b2c1632279d","tools": ["tool_result_read","list_room_targets",@@ -112,8 +112,8 @@]},"skills+voice": {- "bytes": 18294,- "sha256": "e26a901638888fb66d009665f1b530e73cb3f77a4673c2a8f04f0a040a4b1211",+ "bytes": 18281,+ "sha256": "1070f2114ad93929c5607278439d03df4a9ec47d4ea4319c4c2b0e7f47bb4cf5","tools": ["tool_result_read","list_room_targets",@@ -135,8 +135,8 @@]},"skills+shared": {- "bytes": 17553,- "sha256": "fd3eff21b7949bf350ff6442598fcfc262fe83ff5aec5161d7b713f80192ee83",+ "bytes": 17540,+ "sha256": "d9d1eb64e1ad8276b29cb91e9e3174cf5739b07bd0ee93a2ad026d3e9167b3ef","tools": ["tool_result_read","list_room_targets",@@ -157,8 +157,8 @@]},"skills+shared+voice": {- "bytes": 18334,- "sha256": "75508bd60b6ca0880d85c4189abe41873d908f3d7a3c1999d17093c5db0fba28",+ "bytes": 18321,+ "sha256": "a1e5092cc513d973537501ed7aeb7923593bc1b98e30c171dfeee0b86d2a4d8c","tools": ["tool_result_read","list_room_targets",@@ -180,8 +180,8 @@]},"non-chief": {- "bytes": 17369,- "sha256": "23e2ad80b432e01a6ae06d62771a8b65ea699502f59f7215c1900c47bcb97e6b",+ "bytes": 17356,+ "sha256": "26f5eba3388e9433598e88c04b9d9ad24e6cc08af86a113d41f75076765eff0e","tools": ["tool_result_read","list_room_targets",@@ -202,8 +202,8 @@]},"voice+non-chief": {- "bytes": 18150,- "sha256": "ffbe59a8b70d4aeae2946c2713908f9b3c811b55d73825461ef83ec644f11446",+ "bytes": 18137,+ "sha256": "70c4eecfa79dcad070fba09dece0a8cac1f34245ead28b0bb39801952fc70006","tools": ["tool_result_read","list_room_targets",@@ -225,8 +225,8 @@]},"shared+non-chief": {- "bytes": 17409,- "sha256": "d129b8138301a4c0703955ec68c9783974dde152a880b0d5ec00603602b25503",+ "bytes": 17396,+ "sha256": "03eedaf024f646b4ef95d04b63d72a173e80e8343a1937e84f69d71bc45b1b3d","tools": ["tool_result_read","list_room_targets",@@ -247,8 +247,8 @@]},"shared+voice+non-chief": {- "bytes": 18190,- "sha256": "112581dc343c96f68d10b4e5bec09da88d4b43facbaf6565b3f9346a9e109932",+ "bytes": 18177,+ "sha256": "6326e8f0ed6427c86ae4c67a10e1ef946d9c61e1bc49cc0d80f61a4ac9b196fd","tools": ["tool_result_read","list_room_targets",@@ -270,8 +270,8 @@]},"skills+non-chief": {- "bytes": 17396,- "sha256": "532344c69251be38f6785733efff8b883ffb9e29e4aa2fee7eff0b3cd3a8f5f0",+ "bytes": 17383,+ "sha256": "67546e4f37616394ab22118488bd0803700ae882110e5376b32b2ef9f265bcd3","tools": ["tool_result_read","list_room_targets",@@ -292,8 +292,8 @@]},"skills+voice+non-chief": {- "bytes": 18177,- "sha256": "883ba35de49e0e42710ad70d3c4eca867a9914928e286fbb7e437533198fe436",+ "bytes": 18164,+ "sha256": "9bbe9e615e6467bb94b9f6d3d26a56e0bf98026a8a4757771f2b18632b3f556b","tools": ["tool_result_read","list_room_targets",@@ -315,8 +315,8 @@]},"skills+shared+non-chief": {- "bytes": 17436,- "sha256": "22d7409a3317748c631d7a3c68d50630a8ce3bc44e8b9c01b671cbc8f8be8ae6",+ "bytes": 17423,+ "sha256": "4ce82d42a71f6a6d4b1e8dadc4418178f6438f8726897ff55ce86b0e33f81a20","tools": ["tool_result_read","list_room_targets",@@ -337,8 +337,8 @@]},"skills+shared+voice+non-chief": {- "bytes": 18217,- "sha256": "02adbb9ba959791624147bdad4998a3400320212b0deb2773403a4472580d8f3",+ "bytes": 18204,+ "sha256": "a1a50a9be4cd5f148abaa67d56c3e059bd6b06b7498165e8275bd583c6b4da86","tools": ["tool_result_read","list_room_targets",@@ -360,8 +360,8 @@]},"skills+shared+voice+cloud-home": {- "bytes": 18350,- "sha256": "10d9df396cdce0dad65a7d03c5dfaed9cf17aa90d35a4f4659c28d86fd8f8f19",+ "bytes": 18337,+ "sha256": "f9977b9b0b06c9c10c1268936f07937cf850b44c9d8c17c8649969eeca275003","tools": ["tool_result_read","list_room_targets",@@ -383,8 +383,8 @@]},"skills+shared+voice+non-chief+cloud-home": {- "bytes": 18233,- "sha256": "d5cc0e692abc9ea368d320c7f7366ed2f47f0e550a36f17efd9e6c5318094024",+ "bytes": 18220,+ "sha256": "60886081deaccdbdd827e4567f39e96f9c21a3e3558a7246e81ec70483f13812","tools": ["tool_result_read","list_room_targets",@@ -406,8 +406,8 @@]},"skills+shared+voice+escalations": {- "bytes": 18352,- "sha256": "ef2b735dbd2144ad669fa2a86e5f597ae9111788a908d03358b7c521ce33850d",+ "bytes": 18339,+ "sha256": "3e2bacebc19fc38fa32e07a7c8df5f2e448f2770da4f4ad90cfb1ee230140991","tools": ["tool_result_read","list_room_targets",@@ -429,8 +429,8 @@]},"skills+shared+voice+escalations+x": {- "bytes": 18413,- "sha256": "2dc4a8eeae7c4952555dec885e44f31d6b548de2160a2bffd49d7bb465497037",+ "bytes": 18400,+ "sha256": "11027f1cc8ddf6aed937754128db624d7fd55175ad24a5e9ba9f7334daba57c5","tools": ["tool_result_read","list_room_targets",@@ -452,8 +452,8 @@]},"skills+shared+voice+escalations+x+team": {- "bytes": 18413,- "sha256": "2dc4a8eeae7c4952555dec885e44f31d6b548de2160a2bffd49d7bb465497037",+ "bytes": 18400,+ "sha256": "11027f1cc8ddf6aed937754128db624d7fd55175ad24a5e9ba9f7334daba57c5","tools": ["tool_result_read","list_room_targets",@@ -475,8 +475,8 @@]},"skills+shared+voice+escalations+x+team+images": {- "bytes": 18429,- "sha256": "bbbe7bb7e483b7e6df32f08db33aa661946ae079db2e3fe369bf4062bf7be3c9",+ "bytes": 18416,+ "sha256": "c5b35a83e416aad05080a823ef2741ad74c71d88c4c05d1813517986ff703dfd","tools": ["tool_result_read","list_room_targets",@@ -498,8 +498,8 @@]},"default+legacy-switches": {- "bytes": 17486,- "sha256": "d6c5f68fac5114c9a084906d9dbb41e4acf688dc399af136f646a8dbe09b3a48",+ "bytes": 17473,+ "sha256": "fcebae60f1a1c3c6696f0791a2579359c15b2a87e06f413ec60f49aed267567b","tools": ["tool_result_read","list_room_targets",@@ -520,8 +520,8 @@]},"default+mausbot": {- "bytes": 17538,- "sha256": "372d2580c54c1890ca1e06cbc713911adb5946b463002db1a943d965858c5bf8",+ "bytes": 17525,+ "sha256": "05c21c88d316f16b946eca7e36715b4b018d4584b6f61a917afd720bab91f20c","tools": ["tool_result_read","list_room_targets",@@ -542,8 +542,8 @@]},"skills+shared+voice+mausbot": {- "bytes": 18386,- "sha256": "8aec2a285e436bec7cfd7538b248a208670e29bde9613276edb4defa14d78ef6",+ "bytes": 18373,+ "sha256": "a9ae31060965c18e508370a57086b001ab2f9f782b57658f2cc8e599723e42fc","tools": ["tool_result_read","list_room_targets",@@ -565,8 +565,8 @@]},"default+no-computer-pick": {- "bytes": 16274,- "sha256": "8b5d7cd726989715e430fd0c602e3f72ffa1159d9614d3a357fd02f7b572b3ad",+ "bytes": 16261,+ "sha256": "f364ef71dc1a0370f6eb403f6ccf57667e1eb7b8bb54d9ec7eae09f18cccbd3f","tools": ["tool_result_read","list_room_targets",@@ -586,8 +586,8 @@]},"default+room": {- "bytes": 16213,- "sha256": "f3b83f7007aa75a8830e9457e67772f16e627703fcb2c4272f79cc5a497774b6",+ "bytes": 16200,+ "sha256": "42c900429ff018befde76478a185ba9db75bdc06d5c5f70c9f00ac2ddfa6c4bc","tools": ["tool_result_read","list_room_targets",@@ -607,8 +607,8 @@]},"non-chief+room": {- "bytes": 16096,- "sha256": "3555bc218e9e3763c03d0ad9ad5362822c949db1fb822ae3fb6e27e4c2156bfd",+ "bytes": 16083,+ "sha256": "cd88896555595729f19b1c41316ec6c06edb639372f3a97665c408f58b4d38aa","tools": ["tool_result_read","list_room_targets",@@ -628,8 +628,8 @@]},"default+images": {- "bytes": 17502,- "sha256": "ce42f064070e44731e840ec00db6977fbe880c8318f2188364f2dd8202b46867",+ "bytes": 17489,+ "sha256": "21eab4936ea8a778cb3c684907c6707deac2338e383bb73e2aadeafd5d31b84d","tools": ["tool_result_read","list_room_targets",diff --git a/server/drivers/agents-catalog-goldens/bridged.tools-list.json b/server/drivers/agents-catalog-goldens/bridged.tools-list.jsonindex bc8fead8a0..ee6499495e 100644--- a/server/drivers/agents-catalog-goldens/bridged.tools-list.json+++ b/server/drivers/agents-catalog-goldens/bridged.tools-list.json@@ -179,7 +179,7 @@},{"name": "publish_page",- "description": "Publish a page you made to a public link, only when the person asks to share or publish it: an .html file, or a folder with an index.html (static files, csv and parquet data too, up to 5 MB). Publishing the same path again, or passing page_id, updates the same link. Never publish secrets or personal details the person didn't ask to share. For a data dashboard, follow the data-dashboards skill.",+ "description": "Publish a page you made to a public link, only when the person asks to share or publish it: an .html file, or a folder with an index.html (static files and data too, up to 5 MB). Publishing the same path again, or passing page_id, updates the same link. Never publish secrets or personal details the person didn't ask to share. For a data dashboard, follow the data-dashboards skill.","inputSchema": {"type": "object","additionalProperties": false,diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.jsonindex 206cdde69e..0a05ea676f 100644--- a/server/drivers/agents-catalog-goldens/full.tools-list.json+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json@@ -441,7 +441,7 @@},{"name": "show_html",- "description": "Show a small self-contained web page in this chat, where the person watches it appear and can point at a part to change: a mini app, a game, a chart, a calculator, a report. For forms and choices use show_widget instead, and for plain data a markdown table. Send `html`, one HTML document (a fragment is wrapped) with inline style and script, or `jsx`, one React component file with a default export: it can import react, lucide-react icons, echarts, and Chart and useTheme from \"mausbot\", and style with Tailwind classes. Or send `path`, a folder in your working folder with index.html and its files (scripts, data, csv or parquet, images; up to 5 MB). It runs in a locked sandbox: no network requests, cookies, storage, popups or form posts. Scripts, styles and fonts load only from cdnjs.cloudflare.com, cdn.jsdelivr.net, unpkg.com and Google Fonts; images must be data: URLs or come from those CDNs. Embed the data you need. Use the CSS variables --color-text-primary, --color-background-primary, --color-border-primary and --font-sans to match the person's theme. In the page, mausbot.send(text) sends text as the person's next message (only after they click in it), mausbot.open(url) opens a link, and mausbot.setContext(text) tells you what they see, with their next message. At most 256 KB. To replace a page you showed, in place, call this again with the app_id it returned and new html, jsx or path (was update_html); it reloads, so anything the person did in it is lost. Never put secrets in it. Not available in rooms. For a data dashboard, follow the data-dashboards skill.",+ "description": "Show a small self-contained web page in this chat, where the person watches it appear and can point at a part to change: a mini app, a game, a chart, a calculator, a report. For forms and choices use show_widget instead, and for plain data a markdown table. Send `html`, one HTML document (a fragment is wrapped) with inline style and script, or `jsx`, one React component file with a default export: it can import react, lucide-react icons, echarts, and Chart and useTheme from \"mausbot\", and style with Tailwind classes. Or send `path`, a folder in your working folder with index.html and its files (scripts, images, csv, geojson or parquet data; up to 5 MB). It runs in a locked sandbox: no network requests, cookies, storage, popups or form posts. Scripts, styles and fonts load only from cdnjs.cloudflare.com, cdn.jsdelivr.net, unpkg.com and Google Fonts; images must be data: URLs or come from those CDNs. Embed the data you need. Use the CSS variables --color-text-primary, --color-background-primary, --color-border-primary and --font-sans to match the person's theme. In the page, mausbot.send(text) sends text as the person's next message (only after they click in it), mausbot.open(url) opens a link, and mausbot.setContext(text) tells you what they see, with their next message. At most 256 KB. To replace a page you showed, in place, call this again with the app_id it returned and new html, jsx or path (was update_html); it reloads, so anything the person did in it is lost. Never put secrets in it. Not available in rooms. For a data dashboard, follow the data-dashboards skill.","inputSchema": {"type": "object","additionalProperties": false,@@ -483,7 +483,7 @@},{"name": "publish_page",- "description": "Publish a page you made to a public link, only when the person asks to share or publish it: an .html file, or a folder with an index.html (static files, csv and parquet data too, up to 5 MB). Publishing the same path again, or passing page_id, updates the same link. Never publish secrets or personal details the person didn't ask to share. For a data dashboard, follow the data-dashboards skill.",+ "description": "Publish a page you made to a public link, only when the person asks to share or publish it: an .html file, or a folder with an index.html (static files and data too, up to 5 MB). Publishing the same path again, or passing page_id, updates the same link. Never publish secrets or personal details the person didn't ask to share. For a data dashboard, follow the data-dashboards skill.","inputSchema": {"type": "object","additionalProperties": false,diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.jsonindex 9a062a1526..1579b4c930 100644--- a/server/drivers/agents-catalog-goldens/profiles.json+++ b/server/drivers/agents-catalog-goldens/profiles.json@@ -1,7 +1,7 @@{"default": {- "bytes": 59340,- "sha256": "65d2d72264da0bb12933526d00f03a59d3ba967620701fc789fd9bebfe21f8ad",+ "bytes": 59335,+ "sha256": "bb1d91bb78f2231de50a2d9d23c6727cbde3939e1e696d43fa2ae5404c20102e","tools": ["tool_result_read","list_room_targets",@@ -51,8 +51,8 @@]},"voice": {- "bytes": 60121,- "sha256": "d4f551d4b173db1affb0926e8636e1a4ac37d1649bf2097197d3fd6e0163faa7",+ "bytes": 60116,+ "sha256": "8d6c2f704478ee6857b370e065083cf8f82078147defce0fb6f22521b31ff701","tools": ["tool_result_read","list_room_targets",@@ -103,8 +103,8 @@]},"shared": {- "bytes": 61605,- "sha256": "fd9928ed2b6b442cdaf8ab55140e7092964a8d46c971e04e973292f2dad9d019",+ "bytes": 61600,+ "sha256": "a404a6ee9252d45e088068e1a73ff300ae22602082eb7391b88dc663102449ba","tools": ["tool_result_read","list_shared_computers",@@ -156,8 +156,8 @@]},"shared+voice": {- "bytes": 62386,- "sha256": "36e5ff149ad0b93c6b5c497eb9f3bff8652aaf860f97cf8bebe97dcf9f8a563f",+ "bytes": 62381,+ "sha256": "d3255a56e24880bcc73ea940fa75b52195387a5c8cf51849eb500c30becb2d73","tools": ["tool_result_read","list_shared_computers",@@ -210,8 +210,8 @@]},"skills": {- "bytes": 62267,- "sha256": "6135fd2608e4d49a9e231f5e636ffd86e3a8720088a7ca7aba23a13e5b3662db",+ "bytes": 62262,+ "sha256": "66cfaa37f07114d5c228403a011ad4a002e7dc241c8c8c3fb97cd402f35a43f9","tools": ["tool_result_read","list_room_targets",@@ -263,8 +263,8 @@]},"skills+voice": {- "bytes": 63048,- "sha256": "66252617bb7029d34ef24820f18f48b8691236c0c74ac34911beb06765493210",+ "bytes": 63043,+ "sha256": "50627f02d6efb6e4a520017a155e5970ccdd435e13bead5b3bd5080b0a34a520","tools": ["tool_result_read","list_room_targets",@@ -317,8 +317,8 @@]},"skills+shared": {- "bytes": 64532,- "sha256": "60145540ec7ff1c02e64d87bae1c93dcdf5bca1446fc90c5c18d7f90f1271c3d",+ "bytes": 64527,+ "sha256": "2e993d2ae51a1dfc1fb39f621d0fd0a7866f5ef261c732f8c36a22f7d338c68c","tools": ["tool_result_read","list_shared_computers",@@ -372,8 +372,8 @@]},"skills+shared+voice": {- "bytes": 65313,- "sha256": "ac0555dbd0032ef3c12614a36d087d63950c955d306a030b3cacd1e8b3e83ec1",+ "bytes": 65308,+ "sha256": "9ef28fe5caed028538a4560bbfae791f28dae24f7948de8d691d10c0a937ffc0","tools": ["tool_result_read","list_shared_computers",@@ -428,8 +428,8 @@]},"non-chief": {- "bytes": 50124,- "sha256": "adeb52d81654ce85904d77c4d615590845236af686cfa5bbad250144e0fb3997",+ "bytes": 50119,+ "sha256": "554726c315150eab42be820c4f0ed544b07a955b246178e82bc752815ebfacee","tools": ["tool_result_read","list_room_targets",@@ -472,8 +472,8 @@]},"voice+non-chief": {- "bytes": 50905,- "sha256": "6b97feae5be74344a3d1d90bb56afc5e1ce8966650e0fb74984381e8959feaf8",+ "bytes": 50900,+ "sha256": "6064fc85e1bff66b698639c5fe6c36c2aa5068655cc1d46798364acc9c70405d","tools": ["tool_result_read","list_room_targets",@@ -517,8 +517,8 @@]},"shared+non-chief": {- "bytes": 52389,- "sha256": "f1822146db8afe5c8f8a946b4a63ca9967e762a1190f17364b8178b4f924158e",+ "bytes": 52384,+ "sha256": "ad0e7d200a895f0e312b7f8726f253f3a5fcc6d93115cc9aa5397c3be707def0","tools": ["tool_result_read","list_shared_computers",@@ -563,8 +563,8 @@]},"shared+voice+non-chief": {- "bytes": 53170,- "sha256": "94f805eb579b87ef9753c967f95cd8a12a734bb18d9f113f30ed05f7b931225a",+ "bytes": 53165,+ "sha256": "b4ebb2e21440a76cb5e1a5f5bae40da396957a4bbb574b87235fe5f5eb9104df","tools": ["tool_result_read","list_shared_computers",@@ -610,8 +610,8 @@]},"skills+non-chief": {- "bytes": 53051,- "sha256": "24f66bc798e102712896fb3b86461901d5b8738cec45113ef7e599b16f9058d1",+ "bytes": 53046,+ "sha256": "c066a8d93ce53263a2b9e138f576b11cd312852a378192b0f249737b37a4cbc6","tools": ["tool_result_read","list_room_targets",@@ -656,8 +656,8 @@]},"skills+voice+non-chief": {- "bytes": 53832,- "sha256": "20c008bdb7ade399b3e391e1d474e969ede68cf5cb3bb8ee698cddc2ae57f4d6",+ "bytes": 53827,+ "sha256": "d6b076820db28daf4456c6bf3df654afb2f7e23d73a3d577b1699625f74757fc","tools": ["tool_result_read","list_room_targets",@@ -703,8 +703,8 @@]},"skills+shared+non-chief": {- "bytes": 55316,- "sha256": "db965becc32ce7aa75339f0cb93ead0e911e8a3d8a4b5570271cf1708b4e340e",+ "bytes": 55311,+ "sha256": "f0c2b29ae4695a3930885dcfef7119151d65b6ad76eef3f7a9c7202a16c4d123","tools": ["tool_result_read","list_shared_computers",@@ -751,8 +751,8 @@]},"skills+shared+voice+non-chief": {- "bytes": 56097,- "sha256": "03d6a0d9a39b0b0cf5e18550c52810548f39809e9b622b6ba0fca4911f3b4d92",+ "bytes": 56092,+ "sha256": "d7fe4144b3c79be2c54db8ac56334f0bd46e133e5a155117b4059f993148a31e","tools": ["tool_result_read","list_shared_computers",@@ -800,8 +800,8 @@]},"skills+shared+voice+cloud-home": {- "bytes": 65079,- "sha256": "a5a0d5849e250c33b63bb04b914fe8c14bfbfe41ca1c163128202399e24f7975",+ "bytes": 65074,+ "sha256": "989e87a6d8d5645d10b7b691827e5bbf7abf41cc872815c4182f8da36dfe2abb","tools": ["tool_result_read","list_shared_computers",@@ -856,8 +856,8 @@]},"skills+shared+voice+non-chief+cloud-home": {- "bytes": 55863,- "sha256": "1a659071281088ad5aa9d7e5116c2c62f0cbf4ba7068e0f61edcaf70c15d9a7c",+ "bytes": 55858,+ "sha256": "8b7b66a2c8aa505b583b19a8085855357975a259195af260b5ed19ecf40cb282","tools": ["tool_result_read","list_shared_computers",@@ -905,8 +905,8 @@]},"skills+shared+voice+escalations": {- "bytes": 66143,- "sha256": "bb56189a11306e2b4636f108135aee82b52fcc3be1cb4b6b616fc680aaaa3287",+ "bytes": 66138,+ "sha256": "c699c17db8aff3b83f08334798fd13b6f1c8632fc625b16429deb9cc5a2b6764","tools": ["tool_result_read","list_shared_computers",@@ -962,8 +962,8 @@]},"skills+shared+voice+escalations+x": {- "bytes": 69982,- "sha256": "018968d7f08733f6d23945eff608f5c41937d078de5d9e95f96ab59f06267a95",+ "bytes": 69977,+ "sha256": "2c67c8b81db693f029c3e7be1eaf9948f58b99230ef68d9f79e732d7f86f2545","tools": ["tool_result_read","list_shared_computers",@@ -1023,8 +1023,8 @@]},"skills+shared+voice+escalations+x+team": {- "bytes": 69982,- "sha256": "018968d7f08733f6d23945eff608f5c41937d078de5d9e95f96ab59f06267a95",+ "bytes": 69977,+ "sha256": "2c67c8b81db693f029c3e7be1eaf9948f58b99230ef68d9f79e732d7f86f2545","tools": ["tool_result_read","list_shared_computers",@@ -1084,8 +1084,8 @@]},"skills+shared+voice+escalations+x+team+images": {- "bytes": 70755,- "sha256": "66dec6f1a6ea0a4750f5d3bd9293306b19640998e0aaa9d1e0c319590fcd5374",+ "bytes": 70750,+ "sha256": "31e2df247acf80d730eff39267cd09fe08d6445985f0d74b9f421e9d3dbae175","tools": ["tool_result_read","list_shared_computers",@@ -1146,8 +1146,8 @@]},"default+legacy-switches": {- "bytes": 59340,- "sha256": "65d2d72264da0bb12933526d00f03a59d3ba967620701fc789fd9bebfe21f8ad",+ "bytes": 59335,+ "sha256": "bb1d91bb78f2231de50a2d9d23c6727cbde3939e1e696d43fa2ae5404c20102e","tools": ["tool_result_read","list_room_targets",@@ -1197,8 +1197,8 @@]},"default+mausbot": {- "bytes": 59991,- "sha256": "e1edab1ae4b38a0cec81b901df0cbe413f0f7e7790d9918d9fd3b50926112fbc",+ "bytes": 59986,+ "sha256": "12ba8e0c3a30c0304c479f662d90c89950d63a40710b700c4c128b87e3dc418b","tools": ["tool_result_read","list_room_targets",@@ -1250,8 +1250,8 @@]},"skills+shared+voice+mausbot": {- "bytes": 65964,- "sha256": "eac49bb7dd495ff29c5ea3ea1d63d8c0c580b7686ea7a2f13408647ce7612b0a",+ "bytes": 65959,+ "sha256": "37f201ca7bf1663921b0a74ae4ed1f3947b7457a5ea946a422e0daa8c6784414","tools": ["tool_result_read","list_shared_computers",@@ -1308,8 +1308,8 @@]},"default+no-computer-pick": {- "bytes": 58128,- "sha256": "9009c1ff16258622aca14cb953ddda86042c1d3cb29a00128a4342989ca1a6e0",+ "bytes": 58123,+ "sha256": "e9336fbff7e7539a3e6141e2c44946a14696f4bdd7e87754ddfe95383c7e0fee","tools": ["tool_result_read","list_room_targets",@@ -1358,8 +1358,8 @@]},"default+room": {- "bytes": 51038,- "sha256": "81b4744f0ce5d9f8561b5adcbc2a6c811b69fb6fc006801d54db14ec610fc6c1",+ "bytes": 51025,+ "sha256": "1eeb67d32783ab5281a04d68b63e5398ac8b863b3cbffb89968837fd8bd8d5a2","tools": ["tool_result_read","list_room_targets",@@ -1403,8 +1403,8 @@]},"non-chief+room": {- "bytes": 41822,- "sha256": "16223df55fd195f63ae20dfc59abd1501deaf29823f6d6889a155afe6cbe9235",+ "bytes": 41809,+ "sha256": "dbf465585a45cf2c45de06eec811a1e5a5807db3d6a2126ee824db0dbda4d183","tools": ["tool_result_read","list_room_targets",@@ -1441,8 +1441,8 @@]},"default+images": {- "bytes": 60113,- "sha256": "600ec9e8c705f967f2bc4869d472fd0e52249ad6d7d13159c39571869b8ecf19",+ "bytes": 60108,+ "sha256": "50e4b6db12989dac797dce5dfa13bc9009560e5e489ede0da6f637b77f8a4fa5","tools": ["tool_result_read","list_room_targets",diff --git a/server/drivers/agents-pages-tools.ts b/server/drivers/agents-pages-tools.tsindex ad1317485c..f28dd4f8bd 100644--- a/server/drivers/agents-pages-tools.ts+++ b/server/drivers/agents-pages-tools.ts@@ -17,7 +17,7 @@ export const PAGE_TOOL_DEFINITIONS = [{name: "publish_page",description:- "Publish a page you made to a public link, only when the person asks to share or publish it: an .html file, or a folder with an index.html (static files, csv and parquet data too, up to 5 MB). Publishing the same path again, or passing page_id, updates the same link. Never publish secrets or personal details the person didn't ask to share. For a data dashboard, follow the data-dashboards skill.",+ "Publish a page you made to a public link, only when the person asks to share or publish it: an .html file, or a folder with an index.html (static files and data too, up to 5 MB). Publishing the same path again, or passing page_id, updates the same link. Never publish secrets or personal details the person didn't ask to share. For a data dashboard, follow the data-dashboards skill.",inputSchema: {type: "object",additionalProperties: false,diff --git a/server/folder-pages.e2e.test.ts b/server/folder-pages.e2e.test.tsindex f46489684f..cecaa1c03c 100644--- a/server/folder-pages.e2e.test.ts+++ b/server/folder-pages.e2e.test.ts@@ -69,10 +69,13 @@ it("shows a dashboard folder inline, serves its Parquet to the frame by token onwriteFileSync(join(dash, "index.html"), "<!doctype html><h1>Sales</h1><script src=\"app.js\"></script>");writeFileSync(join(dash, "app.js"), "fetch(new URL(\"data.parquet\", document.baseURI));");writeFileSync(join(dash, "data.parquet"), PARQUET);+ writeFileSync(join(dash, "regions.geojson"), "{\"type\":\"FeatureCollection\",\"features\":[]}");+ writeFileSync(join(dash, "regions.kml"), "<kml/>");const [shown] = await turn(analyst, [{ tool: "show_html", arguments: { path: "dash", title: "Sales dashboard" } }]);const appId = /^Shown as app ([\w-]+)\./.exec(shown!)?.[1];expect(appId, shown).toBeTruthy();+ expect(shown).toMatch(/ Left out regions\.kml \(pages can't carry \.kml files\)\.$/);const doc = await api(`/api/threads/${analyst.activeTaskId}/messages/${appId}/app?origin=${encodeURIComponent(fixture.info.url)}`);const base = /<base href="([^"]+)">/.exec(doc.body.srcdoc)?.[1] ?? "";expect(base).toMatch(new RegExp(`^${fixture.info.url}/api/page-files/[A-Za-z0-9_-]{43}/$`));@@ -86,6 +89,8 @@ it("shows a dashboard folder inline, serves its Parquet to the frame by token onexpect(Buffer.from(await ranged.arrayBuffer()).toString()).toBe("PAR1");const whole = await realFetch(`${base}data.parquet`);expect(Buffer.from(await whole.arrayBuffer()).equals(PARQUET)).toBe(true);+ const regions = await realFetch(`${base}regions.geojson`);+ expect([regions.status, regions.headers.get("content-type"), await regions.text()]).toEqual([200, "application/geo+json", "{\"type\":\"FeatureCollection\",\"features\":[]}"]);// A dot segment, even percent-encoded, is folded away by the URL itself and lands outside the token's folder.expect((await realFetch(`${base}%2e%2e/index.html`)).status).toBe(404);expect((await realFetch(`${base}..%2Fapp.js`)).status).toBe(400);@@ -135,7 +140,7 @@ it("streams a folder's video to the card by byte range, leaves it out of a publiexpect(Buffer.from(await seek.arrayBuffer()).equals(movie.subarray(2_000_000, 2_000_100))).toBe(true);const published = await turn(bot, { tool: "publish_page", arguments: { path: "film", title: "Film" } });- expect(published).toContain("Left out 1 file a page can't serve: clip.webm");+ expect(published).toContain("Left out clip.webm (published pages can't carry video).");expect([...[...stub.service.pages.values()].at(-1)!.files.keys()]).not.toContain("clip.webm");const kept = await realFetch(`${await base()}clip.webm`, { headers: { range: "bytes=0-9" } });expect(kept.status).toBe(206);diff --git a/server/index.ts b/server/index.tsindex 1e905c88d4..b63f9cd1c4 100644--- a/server/index.ts+++ b/server/index.ts@@ -13101,7 +13101,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {input: (body?.tool === "show_html" || body?.tool === "update_html") && cloudGuestDriven(internalCapability.threadId) ? { ...body, frameless: false } : body, authored: (id) => handoffs.authored(internalCapability.threadId, internalCapability.generation, id),});return result.ok- ? json(res, 201, { messageId: result.messageId, ...("masked" in result && result.masked ? { masked: true } : {}) })+ ? json(res, 201, { messageId: result.messageId, ...("masked" in result && result.masked ? { masked: true } : {}), ...("leftOut" in result && result.leftOut ? { leftOut: result.leftOut } : {}) }): json(res, result.status, { error: result.error });}// Notes from a room fewer people can see than this bot would carry its words to everyone who can see the bot.diff --git a/server/page-files.test.ts b/server/page-files.test.tsindex fdaa9b8a69..90fefe0a58 100644--- a/server/page-files.test.ts+++ b/server/page-files.test.ts@@ -17,10 +17,10 @@ vi.mock("node:fs/promises", async (original) => {const PARQUET = Buffer.from("PAR1\u0000\u0001\u0002\u0003 rows and columns PAR1", "latin1");-function setup() {+function setup(more: Array<{ path: string; data: Buffer }> = []) {const docs = new AppDocs(join(mkdtempSync(join(tmpdir(), "omb-page-files-")), "app-docs"));const stored = docs.put({ source: "html", html: "<h1>Sales</h1><script src=\"app.js\"></script>", data: { folder: "/work/dash" },- files: [{ path: "app.js", data: Buffer.from("draw()") }, { path: "data/sales.parquet", data: PARQUET }, { path: "notes.html", data: Buffer.from("<p>n</p>") }] });+ files: [{ path: "app.js", data: Buffer.from("draw()") }, { path: "data/sales.parquet", data: PARQUET }, { path: "notes.html", data: Buffer.from("<p>n</p>") }, ...more] });if (!stored.ok) throw new Error("not stored");let clock = 1_000;const files = createPageFiles({ docs, now: () => clock });@@ -74,6 +74,13 @@ describe("a folder page's files route", () => {expect(get(`${folder}data/sales.parquet`, { headers: { range: "lines=1-2" } }).status).toBe(416);});+ it("serves map and table data with its own type", () => {+ const types = { "land.geojson": "application/geo+json", "world.topojson": "application/json; charset=utf-8",+ "rows.tsv": "text/tab-separated-values; charset=utf-8", "events.ndjson": "application/x-ndjson; charset=utf-8" };+ const { folder, get } = setup(Object.keys(types).map((path) => ({ path, data: Buffer.from("{}") })));+ expect(Object.fromEntries(Object.keys(types).map((path) => [path, get(`${folder}${path}`).headers["content-type"]]))).toEqual(types);+ });+it("refuses a path that steps out of the folder or isn't one of its files, and a token it didn't give or that went stale", () => {const { folder, get, tick } = setup();for (const path of ["../app.js", "data/../app.js", "%2e%2e/app.js", "data%2Fsales.parquet", "data//sales.parquet", "data\\sales.parquet", "./app.js", "app.js%00"]) {diff --git a/server/page-files.ts b/server/page-files.tsindex 1f167eff49..57d0ca3d8f 100644--- a/server/page-files.ts+++ b/server/page-files.ts@@ -15,6 +15,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";import { extname } from "node:path";import { pipeline } from "node:stream";+import { PAGE_FILE_TYPES } from "../shared/published-page.ts";import type { AppDocs } from "./app-docs.ts";import type { PageVideo } from "./pages/bundle.ts";@@ -23,14 +24,7 @@ const TOKEN = /^[A-Za-z0-9_-]{43}$/;const DAY_MS = 24 * 60 * 60_000;const MAX_TOKENS = 5_000;-const TYPES: Readonly<Record<string, string>> = {- html: "text/html; charset=utf-8", htm: "text/html; charset=utf-8", css: "text/css; charset=utf-8", js: "text/javascript; charset=utf-8",- mjs: "text/javascript; charset=utf-8", json: "application/json; charset=utf-8", txt: "text/plain; charset=utf-8", csv: "text/csv; charset=utf-8",- md: "text/markdown; charset=utf-8", parquet: "application/vnd.apache.parquet", arrow: "application/vnd.apache.arrow.file", svg: "image/svg+xml",- png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", avif: "image/avif", ico: "image/x-icon",- woff: "font/woff", woff2: "font/woff2", ttf: "font/ttf", otf: "font/otf",- mp4: "video/mp4", webm: "video/webm", mov: "video/quicktime",-};+const TYPES: Readonly<Record<string, string>> = { ...PAGE_FILE_TYPES, mp4: "video/mp4", webm: "video/webm", mov: "video/quicktime" };// O_NOFOLLOW refuses a symlink swapped in at the last step, and O_NONBLOCK keeps a FIFO swapped in from hanging the open.// Windows has neither; there the identity check on the open handle alone refuses a different file.const VIDEO_OPEN_FLAGS = fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0);diff --git a/server/pages/bundle.ts b/server/pages/bundle.tsindex 7e8ccce0b7..d00cb313de 100644--- a/server/pages/bundle.ts+++ b/server/pages/bundle.ts@@ -1,5 +1,6 @@// A page's files, read from inside the bot's own folders only: the path is resolved and every file re-checked with// realpath containment, symlinks out of the folder are skipped, and hidden files and folders (.git, .env) never go.+// Everything left out is named to the bot, except the secret folder, which a page never mentions.import { lstat, readdir, readFile, realpath, stat } from "node:fs/promises";import { basename, extname, isAbsolute, join, relative, resolve, sep } from "node:path";import { PAGE_FILE_EXTENSIONS, PAGE_MAX_BYTES, PAGE_MAX_FILES } from "../../shared/published-page.ts";@@ -21,13 +22,19 @@ export interface PageVideo {ino: string;mtimeNs: string;}+/** Why a page left a file out, in the order the bot is told them. */+const SKIP_REASONS = ["type", "video", "name", "link", "deep", "packages", "hidden"] as const;+/** A file or folder (its path ends in "/") a page left out. */+export interface SkippedFile {+ path: string;+ why: (typeof SKIP_REASONS)[number];+}export interface PageBundle {/** The file or folder published, canonical: the same source publishes to the same link again. */source: string;files: PageFile[];bytes: number;- /** Files left out because a page can't serve them. */- skipped: string[];+ skipped: SkippedFile[];/** Only when asked for, by path in the folder: the pages Worker refuses video, so a published page leaves it out. */videos?: Record<string, PageVideo>;}@@ -102,29 +109,32 @@ export async function readPageBundle(requested: string, roots: readonly string[]return { source: target, files: [{ path: "index.html", data }], bytes: data.byteLength, skipped: [] };}if (!info.isDirectory()) throw new PageBundleError("Publish an .html file or a folder.");- const files: PageFile[] = [], skipped: string[] = [], videos: Record<string, PageVideo> = {};+ const files: PageFile[] = [], skipped: SkippedFile[] = [], videos: Record<string, PageVideo> = {};let bytes = 0;const walk = async (folder: string, depth: number): Promise<void> => {for (const name of (await readdir(folder)).sort()) {- if (name.startsWith(".")) continue;- const full = join(folder, name), own = await lstat(full);+ const full = join(folder, name);+ if (inSecretFolder(full)) continue;+ const own = await lstat(full), path = relative(target, full).split(sep).join("/");+ if (name.startsWith(".")) { skipped.push({ path: own.isDirectory() ? `${path}/` : path, why: "hidden" }); continue; }const real = own.isSymbolicLink() ? await realpath(full).catch(() => null) : full;- if (!real || !containedBy(root, real) || inSecretFolder(real)) continue;+ if (!real || !containedBy(root, real) || inSecretFolder(real)) { skipped.push({ path, why: "link" }); continue; }const entry = own.isSymbolicLink() ? await stat(real) : own;- const path = relative(target, full).split(sep).join("/");if (entry.isDirectory()) {- if (SKIPPED_FOLDERS.has(name) || depth >= 9 || !SEGMENT.test(name) || name.endsWith(".")) { skipped.push(`${path}/`); continue; }+ const why = SKIPPED_FOLDERS.has(name) ? "packages" : depth >= 9 ? "deep" : !SEGMENT.test(name) || name.endsWith(".") ? "name" : null;+ if (why) { skipped.push({ path: `${path}/`, why }); continue; }await walk(full, depth + 1);continue;}if (!entry.isFile()) continue;- if (options.videos && isVideo(name) && SEGMENT.test(name) && !name.endsWith(".")) {+ if (!servable(name) && !(options.videos && isVideo(name))) { skipped.push({ path, why: isVideo(name) ? "video" : "type" }); continue; }+ if (!SEGMENT.test(name) || name.endsWith(".")) { skipped.push({ path, why: "name" }); continue; }+ if (isVideo(name)) {if (files.length + Object.keys(videos).length >= limits.files) throw new PageBundleError(`The folder has more than ${limits.files} files a page can hold. Publish a smaller folder.`, 413);const identity = await stat(real, { bigint: true });videos[path] = { file: real, bytes: Number(identity.size), dev: String(identity.dev), ino: String(identity.ino), mtimeNs: String(identity.mtimeNs) };continue;}- if (!servable(name) || !SEGMENT.test(name) || name.endsWith(".")) { skipped.push(path); continue; }if (files.length >= limits.files) throw new PageBundleError(`The folder has more than ${limits.files} files a page can hold. Publish a smaller folder.`, 413);bytes += entry.size;if (bytes > limits.bytes) throw new PageBundleError(`The folder's files come to more than ${limits.bytes} bytes, a page's limit. Make the images smaller or leave some out.`, 413);@@ -138,6 +148,40 @@ export async function readPageBundle(requested: string, roots: readonly string[]return { source: target, files, bytes, skipped, ...(options.videos ? { videos } : {}) };}+const NOTE_GROUPS = 4, NOTE_PATHS = 3;++function reason(file: SkippedFile): string {+ switch (file.why) {+ case "type": {+ const extension = extname(file.path).slice(1).toLowerCase();+ return extension ? `pages can't carry .${extension} files` : "pages can't carry files without an extension";+ }+ case "video": return "published pages can't carry video";+ case "name": return "names with characters a page can't hold";+ case "link": return "links a page can't follow";+ case "deep": return "nested too deep";+ case "packages": return "package and cache folders";+ case "hidden": return "hidden";+ }+}++const inWords = (parts: readonly string[]) => parts.length > 1 ? `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}` : parts[0] ?? "";++/** One sentence for the bot naming what a page left out and why, grouped by reason; "" when nothing was. */+export function skippedNote(skipped: readonly SkippedFile[]): string {+ const groups = new Map<string, string[]>();+ for (const file of [...skipped].sort((a, b) => SKIP_REASONS.indexOf(a.why) - SKIP_REASONS.indexOf(b.why))) {+ const why = reason(file);+ groups.set(why, [...(groups.get(why) ?? []), file.path]);+ }+ const shown = [...groups].slice(0, NOTE_GROUPS);+ const parts = shown.map(([why, paths]) =>+ `${paths.slice(0, NOTE_PATHS).join(", ")}${paths.length > NOTE_PATHS ? ` and ${paths.length - NOTE_PATHS} more` : ""} (${why})`);+ const rest = skipped.length - shown.reduce((sum, [, paths]) => sum + paths.length, 0);+ if (rest) parts.push(`${rest} more`);+ return parts.length ? `Left out ${inWords(parts)}.` : "";+}+/** The bot's own folders for a turn, and its Local VM's workspace on this computer when it has one. */export type BotFolders = () => Promise<{ roots: readonly string[]; vmWorkspace: string | null }>;diff --git a/server/pages/published-pages.test.ts b/server/pages/published-pages.test.tsindex d8b1a7b2dc..dec64001d0 100644--- a/server/pages/published-pages.test.ts+++ b/server/pages/published-pages.test.ts@@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";import type { PublishedPageCard } from "../../shared/published-page.ts";import { FAKE_DESKTOP_TOKEN, FAKE_HOME, FAKE_TOKEN_URL, fakePagesService } from "../testing/fake-pages.ts";import { applyIncludedPagesMessage, pagesHomeSignature } from "./access.ts";-import { PageBundleError, readPageBundle } from "./bundle.ts";+import { PageBundleError, readPageBundle, skippedNote } from "./bundle.ts";import { PublishedPagesStore } from "./store.ts";import { createPublishedPages } from "./service.ts";import { createPagesInternalRoutes, createPublishedPageRoutes, type AppPages } from "../routes/published-pages.ts";@@ -85,7 +85,7 @@ describe("publishing a page", () => {const url = `https://${page}.mausbot.page/`;expect(outcome.text).toContain(`Published “Bake sale” at ${url}`);expect(outcome.text).toContain("This account now has 1 of 5 pages.");- expect(outcome.text).toContain("Free pages carry a small “Made with MausBot” badge.");+ expect(outcome.text.split("\n").at(-1)).toBe("Free pages carry a small “Made with MausBot” badge.");expect(f.cards).toEqual([{ threadId: "thread-1", id: "m1", text: `Published “Bake sale”: ${url} (1 of 5 pages)`,card: { state: "live", title: "Bake sale", pageId: page, url, usage: { pages: 1, limit: 5 } } }]);expect(Object.fromEntries(f.service.pages.get(page!)!.files)).toEqual(SITE);@@ -172,19 +172,31 @@ describe("publishing a page", () => {writeFileSync(join(dir, "secret.txt"), "outside");symlinkSync(join(dir, "secret.txt"), join(site, "linked.txt"));const outcome = await f.publish({ path: "site" });- expect(outcome.text).toContain("Left out 2 files a page can't serve: app.py, node_modules/");+ expect(outcome.text.split("\n").at(-1))+ .toBe("Left out app.py (pages can't carry .py files), linked.txt (links a page can't follow), node_modules/ (package and cache folders) and .env, .git/ (hidden).");const published = [...f.service.pages.values()][1]!;expect([...published.files.keys()].sort()).toEqual(["img/logo.svg", "index.html", "style.css"]);});- it("publishes a dashboard's csv, parquet and arrow data with it, and leaves out a wasm file", async () => {+ it("publishes a dashboard's csv, parquet, arrow and map data with it, and leaves out a wasm file", async () => {const f = setup();signIn();- writeSite(join(f.work, "dash"), { "index.html": "<p>Sales</p>", "data.parquet": "PAR1", "data/backup.csv": "a\n1\n", "data/live.arrow": "ARROW1", "duckdb.wasm": "x" });+ writeSite(join(f.work, "dash"), { "index.html": "<p>Sales</p>", "data.parquet": "PAR1", "data/backup.csv": "a\n1\n", "data/live.arrow": "ARROW1",+ "data/land.geojson": "{}", "duckdb.wasm": "x" });const outcome = await f.publish({ path: "dash" });- expect(outcome.text).toContain("Left out 1 file a page can't serve: duckdb.wasm");+ expect(outcome.text).toContain("Left out duckdb.wasm (pages can't carry .wasm files).");const [published] = [...f.service.pages.values()];- expect([...published!.files.keys()].sort()).toEqual(["data.parquet", "data/backup.csv", "data/live.arrow", "index.html"]);+ expect([...published!.files.keys()].sort()).toEqual(["data.parquet", "data/backup.csv", "data/land.geojson", "data/live.arrow", "index.html"]);+ });++ it("says why each file was left out, a few names per reason, and how many more", async () => {+ const site = writeSite(join(dir, "site"), { "index.html": "<p>x</p>", "page#2.js": "x", [`${"d/".repeat(10)}deep.js`]: "x" });+ expect((await readPageBundle(site, [dir])).skipped).toEqual([{ path: "d/".repeat(10), why: "deep" }, { path: "page#2.js", why: "name" }]);+ expect(skippedNote([])).toBe("");+ const py = ["a.py", "b.py", "c.py", "d.py", "e.py"].map((path) => ({ path, why: "type" as const }));+ expect(skippedNote([{ path: ".env", why: "hidden" }, ...py, { path: "x.foo", why: "type" }, { path: "Makefile", why: "type" }, { path: "a#b.js", why: "name" }]))+ .toBe("Left out a.py, b.py, c.py and 2 more (pages can't carry .py files), x.foo (pages can't carry .foo files), " ++ "Makefile (pages can't carry files without an extension), a#b.js (names with characters a page can't hold) and 1 more.");});it("refuses a folder over a page's bytes or files before asking for a token", async () => {diff --git a/server/pages/publisher.ts b/server/pages/publisher.tsindex 4f7948c3c1..7fe3fc236a 100644--- a/server/pages/publisher.ts+++ b/server/pages/publisher.ts@@ -1,6 +1,6 @@import { PAGE_ID, type PublishedPageCard } from "../../shared/published-page.ts";import { redactSecretsInText } from "../../shared/redact.ts";-import { PageBundleError, pageSource, readPageBundle, type PageBundle } from "./bundle.ts";+import { PageBundleError, pageSource, readPageBundle, skippedNote, type PageBundle } from "./bundle.ts";import type { PagesCall, PagesClient, PagesFailure, PageUsage } from "./client.ts";import type { PublishedPagesStore } from "./store.ts";@@ -122,9 +122,9 @@ export function createPagePublisher(deps: {`Page id ${result.pageId}. This account now has ${usageWords(result.usage)}.`,"A card with the link, Copy link and Unpublish is in the chat. Publishing the same file or folder again updates this same link.",...(result.badge ? ["Free pages carry a small “Made with MausBot” badge."] : []),- ...(bundle.skipped.length ? [`Left out ${bundle.skipped.length} file${bundle.skipped.length === 1 ? "" : "s"} a page can't serve: ${bundle.skipped.slice(0, 5).join(", ")}${bundle.skipped.length > 5 ? ", …" : ""}.`] : []),+ skippedNote(bundle.skipped),];- return { status: 200, text: lines.join("\n"), card };+ return { status: 200, text: lines.filter(Boolean).join("\n"), card };}return {diff --git a/server/secret-folder.test.ts b/server/secret-folder.test.tsindex c563149c2f..59e7322b4f 100644--- a/server/secret-folder.test.ts+++ b/server/secret-folder.test.ts@@ -54,6 +54,10 @@ describe("a bot's private secret files", () => {it("are never published, read by the extract helper, or uploaded to a page", async () => {await expect(readPageBundle(secret, [workspace])).rejects.toMatchObject({ status: 403, message: SECRET_FILE_REFUSAL });+ writeFileSync(join(workspace, ".env"), "x");+ const whole = await readPageBundle(workspace, [workspace]);+ expect(whole.files.map((file) => file.path).sort()).toEqual(["index.html", "notes.txt"]);+ expect(whole.skipped).toEqual([{ path: ".env", why: "hidden" }]);await expect(botFileSource(secret, async () => ({ roots: [workspace], vmWorkspace: null }))).rejects.toMatchObject({ status: 403 });expect(uploadableFiles([secret], [workspace])).toEqual({ error: SECRET_FILE_REFUSAL });expect(uploadableFiles([join(workspace, "notes.txt")], [workspace])).toMatchObject({ files: [expect.stringContaining("notes.txt")] });diff --git a/shared/published-page.ts b/shared/published-page.tsindex 1f0bce6f4b..10ab53362f 100644--- a/shared/published-page.ts+++ b/shared/published-page.ts@@ -18,10 +18,17 @@ export interface PublishedPageCard {/** The MausBot pages Worker's page ids: one DNS label of lowercase letters and digits. */export const PAGE_ID = /^[a-z0-9]{20,63}$/;-/** What a page's files may be, as the pages Worker serves them (openmaus-cloud pages-worker/src/files.ts refuses the rest). */-export const PAGE_FILE_EXTENSIONS: ReadonlySet<string> = new Set([- "html", "htm", "css", "js", "mjs", "json", "txt", "csv", "md", "parquet", "arrow",- "svg", "png", "jpg", "jpeg", "gif", "webp", "avif", "ico", "woff", "woff2", "ttf", "otf",-]);+/** What a page's files may be, by extension, and the Content-Type each is served with: the same list as the pages+ * Worker's (openmaus-cloud pages-worker/src/files.ts refuses the rest). */+export const PAGE_FILE_TYPES: Readonly<Record<string, string>> = {+ html: "text/html; charset=utf-8", htm: "text/html; charset=utf-8", css: "text/css; charset=utf-8", js: "text/javascript; charset=utf-8",+ mjs: "text/javascript; charset=utf-8", json: "application/json; charset=utf-8", txt: "text/plain; charset=utf-8", csv: "text/csv; charset=utf-8",+ tsv: "text/tab-separated-values; charset=utf-8", ndjson: "application/x-ndjson; charset=utf-8", md: "text/markdown; charset=utf-8",+ geojson: "application/geo+json", topojson: "application/json; charset=utf-8",+ parquet: "application/vnd.apache.parquet", arrow: "application/vnd.apache.arrow.file", svg: "image/svg+xml",+ png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", avif: "image/avif", ico: "image/x-icon",+ woff: "font/woff", woff2: "font/woff2", ttf: "font/ttf", otf: "font/otf",+};+export const PAGE_FILE_EXTENSIONS: ReadonlySet<string> = new Set(Object.keys(PAGE_FILE_TYPES));export const PAGE_MAX_BYTES = 5 * 1024 * 1024;export const PAGE_MAX_FILES = 200;