Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(cloud): check the baked engines start, and stop offering codex update on My Cloud
AdityaUmale3a8b44af5922
diff --git a/Dockerfile b/Dockerfileindex 9e6113ebc4..028d0bc881 100644--- a/Dockerfile+++ b/Dockerfile@@ -176,11 +176,27 @@ RUN if [ -n "$GROK_VERSION" ]; then \# Engine CLIs baked into the image (space-separated npm packages). The publish# job passes each one's current version, or names only and today's date as# ENGINES_CACHE_TAG when it cannot look them up. Build-time CLI caches must-# not end up in the image or a customer's volume.+# not end up in the image or a customer's volume. npm can leave out an engine's+# platform package when its download fails and still succeed, and a Cloud's+# /usr/local is read-only, so nobody can repair it there: each engine CLI must+# start, else the install runs once more, else the build fails.ARG CLOUD_HOME_ENGINES="@anthropic-ai/claude-code @openai/codex"ARG ENGINES_CACHE_TAG=""RUN echo "engines: ${CLOUD_HOME_ENGINES:-none} ${ENGINES_CACHE_TAG}" \- && if [ -n "$CLOUD_HOME_ENGINES" ]; then HOME=/tmp/omb-build-home npm install -g $CLOUD_HOME_ENGINES; fi \+ && engines_start() { \+ for package in $CLOUD_HOME_ENGINES; do \+ case "$package" in \+ @anthropic-ai/claude-code|@anthropic-ai/claude-code@*) cli=claude ;; \+ @openai/codex|@openai/codex@*) cli=codex ;; \+ *) continue ;; \+ esac; \+ HOME=/tmp/omb-build-home "$cli" --version || { echo "$package installed, but $cli does not start" >&2; return 1; }; \+ 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; }; }; \+ 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/# The root supervisor runs /app's code and hands the server its secrets, sodiff --git a/scripts/docker-image.test.ts b/scripts/docker-image.test.tsindex 48d84fbd98..bf1ae5d41f 100644--- a/scripts/docker-image.test.ts+++ b/scripts/docker-image.test.ts@@ -296,6 +296,34 @@ describe("container images", () => {expect(keys.env!.CLOUD_HOME_ENGINES).toBe("@anthropic-ai/claude-code @openai/codex");});+ it.skipIf(process.platform === "win32")("installs the engines once more when one does not start, and fails the build when it still does not", () => {+ const engines = all.find(s => s.name === "cloud-home")!.steps.find(step => npmInstall(step) && step.args.includes("$CLOUD_HOME_ENGINES"))!;+ // `broken` lists what each install leaves out: one line per npm run, read in turn.+ const run = (broken: string[], packages = "@anthropic-ai/[email protected] @openai/[email protected]") => {+ const root = mkdtempSync(join(tmpdir(), "omb-engines-"));+ temporaryDirectories.push(root);+ writeFileSync(join(root, "plan"), broken.join("\n") + "\n");+ writeFileSync(join(root, "npm"), `#!/bin/sh\necho "$*" >> "${root}/npm.log"\nsed -n "$(wc -l < "${root}/npm.log")p" "${root}/plan" > "${root}/broken"\n`, { mode: 0o755 });+ for (const cli of ["claude", "codex"]) {+ writeFileSync(join(root, cli), `#!/bin/sh\ngrep -qx ${cli} "${root}/broken" && { echo "Missing optional dependency" >&2; exit 1; }\necho ${cli} 1.0\n`, { mode: 0o755 });+ }+ const result = spawnSync("sh", ["-c", engines.args], {+ env: { PATH: `${root}:/usr/bin:/bin`, CLOUD_HOME_ENGINES: packages, ENGINES_CACHE_TAG: "" }, encoding: "utf8",+ });+ const installs = readFileSync(join(root, "npm.log"), "utf8").trim().split("\n");+ return { status: result.status, installs: installs.length, stderr: result.stderr };+ };+ expect(run([""])).toMatchObject({ status: 0, installs: 1 });+ // npm leaving out Codex's platform package the first time: a second install puts it in+ expect(run(["codex", ""])).toMatchObject({ status: 0, installs: 2 });+ const stillBroken = run(["codex", "codex"]);+ expect(stillBroken).toMatchObject({ installs: 2 });+ expect(stillBroken.status).not.toBe(0);+ expect(stillBroken.stderr).toContain("@openai/[email protected] installed, but codex does not start");+ // names without versions, as the default build argument has them+ expect(run(["claude", "claude"], "@anthropic-ai/claude-code @openai/codex").status).not.toBe(0);+ });+it.skipIf(!jq)("resolves the current Chrome and engine releases, and keys on the date when a lookup fails", () => {const keys = (workflow.jobs.publish.steps as { id?: string; run?: string; env?: Record<string, string> }[]).find(step => step.id === "keys")!;const resolve = (ok: boolean) => {diff --git a/server/cli-setup.ts b/server/cli-setup.tsindex dbfeccc5c1..27684f8d7b 100644--- a/server/cli-setup.ts+++ b/server/cli-setup.ts@@ -195,7 +195,8 @@ async function connectNative(} else {io.log("Existing sign-in found — you do not need to sign in again.");}- if (state.snapshot.update) io.log(`${state.snapshot.update.title}: ${state.snapshot.update.command}`);+ const update = state.snapshot.update;+ if (update) io.log(`${update.title}: ${update.command ?? update.message}`);io.log("Sign-in confirmed. Model access is checked by the provider when you send your first message.");return state.models;}diff --git a/server/contracts.ts b/server/contracts.tsindex 8d2bd42008..7612796884 100644--- a/server/contracts.ts+++ b/server/contracts.ts@@ -363,7 +363,8 @@ export interface ProviderSnapshot {update?: {title: string;message: string;- command: string;+ /** Absent when there is nothing to run here, e.g. My Cloud's engines update with the Cloud. */+ command?: string;};/** On a subscription a reported cost is notional. */billing?: "metered" | "subscription";diff --git a/server/drivers/codex-update.ts b/server/drivers/codex-update.tsindex 0c0648dc87..4f80c840e1 100644--- a/server/drivers/codex-update.ts+++ b/server/drivers/codex-update.ts@@ -1,5 +1,6 @@// What the engine card offers when a newer stable Codex CLI is out: the update command for the configured executable.import { existsSync } from "node:fs";+import { cloudHomeConfigured } from "../cloud-home.ts";import type { ProviderSnapshot } from "../contracts.ts";import { splitCliString } from "../env-path.ts";import { codexVersionBehind, readLatestCodexRelease } from "./codex-release.ts";@@ -18,9 +19,14 @@ export function codexUpdateCommand(cli: string, platform: NodeJS.Platform = procreturn platform === "win32" ? `& ${command} update` : `${command} update`;}-export async function codexReleaseUpdate(version: string, cli: string): Promise<ProviderSnapshot["update"] | undefined> {+export async function codexReleaseUpdate(version: string, cli: string, onCloud = cloudHomeConfigured()): Promise<ProviderSnapshot["update"] | undefined> {const latest = await readLatestCodexRelease();if (!latest || !codexVersionBehind(version, latest)) return undefined;+ // My Cloud's Codex comes with the image, in a folder nobody can write to: `codex update` can only fail there.+ if (onCloud) return {+ title: `Codex ${latest} is out`,+ message: `A newer stable Codex CLI is available (installed: ${version}). On My Cloud, Codex comes with the Cloud and updates with its next release; there is nothing to run here.`,+ };return {title: `Update Codex to ${latest}`,message: `A newer stable Codex CLI is available (installed: ${version}). Update it, then refresh models. Model availability also depends on your signed-in account.`,diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.tsindex dd6763043a..58e7b8e971 100644--- a/server/drivers/codex.test.ts+++ b/server/drivers/codex.test.ts@@ -18,6 +18,7 @@ import { publishedMessages, replyProblems } from "../harness/text-items.testkit.import { caseTokens, LIVE_REPLY_CASES, liveReplyScripts } from "../testing/live-reply-cases.ts";import { CodexDriver, codexNativeIncomingLogMessage, codexUpdateCommand } from "./codex.ts";import { codexCliOverrides } from "./codex-process.ts";+import { codexReleaseUpdate } from "./codex-update.ts";import { parseToml } from "../toml-lite.ts";import * as codexProcess from "./codex-process.ts";import { CODEX_SIGN_IN_EXPIRED, codexLimitFacts, codexNotSignedIn, codexSignInRefused, codexUserError } from "./codex-errors.ts";@@ -3629,6 +3630,16 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`));});+ it("offers no update command on My Cloud, whose Codex updates with the Cloud", async () => {+ expect(await codexReleaseUpdate("0.150.0", "codex", false)).toMatchObject({ title: "Update Codex to 0.156.1", command: "codex update" });+ const cloud = await codexReleaseUpdate("0.150.0", "codex", true);+ expect(cloud).toEqual({+ title: "Codex 0.156.1 is out",+ message: expect.stringContaining("On My Cloud, Codex comes with the Cloud and updates with its next release"),+ });+ expect(await codexReleaseUpdate("0.156.1", "codex", true)).toBeUndefined();+ });+it("marks a Codex 401 as setup so the UI offers sign-in instead of Retry", async () => {await create({ mode: "unauthorized" });await instance.adapter.sendTurn({ threadId: "t-unauthorized", text: "hi" });diff --git a/src/components/EngineSetup.tsx b/src/components/EngineSetup.tsxindex 1e35bf727b..533add385b 100644--- a/src/components/EngineSetup.tsx+++ b/src/components/EngineSetup.tsx@@ -246,9 +246,9 @@ export function EngineUpdateNotice({<p className="mt-0.5 text-[12px] leading-relaxed text-ink-secondary">{update.message}</p></div></div>- {instance?.install?.server+ {update.command && (instance?.install?.server? <ServerEngineInstall instance={instance} mode="update" command={update.command} quiet={quiet} />- : <CommandRow command={update.command} actionLabel={t("engineSetup.openUpdate")} compact />}+ : <CommandRow command={update.command} actionLabel={t("engineSetup.openUpdate")} compact />)}</div>);}diff --git a/src/components/EngineUpdateNotice.test.ts b/src/components/EngineUpdateNotice.test.tsindex f2a452ab16..3205e98840 100644--- a/src/components/EngineUpdateNotice.test.ts+++ b/src/components/EngineUpdateNotice.test.ts@@ -22,6 +22,15 @@ describe("EngineUpdateNotice", () => {expect(markup).toContain('aria-label="Copy command"');});+ it("shows only the note when there is nothing to run, as on My Cloud", () => {+ const cloud = { title: "Codex 0.160.1 is out", message: "On My Cloud, Codex updates with the Cloud." };+ const markup = renderToStaticMarkup(createElement(EngineUpdateNotice, { update: cloud }));++ expect(markup).toContain("On My Cloud, Codex updates with the Cloud.");+ expect(markup).not.toContain('aria-label="Copy command"');+ expect(markup).not.toContain("<button");+ });+it("offers the native Terminal action when the desktop bridge supports it", () => {vi.stubGlobal("window", { ogb: { openInstallTerminal: vi.fn() } });diff --git a/src/state/store.tsx b/src/state/store.tsxindex 8a73dad86b..12cbb96c4b 100644--- a/src/state/store.tsx+++ b/src/state/store.tsx@@ -428,7 +428,7 @@ export interface InstanceInfo extends InstanceEndpointInfo {authenticationUnavailableReason?: string;account?: { email?: string; organization?: string; method?: "login" | "api-key" };version?: string | null;- update?: { title: string; message: string; command: string };+ update?: { title: string; message: string; command?: string };billing?: "metered" | "subscription";warning?: { title: string; message: string }; ollama?: import("../../shared/local-model").OllamaProblem;};