Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Self-hosted image: the CLI reads the version the bundle ships, and never reports one it could not read
Dantec882197664eb
diff --git a/server/cli.ts b/server/cli.tsindex de9c2f3fae..01276d9272 100644--- a/server/cli.ts+++ b/server/cli.ts@@ -25,6 +25,7 @@ import { parseAllowList } from "./account-signin.ts";import { appendAdminAction, flushAdminActivity, sharedSignIn } from "./admin-activity.ts";import { bindDecisionRetention, decisionRetentionDays } from "./decision-log.ts";import { hostedWorkspaceConfigured } from "./enterprise.ts";+import { reportableServerVersion, serverVersion } from "./environment.ts";import { resolveLoopbackTrust } from "./request-auth.ts";import { restartPolicy } from "./restart.ts";import { writeFileAtomic } from "./atomic.ts";@@ -246,16 +247,6 @@ export function defaultIo(): CliIo {};}-export function serverVersion(here = HERE): string {- try {- const parsed: unknown = JSON.parse(readFileSync(resolve(here, "..", "package.json"), "utf8"));- const version = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "version") : undefined;- return typeof version === "string" && version ? version : "0.0.0";- } catch {- return "0.0.0";- }-}-const message = (error: unknown) => (error instanceof Error ? error.message : String(error));/** On a service-trust server: the secret `serve` handed the server it started, which opens its pairing route. */@@ -438,7 +429,7 @@ export async function runStatus(options: CliOptions, io: CliIo = defaultIo()): Pconst sessions = await api(options.port, "/api/auth/sessions").catch(() => null);if (Array.isArray(sessions?.body?.sessions)) io.log(`Paired ${sessions.body.sessions.length} device${sessions.body.sessions.length === 1 ? "" : "s"} ${cliCommand("devices")}`);}- const account = options.json ? null : describeTunnelAccount(createTunnelAccount({ dataDir: options.dataDir, version: serverVersion() }).credentials.read());+ const account = options.json ? null : describeTunnelAccount(createTunnelAccount({ dataDir: options.dataDir, version: reportableServerVersion() }).credentials.read());if (!options.json && fleetCredential()) io.log(`MausBot web address: managed by the fleet (${FLEET_CREDENTIAL_ENV} is set)`);else if (account?.address) io.log(`MausBot web address: ${account.address} (signed in as ${account.email ?? "?"}; serve it with ${cliCommand("serve --tunnel")})`);return body ? 0 : 1;@@ -510,7 +501,7 @@ export async function runAccess(options: CliOptions, io: CliIo = defaultIo()): P}export async function runLogin(options: CliOptions, io: CliIo = defaultIo()): Promise<number> {- const account = createTunnelAccount({ dataDir: options.dataDir, version: serverVersion(), relayOnly: options.relay === true });+ const account = createTunnelAccount({ dataDir: options.dataDir, version: reportableServerVersion(), relayOnly: options.relay === true });if (fleetCredential()) io.log(`note: ${FLEET_CREDENTIAL_ENV} is set, so serve --tunnel will use that credential rather than this account`);if (account.credentials.status === "unavailable") {io.error(`${account.credentials.file} exists but could not be read; fix or remove it, then try again`);@@ -553,7 +544,7 @@ export async function runLogin(options: CliOptions, io: CliIo = defaultIo()): Pr}export async function runLogout(options: CliOptions, io: CliIo = defaultIo()): Promise<number> {- const account = createTunnelAccount({ dataDir: options.dataDir, version: serverVersion() });+ const account = createTunnelAccount({ dataDir: options.dataDir, version: reportableServerVersion() });const before = describeTunnelAccount(account.credentials.read());if (!before.email) {io.log("this machine is not signed in");@@ -644,12 +635,12 @@ async function planTunnel(options: CliOptions, log: (line: string) => void, recoif (credential) {log(`tunnel: using the installation credential from ${FLEET_CREDENTIAL_ENV}`);try {- access = await fleetAccess({ credential, version: serverVersion() });+ access = await fleetAccess({ credential, version: reportableServerVersion() });} catch (error) {return { error: `--tunnel: ${message(error)}` };}} else {- account = createTunnelAccount({ dataDir: options.dataDir, version: serverVersion(), recovery, log: (line) => log(`tunnel: ${line}`) });+ account = createTunnelAccount({ dataDir: options.dataDir, version: reportableServerVersion(), recovery, log: (line) => log(`tunnel: ${line}`) });if (account.credentials.status === "unavailable") return fail(`${account.credentials.file} exists but could not be read; fix or remove it`);if (!describeTunnelAccount(account.credentials.read()).email) {return fail(`no account on this machine yet: run ${cliCommand("login")} first, then ${cliCommand("serve --tunnel")}`);@@ -957,7 +948,7 @@ export async function runOnboardingCommand(if (interactive && options.pair && !options.local && (options.command === "setup" || !saved)) {io.log("\nOne optional step: connect your phone. You can skip this and start chatting here.");const result = await (flow.phoneSetup ?? runPhoneSetup)(launch, prompts, {- accountReady: (value) => !!describeTunnelAccount(createTunnelAccount({ dataDir: value.dataDir, version: serverVersion() }).credentials.read()).email,+ accountReady: (value) => !!describeTunnelAccount(createTunnelAccount({ dataDir: value.dataDir, version: reportableServerVersion() }).credentials.read()).email,login: (value, ui) => runLogin(value, {log: ui.log, error: ui.log,ask: (question) => /code/i.test(question) ? ui.secret(question) : ui.ask(question),diff --git a/server/environment.test.ts b/server/environment.test.tsindex e7b18af9f1..fa436816f6 100644--- a/server/environment.test.ts+++ b/server/environment.test.ts@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, describe, expect, it } from "vitest";-import { environmentDescriptor, loadEnvironmentId, serverInstall, serverVersion } from "./environment.ts";+import { environmentDescriptor, loadEnvironmentId, reportableServerVersion, serverInstall, serverVersion } from "./environment.ts";const dirs: string[] = [];@@ -190,4 +190,23 @@ describe("environment identity", () => {expect(serverVersion(bundle)).toBe("0.1.120");delete process.env.OMB_APP_VERSION;});++ it("reads the version of the self-hosted image, which ships dist-server/package.json and no /app/package.json", () => {+ delete process.env.OMB_APP_VERSION;+ const app = mkdtempSync(join(tmpdir(), "omb-app-"));+ dirs.push(app);+ const bundle = join(app, "dist-server");+ mkdirSync(bundle);+ writeFileSync(join(bundle, "package.json"), '{"type":"module","version":"0.1.153"}\n');+ expect(existsSync(join(app, "package.json"))).toBe(false);+ expect(serverVersion(bundle)).toBe("0.1.153");+ expect(reportableServerVersion(serverVersion(bundle))).toBe("0.1.153");+ });++ it("reports only a release version to the control plane", () => {+ expect(reportableServerVersion("0.1.153")).toBe("0.1.153");+ expect(reportableServerVersion("0.2.0-beta.1")).toBe("0.2.0-beta.1");+ expect(reportableServerVersion("unknown")).toBeUndefined();+ expect(reportableServerVersion("")).toBeUndefined();+ });});diff --git a/server/environment.ts b/server/environment.tsindex abaf318e54..e8592fd48d 100644--- a/server/environment.ts+++ b/server/environment.ts@@ -146,6 +146,14 @@ export function serverVersion(root = SERVER_ROOT): string {return "unknown";}+const RELEASE_VERSION = /^\d+\.\d+\.\d+(?:[-+].*)?$/;++/** The version to tell the control plane, or none: it records what it is told, and stops serving a public address to a+ * version below its minimum, so a version this server could not read must not stand in for the release it runs. */+export function reportableServerVersion(version = serverVersion()): string | undefined {+ return RELEASE_VERSION.test(version) ? version : undefined;+}+export type ServerInstall = "npx" | "global" | "docker" | "source";/** How this server was started: the Docker image (OMB_CLI_PREFIX, or Docker's own /.dockerenv), a checkout, npx, or adiff --git a/server/tunnel.test.ts b/server/tunnel.test.tsindex e5195643d8..c56644142a 100644--- a/server/tunnel.test.ts+++ b/server/tunnel.test.ts@@ -201,6 +201,18 @@ describe("login and logout against the control plane", () => {expect(stub.calls).toContain("POST /api/auth/sign-out");});+ it("tells the control plane the release this server runs, and no version at all when it cannot read one", async () => {+ vi.stubEnv("OMB_APP_VERSION", "0.1.153");+ expect(await runLogin(options(dir, { email: "[email protected]" }), fakeIo([stub.otp]).io)).toBe(0);+ expect([...stub.installations.values()][0]?.appVersion).toBe("0.1.153");++ expect(await runLogout(options(dir, { command: "logout" }), fakeIo([]).io)).toBe(0);+ stub.installations.clear();+ vi.stubEnv("OMB_APP_VERSION", "unknown");+ expect(await runLogin(options(dir, { email: "[email protected]" }), fakeIo([stub.otp]).io)).toBe(0);+ expect([...stub.installations.values()][0]?.appVersion).toBeNull();+ });+it("a running serve --tunnel re-creates a reclaimed endpoint behind the same address and reconnects", async () => {expect(await runLogin(options(dir, { email: "[email protected]" }), fakeIo([stub.otp]).io)).toBe(0);const pending = new Map<number, () => void>();diff --git a/server/tunnel.ts b/server/tunnel.tsindex 79240a253b..f6cb2b5540 100644--- a/server/tunnel.ts+++ b/server/tunnel.ts@@ -128,7 +128,7 @@ const STOPPED_TUNNEL: ManagedTunnelState = { status: "stopped", ready: false };/** A server's operator owns its environment, so OMB_CONTROL_PLANE_URL is always honoured here (the desktop: dev builds only). */export function createTunnelAccount(options: {dataDir: string;- version: string;+ version: string | undefined;env?: NodeJS.ProcessEnv;fetchImpl?: typeof fetch;machineName?: string;