Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
perf(server): enable ESM code-splitting and tighten container builds (batch 4)
milind-soni19f7c6d4343c
diff --git a/Dockerfile b/Dockerfileindex e2b3ea2a88..0a5fc05f71 100644--- a/Dockerfile+++ b/Dockerfile@@ -50,7 +50,7 @@ RUN node /stage/prepare-cloudflared.mjs --current --root /stage \FROM --platform=$BUILDPLATFORM node:24-bookworm-slim AS buildWORKDIR /src# pinned to package.json#packageManager; corepack is being removed from Node-RUN npm install -g [email protected]+RUN npm install -g [email protected] --no-audit --no-fund# The image never runs Electron, so skip its ~100MB postinstall download.ENV ELECTRON_SKIP_BINARY_DOWNLOAD=1COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./@@ -112,7 +112,7 @@ ARG TARGETARCH# The global link must be the native binary for this platform (agent-browser's# postinstall points it there); the other platforms' binaries are never run.RUN echo "agent-browser ${AGENT_BROWSER_VERSION}, Chrome for Testing ${CHROME_CACHE_TAG:-Stable}, Debian Chromium ${CHROMIUM_CACHE_TAG:-latest}" \- && npm install -g --cache /tmp/npm-cache agent-browser@${AGENT_BROWSER_VERSION} \+ && npm install -g --cache /tmp/npm-cache agent-browser@${AGENT_BROWSER_VERSION} --no-audit --no-fund \&& if [ "$TARGETARCH" = arm64 ]; then \apt-get update && apt-get install -y --no-install-recommends chromium && rm -rf /var/lib/apt/lists/* \&& mkdir -p /opt/openmausbot-browser /etc/chromium/policies && ln -s /usr/lib/chromium/chromium /opt/openmausbot-browser/chrome; \@@ -156,7 +156,7 @@ ARG TARGETARCHRUN apt-get update \&& apt-get install -y --no-install-recommends python3 poppler-utils unzip bubblewrap socat tigervnc-standalone-server \&& rm -rf /var/lib/apt/lists/* \- && HOME=/tmp/omb-build-home npm install -g [email protected] \+ && HOME=/tmp/omb-build-home npm install -g [email protected] --no-audit --no-fund \&& uv_arch=x86_64 && if [ "$TARGETARCH" = arm64 ]; then uv_arch=aarch64; fi \&& mkdir -p /tmp/uv-install \&& curl -fsSL "https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-${uv_arch}-unknown-linux-gnu.tar.gz" | tar -xz -C /tmp/uv-install --strip-components=1 \@@ -208,8 +208,8 @@ RUN echo "engines: ${CLOUD_HOME_ENGINES:-none} ${ENGINES_CACHE_TAG}" \done; \} \&& if [ -n "$CLOUD_HOME_ENGINES" ]; then \- HOME=/tmp/omb-build-home npm install -g $CLOUD_HOME_ENGINES \- && { engines_start || { HOME=/tmp/omb-build-home npm install -g $CLOUD_HOME_ENGINES && engines_start; }; }; \+ HOME=/tmp/omb-build-home npm install -g --no-audit --no-fund $CLOUD_HOME_ENGINES \+ && { engines_start || { HOME=/tmp/omb-build-home npm install -g --no-audit --no-fund $CLOUD_HOME_ENGINES && engines_start; }; }; \fi \&& rm -rf /tmp/omb-build-home /tmp/node-compile-cacheCOPY deploy/fly/Caddyfile deploy/fly/Caddyfile.tls deploy/fly/Caddyfile.tunnel deploy/fly/edge-routes.caddy /app/cloud/@@ -239,7 +239,7 @@ ENV HOME=/dataVOLUME ["/data"]EXPOSE 8080# Fly uses the checks in fly.toml; this one serves a plain `docker run`.-HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=5 \+HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=5 \CMD curl -sf http://127.0.0.1:8080/api/health | grep -q openmausbot || exit 1# Starts as root: hands a fresh volume to `maus`, runs the server and the edge# as `maus`, and hands the server its secrets over a pipe, never an@@ -258,7 +258,7 @@ CMD ["node", "/app/dist-server/cloud-home-start.js"]FROM runtime AS server# Optional engine CLIs baked into the image (space-separated npm packages).ARG ENGINES=""-RUN if [ -n "$ENGINES" ]; then HOME=/tmp/omb-build-home npm install -g $ENGINES && rm -rf /tmp/omb-build-home /tmp/node-compile-cache; fi+RUN if [ -n "$ENGINES" ]; then HOME=/tmp/omb-build-home npm install -g --no-audit --no-fund $ENGINES && rm -rf /tmp/omb-build-home /tmp/node-compile-cache; fiCOPY --from=build --chown=maus:maus /src/dist-native/duckdb/target ./duckdbCOPY --from=build --chown=maus:maus /src/dist-server ./dist-serverCOPY --from=build --chown=maus:maus /src/dist ./distdiff --git a/deploy/podman/Containerfile b/deploy/podman/Containerfileindex d4d8e7916d..709792cac3 100644--- a/deploy/podman/Containerfile+++ b/deploy/podman/Containerfile@@ -2,7 +2,7 @@# Build both server and renderer from this checkout, never mix release artifacts.FROM node:24.15.0-bookworm-slim AS buildWORKDIR /src-RUN npm install -g [email protected]+RUN npm install -g [email protected] --no-audit --no-fundENV ELECTRON_SKIP_BINARY_DOWNLOAD=1COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./COPY apps/docs/package.json ./apps/docs/package.json@@ -27,12 +27,13 @@ RUN curl -fsSL https://github.com/podman-container-tools/podman/releases/downloa&& install -m 0755 /tmp/bin/podman-remote-static-linux_amd64 /usr/local/bin/podman \&& rm /tmp/podman.tgz /tmp/bin/podman-remote-static-linux_amd64WORKDIR /app+# Install optional engine CLIs beneath the per-commit app files and drop the npm cache in the same layer.+ARG ENGINES=""+RUN if [ -n "$ENGINES" ]; then HOME=/tmp/omb-build-home npm install -g --no-audit --no-fund $ENGINES && rm -rf /tmp/omb-build-home /tmp/node-compile-cache; fiCOPY --from=build --chown=maus:maus /src/dist-native/duckdb/linux-x64 ./duckdbCOPY --from=build --chown=maus:maus /src/dist-server ./dist-serverCOPY --from=build --chown=maus:maus /src/dist ./distCOPY --from=build --chown=maus:maus /src/skills ./skills-ARG ENGINES=""-RUN if [ -n "$ENGINES" ]; then npm install -g $ENGINES; fiENV HOME=/data \OMB_DUCKDB_DIR=/app/duckdb \OMB_DATA_DIR=/data/.openmausbot \diff --git a/scripts/bundle-server.mjs b/scripts/bundle-server.mjsindex 002e75d3f0..678a73ee02 100644--- a/scripts/bundle-server.mjs+++ b/scripts/bundle-server.mjs@@ -1,4 +1,4 @@-// Bundles each harness-server entry point into a self-contained ESM file: the+// Bundles the harness-server entry points into ESM under dist-server: the// packaged app ships no node_modules. Entry points keep their exact relative// paths under dist-server, where the server locates each proxy by path.import { build } from "esbuild";@@ -9,6 +9,11 @@ import { serverLocalePlugin } from "./server-locale-plugin.mjs";const root = join(dirname(fileURLToPath(import.meta.url)), "..");const server = join(root, "server");+const outdir = join(root, "dist-server");++// Clear stale bundles and hashed chunks from earlier builds so Docker and+// desktop packages only ship the current entry points and chunks.+rmSync(outdir, { recursive: true, force: true });// yaml's Node export is CommonJS with dynamic requires that cannot run once// inlined into ESM; its browser export is the same parser without them.@@ -28,7 +33,15 @@ const NODE_REQUIRE = {js: 'import { createRequire as __ombCreateRequire } from "node:module";\nconst require = __ombCreateRequire(import.meta.url);',};-// Every file run as its own process.+// Function names stay in stack traces. Node prints a whole source line with an uncaught error, so no line may be long.+const MINIFY_OPTIONS = {+ minifyWhitespace: true,+ minifySyntax: true,+ lineLimit: 500,+};++// Co-located entry points under dist-server that share ESM chunks and defer+// dynamic imports (vega/vega-lite, imapflow/nodemailer, undici) until needed.const ENTRY_POINTS = ["index.ts","message-search.worker.ts",@@ -39,14 +52,11 @@ const ENTRY_POINTS = ["workspace-backup.worker.ts",// the stall watch's thread (perf/stall-watch.ts)"stall-watch.worker.ts",- // the OMB Cloud Pro home image's entry point- "cloud-home-start.ts",// a Cloud server's backup runs it in the home before it packs the volume (cloud-backup-stage.ts)"cloud-backup-db-snapshot.ts",// the container image's entry point"server-launcher.ts",- // Imported directly by the packaged smoke probes. An explicit root sibling,- // because tsc may emit its own copy under dist-server/server/.+ // Imported directly by the packaged smoke probes."proxy-paths.ts","local-computer.ts","local-computer-proxy.ts",@@ -63,27 +73,51 @@ const ENTRY_POINTS = ["drivers/dweb-proxy.ts","drivers/phone-proxy.ts","drivers/chatgpt-plan-token-command.ts",- // the bot box (server/bot-box): the in-box bridge, the probe the self-check runs inside a box, and the check by hand+ // the bot box self-check run by hand or installer+ "bot-box/box-check.ts",+];++// Single-file standalone entry points: copied to remote hosts (meetbot),+// executed inside isolated sandboxes (box-bridge/box-probe), or run as root+// with file-level trust checks (cloud-home-start).+const STANDALONE_ENTRIES = [+ // the OMB Cloud Pro home image's entry point+ "cloud-home-start.ts",+ // the bot box (server/bot-box): the in-box bridge and the probe run inside a box"bot-box/box-bridge.ts","bot-box/box-probe.ts",- "bot-box/box-check.ts",// the meeting bot, copied to a cloud computer and run there with its own Node"meetings/meetbot.ts",];+// Keep chunks at the root of dist-server so every import.meta.url lookup+// inside shared modules resolves at the same directory depth as dist-server/index.js.await build({entryPoints: ENTRY_POINTS.map((entry) => join(server, entry)),bundle: true,+ splitting: true,+ chunkNames: "[name]-[hash]",platform: "node",target: "node20",format: "esm",outbase: server,- outdir: join(root, "dist-server"),- // Function names stay in stack traces. Node prints a whole source line with an uncaught error, so no line may be long.- minifyWhitespace: true,- minifySyntax: true,- lineLimit: 500,- // Written after tsc, replacing its output for these entry points.+ outdir,+ ...MINIFY_OPTIONS,+ allowOverwrite: true,+ logLevel: "info",+ plugins: [yamlEsmPlugin, serverLocalePlugin],+ banner: NODE_REQUIRE,+});++await build({+ entryPoints: STANDALONE_ENTRIES.map((entry) => join(server, entry)),+ bundle: true,+ platform: "node",+ target: "node20",+ format: "esm",+ outbase: server,+ outdir,+ ...MINIFY_OPTIONS,allowOverwrite: true,logLevel: "info",plugins: [yamlEsmPlugin, serverLocalePlugin],@@ -98,7 +132,8 @@ await build({platform: "node",target: "node20",format: "esm",- outfile: join(root, "dist-server", "mcp-server.js"),+ outfile: join(outdir, "mcp-server.js"),+ ...MINIFY_OPTIONS,allowOverwrite: true,logLevel: "info",plugins: [serverLocalePlugin],@@ -112,7 +147,8 @@ await build({platform: "node",target: "node20",format: "esm",- outfile: join(root, "dist-server", "tunnel-guardian.js"),+ outfile: join(outdir, "tunnel-guardian.js"),+ ...MINIFY_OPTIONS,allowOverwrite: true,logLevel: "info",});@@ -125,7 +161,8 @@ await build({platform: "node",target: "node20",format: "esm",- outfile: join(root, "dist-server", "prepare-cloudflared.js"),+ outfile: join(outdir, "prepare-cloudflared.js"),+ ...MINIFY_OPTIONS,allowOverwrite: true,logLevel: "info",});@@ -140,33 +177,34 @@ if (existsSync(join(root, "enterprise", "server", "index.ts"))) {platform: "node",target: "node20",format: "esm",- outfile: join(root, "dist-server", "enterprise", "server", "index.js"),+ outfile: join(outdir, "enterprise", "server", "index.js"),+ ...MINIFY_OPTIONS,allowOverwrite: true,logLevel: "info",plugins: [serverLocalePlugin],});- copyFileSync(join(root, "enterprise", "LICENSE"), join(root, "dist-server", "enterprise", "LICENSE"));+ copyFileSync(join(root, "enterprise", "LICENSE"), join(outdir, "enterprise", "LICENSE"));}// The packaged desktop and the container launcher run this bootstrap to turn on Node's compile cache.// Copied, not bundled: esbuild would inline index.js into it.-copyFileSync(join(root, "scripts", "desktop-server-entry.mjs"), join(root, "dist-server", "desktop-entry.mjs"));+copyFileSync(join(root, "scripts", "desktop-server-entry.mjs"), join(outdir, "desktop-entry.mjs"));// The model catalog snapshot (server/model-catalog/catalog.ts) is read from// disk, not inlined: 1.5 MB of JSON has no place in index.js. The bundle looks// for it under model-catalog/ beside itself. Its MIT notice is inside the file.-const catalogSnapshot = join(root, "dist-server", "model-catalog", "models-dev.snapshot.json");+const catalogSnapshot = join(outdir, "model-catalog", "models-dev.snapshot.json");mkdirSync(dirname(catalogSnapshot), { recursive: true });copyFileSync(join(server, "model-catalog", "models-dev.snapshot.json"), catalogSnapshot);// The starter apps' pages (server/local-apps/starters.ts), read from local-apps/starters/ beside the bundle.-cpSync(join(server, "local-apps", "starters"), join(root, "dist-server", "local-apps", "starters"), { recursive: true });+cpSync(join(server, "local-apps", "starters"), join(outdir, "local-apps", "starters"), { recursive: true });// Pi loads this through its own jiti and supplies TypeBox. Inline our local// policy module so the extension also works without the source checkout;// keep the Pi-owned dependency external and retain the .ts loading contract.const piMcpExtSrc = join(server, "drivers", "pi-mcp-extension.ts");-const piMcpExtDest = join(root, "dist-server", "drivers", "pi-mcp-extension.ts");+const piMcpExtDest = join(outdir, "drivers", "pi-mcp-extension.ts");mkdirSync(dirname(piMcpExtDest), { recursive: true });await build({ entryPoints: [piMcpExtSrc], outfile: piMcpExtDest, bundle: true,platform: "node", target: "node24", format: "esm", external: ["typebox"], });@@ -176,8 +214,4 @@ await build({ entryPoints: [piMcpExtSrc], outfile: piMcpExtDest, bundle: true,// The version rides along: an image ships dist-server without the root// package.json, and the server reports this one (server/environment.ts).const { version } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));-writeFileSync(join(root, "dist-server", "package.json"), `${JSON.stringify({ type: "module", version })}\n`);--// tsc copies the language packs server/server-lines.ts imports (13 MB) beside its own output. The bundles above carry-// the server's keys, so nothing reads the copies.-rmSync(join(root, "dist-server", "src", "locales"), { recursive: true, force: true });+writeFileSync(join(outdir, "package.json"), `${JSON.stringify({ type: "module", version })}\n`);diff --git a/server/places/place-proxy.ts b/server/places/place-proxy.tsindex 5e9c1aad8f..f455077f77 100644--- a/server/places/place-proxy.ts+++ b/server/places/place-proxy.ts@@ -18,7 +18,7 @@ import type { ServerResponse } from "node:http";import { intoPlace, isPlaceId, outOfPlace, ownId, PLACE_FILE_PREFIX, PLACE_KEY } from "../../shared/place-ids.ts";import { fromOwnPage } from "../request-auth.ts";import { userError, type UserErrorKey } from "../user-errors.ts";-import { PASS, type RouteContext, type RouteHandler } from "../routes/table.ts";+import { PASS, type RouteContext, type RouteHandler } from "../routes/pass.ts";/** The live stream of the one bot open in place: `?bot=<cloud:id>`, and `since` (or Last-Event-ID) to resume. */export const PLACE_EVENTS_PATH = `/api/places/${PLACE_KEY}/events`;diff --git a/server/routes/announcements.ts b/server/routes/announcements.tsindex 640d2be32a..2eb5eec810 100644--- a/server/routes/announcements.ts+++ b/server/routes/announcements.ts@@ -1,6 +1,6 @@import { announcementStore } from "../announcements/feed.ts";import { releaseNotesStore } from "../announcements/release-notes.ts";-import { PASS, type RouteHandler } from "./table.ts";+import { PASS, type RouteHandler } from "./pass.ts";export const ANNOUNCEMENTS_PATH = "/api/announcements";diff --git a/server/routes/cloud-sync.ts b/server/routes/cloud-sync.tsindex 6c82f16a8f..4033ba97c4 100644--- a/server/routes/cloud-sync.ts+++ b/server/routes/cloud-sync.ts@@ -8,7 +8,7 @@ import { createLentCopies, type LentCopies } from "../lent-copies.ts";import { createLentClones, type LentClones } from "../lent-clone.ts";import { answerAsleep, cloudPowerNow, type CloudPower } from "../cloud-power.ts";import type { RequestAuth } from "../request-auth.ts";-import { PASS, type RouteContext, type RouteHandler } from "./table.ts";+import { PASS, type RouteContext, type RouteHandler } from "./pass.ts";const FOLDER = String.raw`([\w-]{1,200})`;const UPLOAD = String.raw`([0-9a-f-]{36})`;diff --git a/server/routes/license.ts b/server/routes/license.tsindex aa556cd917..c1cd651bc6 100644--- a/server/routes/license.ts+++ b/server/routes/license.ts@@ -12,7 +12,7 @@ import { licenseEverOffered, licenseFilesUsed, licenseProofMatch, licenseState,import { CONNECTOR_HEADER, LICENSE_PROOF_HEADER } from "../license-proof.ts";import { seatDomains, seatsInUse } from "../license-seats.ts";import { ownerOrAdmin } from "../request-auth.ts";-import { PASS, type RouteContext } from "./table.ts";+import { PASS, type RouteContext } from "./pass.ts";export const LICENSE_PATH = "/api/license";/** The connector reads every 30 seconds; a licence it read this recently came from MausBot and is renewed by it. */diff --git a/server/routes/own-mcp-http.ts b/server/routes/own-mcp-http.tsindex d590393590..f2fe169fb1 100644--- a/server/routes/own-mcp-http.ts+++ b/server/routes/own-mcp-http.ts@@ -10,7 +10,7 @@ import { AGENTS_MCP_ENV } from "../drivers/agents-mcp-env.ts";import type { Json } from "../drivers/agents-client.ts";import { failure, harnessMcpRequest, MAX_INPUT_BYTES, MAX_OUTPUT_BYTES, parseHarnessMcpKind, type RpcId } from "../harness-mcp-request.ts";import { parseToolLimit, TOOL_LIMIT_HEADER } from "../tool-count-limit.ts";-import { PASS, type RouteContext, type RouteHandler } from "./table.ts";+import { PASS, type RouteContext, type RouteHandler } from "./pass.ts";import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH, TOOL_SHARE_HEADER } from "./own-mcp-http-path.ts";diff --git a/server/routes/pass.ts b/server/routes/pass.tsnew file mode 100644index 0000000000..6665be9911--- /dev/null+++ b/server/routes/pass.ts@@ -0,0 +1,30 @@+// Leaf contract shared by route handlers and the dispatch table so built-in+// routes do not form a circular ESM import with ./table.ts.+import type { IncomingMessage, ServerResponse } from "node:http";+import type { json, readBody } from "../harness/http.ts";+import type { RequestAuth } from "../request-auth.ts";++export const PASS: unique symbol = Symbol("route.pass");++export interface RouteContext {+ req: IncomingMessage;+ res: ServerResponse;+ url: URL;+ path: string;+ method: string;+ auth: RequestAuth;+ json: typeof json;+ readBody: typeof readBody;+}++/** Resolve with PASS to decline; anything else means the request was answered. */+export type RouteHandler = (ctx: RouteContext) => Promise<typeof PASS | void>;++/** True means stop routing. A handler that wrote a response but returned PASS still counts as answered. */+export async function dispatchRoutes(routes: readonly RouteHandler[], ctx: RouteContext): Promise<boolean> {+ for (const route of routes) {+ const out = await route(ctx);+ if (out !== PASS || ctx.res.headersSent || ctx.res.writableEnded) return true;+ }+ return false;+}diff --git a/server/routes/table.ts b/server/routes/table.tsindex 6945be9d2d..fe8df8e400 100644--- a/server/routes/table.ts+++ b/server/routes/table.ts@@ -1,38 +1,13 @@// server/index.ts runs this right after the auth gate, so every handler here is already authenticated.-import type { IncomingMessage, ServerResponse } from "node:http";-import type { json, readBody } from "../harness/http.ts";-import type { RequestAuth } from "../request-auth.ts";import { announcementRoutes } from "./announcements.ts";import { cloudSyncRoutes } from "./cloud-sync.ts";import { licenseRoutes } from "./license.ts";import { ownMcpHttpRoutes } from "./own-mcp-http.ts";+import { dispatchRoutes, PASS, type RouteContext, type RouteHandler } from "./pass.ts";import { webPanelRoutes } from "./web-panels.ts";import { placeProxyRoutes } from "../places/place-proxy.ts";-export const PASS: unique symbol = Symbol("route.pass");--export interface RouteContext {- req: IncomingMessage;- res: ServerResponse;- url: URL;- path: string;- method: string;- auth: RequestAuth;- json: typeof json;- readBody: typeof readBody;-}--/** Resolve with PASS to decline; anything else means the request was answered. */-export type RouteHandler = (ctx: RouteContext) => Promise<typeof PASS | void>;+export { dispatchRoutes, PASS, type RouteContext, type RouteHandler };/** Modules with no wiring from index.ts are listed here; index.ts pushes the rest. */export const ROUTES: RouteHandler[] = [placeProxyRoutes, cloudSyncRoutes, ownMcpHttpRoutes, webPanelRoutes, announcementRoutes, licenseRoutes];--/** True means stop routing. A handler that wrote a response but returned PASS still counts as answered. */-export async function dispatchRoutes(routes: readonly RouteHandler[], ctx: RouteContext): Promise<boolean> {- for (const route of routes) {- const out = await route(ctx);- if (out !== PASS || ctx.res.headersSent || ctx.res.writableEnded) return true;- }- return false;-}diff --git a/server/routes/web-panels.ts b/server/routes/web-panels.tsindex 79f9808100..e7325624a2 100644--- a/server/routes/web-panels.ts+++ b/server/routes/web-panels.ts@@ -1,5 +1,5 @@import { checkFraming } from "../web-panel-framing.ts";-import { PASS, type RouteHandler } from "./table.ts";+import { PASS, type RouteHandler } from "./pass.ts";/** GET /api/web-panels/framing?url=…&origin=…: whether the page at `url` lets the app at `origin` frame it.* Security: it reaches only public pages and answers with a verdict, never a page's content. */