Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Train Q: keep the image buildable and math lazy
milind-soni8e6564f32e8b
diff --git a/.dockerignore b/.dockerignoreindex 5db2495bf9..561b5f2e31 100644--- a/.dockerignore+++ b/.dockerignore@@ -35,14 +35,10 @@ apps/docs/**!apps/docs/package.jsoncloudflare/**!cloudflare/control-plane/package.json-# Keep only the tunnel guardian files bundled by scripts/bundle-server.mjs-electron/**-!electron/managed-companion-guardian-main.mjs-!electron/managed-companion-guardian.mjs-!electron/companion-origin-gateway.mjs+# electron/ and companion/ stay: the server and the web app import many of their modules.+electron/resources/cloudflared*iosandroid-companionrelaydocsevalsdiff --git a/.github/workflows/docker.yml b/.github/workflows/docker.ymlindex b5c36e3b9a..56e010b891 100644--- a/.github/workflows/docker.yml+++ b/.github/workflows/docker.yml@@ -227,11 +227,11 @@ jobs:echo "$procs"uids() { awk -v pat="$1" 'NR > 1 && index($0, pat) { print $2 }' <<<"$procs" | sort -u | tr '\n' ' '; }test "$(uids dist-server/cloud-home-start.js)" = "0 "- test "$(uids dist-server/index.js)" = "$maus "+ test "$(uids dist-server/desktop-entry.mjs)" = "$maus " # the server, through its compile-cache bootstraptest "$(uids 'caddy run')" = "$maus "# No secret in the server's starting environment, read as any maus process (an# engine's shell) can read it: root in the container lacks CAP_SYS_PTRACE for that.- spid=$(docker exec home sh -c 'for p in /proc/[0-9]*; do case "$(tr "\0" " " < "$p/cmdline" 2>/dev/null)" in *"dist-server/in""dex.js"*) echo "${p#/proc/}";; esac; done')+ spid=$(docker exec home sh -c 'for p in /proc/[0-9]*; do case "$(tr "\0" " " < "$p/cmdline" 2>/dev/null)" in *"dist-server/desktop-en""try.mjs"*) echo "${p#/proc/}";; esac; done')test -n "$spid"docker exec -u maus home grep -qaF OMB_CLOUD_ROLE=home "/proc/$spid/environ" # the probe reads it# Out of memory, the kernel takes the engines first and the server and the edge (the health check) last.@@ -402,7 +402,7 @@ jobs:test "$(docker exec tunnel stat -c %u "/proc/$cpid")" = "$(docker exec tunnel id -u omb-tunnel)"if docker exec -u maus tunnel cat "/proc/$cpid/environ" >/dev/null 2>&1; then echo "maus can read the tunnel's token"; exit 1; fiif docker exec tunnel sh -c "tr '\\0' ' ' < /proc/$cpid/cmdline" | grep -qF "$token"; then echo "the token is in cloudflared's command line"; exit 1; fi- for p in $(docker exec tunnel sh -c 'for p in /proc/[0-9]*; do case "$(tr "\0" " " < "$p/cmdline" 2>/dev/null)" in *"dist-server/in""dex.js"*|*"caddy r""un"*) echo "${p#/proc/}";; esac; done'); do+ for p in $(docker exec tunnel sh -c 'for p in /proc/[0-9]*; do case "$(tr "\0" " " < "$p/cmdline" 2>/dev/null)" in *"dist-server/desktop-en""try.mjs"*|*"caddy r""un"*) echo "${p#/proc/}";; esac; done'); doif docker exec -u maus tunnel grep -qaF "$token" "/proc/$p/environ"; then echo "the token is in a maus process's environment"; exit 1; fidoneif docker logs tunnel 2>&1 | grep -qF "$token"; then echo "the token reached the log"; exit 1; fidiff --git a/server/cloud-home-start.ts b/server/cloud-home-start.tsindex 87906ab628..6f160e9019 100644--- a/server/cloud-home-start.ts+++ b/server/cloud-home-start.ts@@ -465,7 +465,7 @@ export function startCloudHome(processEnv: NodeJS.ProcessEnv = process.env) {const tunnelIds = ids && tunnelToken ? passwdIds(readFileSync("/etc/passwd", "utf8"), TUNNEL_USER) : null;if (ids && tunnelToken && !tunnelIds) throw new Error(`The ${TUNNEL_USER} user is missing from this image, so its tunnel cannot start.`);if (ids) {- const problem = codeTrustProblem([process.execPath, fileURLToPath(import.meta.url), join(here, "index.js"), edgeBin, edgeFiles.config, edgeFiles.routes,+ const problem = codeTrustProblem([process.execPath, fileURLToPath(import.meta.url), join(here, "index.js"), ...(existsSync(join(here, "desktop-entry.mjs")) ? [join(here, "desktop-entry.mjs")] : []), edgeBin, edgeFiles.config, edgeFiles.routes,...(tunnelToken ? [tunnelBin] : [])], home);if (problem) throw new Error(`This image's code is not safe to run as root: ${problem}. Rebuild it with docker build --target cloud-home.`);}diff --git a/src/styles.css b/src/styles.cssindex 8ba56b6e15..34d4ddf73b 100644--- a/src/styles.css+++ b/src/styles.css@@ -1,6 +1,8 @@@import "tailwindcss" source("../src");@source "../index.html";@source "../rail.html";+/* The dev previews under scripts/testing render with this stylesheet too. */+@source "../scripts/testing/*-preview.tsx";@source not "./locales";@source not "./**/*.test.ts";@source not "./**/*.test.tsx";diff --git a/vite.config.ts b/vite.config.tsindex 6023ae18ba..d42716d2df 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -54,7 +54,9 @@ export default defineConfig({if (!id.includes("node_modules")) return undefined;if (/[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/.test(id)) return "vendor-react";if (/[\\/]node_modules[\\/]lucide-react[\\/]/.test(id)) return "vendor-icons";- if (/[\\/]node_modules[\\/](react-markdown|remark-|rehype-|micromark|mdast-|hast-|unist-|unified|vfile|katex)[\\/]/.test(id)) return "vendor-markdown";+ // Math stays in its own chunk, loaded only when a message has math (ChatMarkdown.tsx).+ if (/[\\/]node_modules[\\/](katex|rehype-katex)[\\/]/.test(id)) return undefined;+ if (/[\\/]node_modules[\\/](react-markdown|remark-|rehype-|micromark|mdast-|hast-|unist-|unified|vfile)[\\/]/.test(id)) return "vendor-markdown";return undefined;},},