mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-12-02 02:33:10 +08:00
* feat: ship a Linux x64 AppImage OpenBot shipped macOS and Windows only. This adds the third target as an AppImage, the one Linux format electron-updater can update in place. - Pin `linux-x64` artifacts for codex, claude, opencode, and grok, so the in-app provider download works as it does on macOS. - Discover a CLI through `$SHELL` on Linux instead of `/bin/zsh`, which most distributions do not install, and look in `/usr/bin` as well. - Register the `openbot://` scheme on Linux, and update in place only when `APPIMAGE` says the app runs from an AppImage. - Report voice transcription as unavailable when the build carries no whisper binary, rather than failing at transcribe time. The composer offers no microphone on Linux. - Move the whisper and remote-desktop resources out of the shared `extraResources` list, because neither is built for Linux. - Ship an AppArmor profile for the Ubuntu 23.10 and Debian 13 user-namespace restriction. `--no-sandbox` stays out of the product and the documentation. - Add the release job, the package verifier, the download route, and the install and troubleshooting sections. Remote desktop stays unavailable on Linux, and the AppImage is unsigned, as the Windows installer is. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(linux): install a desktop entry and keep the sandbox on in CI The protocol registration on Linux goes through `xdg-settings`, which can only name a desktop entry that already exists. An AppImage has none, so the first start now writes `~/.local/share/applications/openbot.desktop` with an `Exec` that points at the running AppImage and accepts `%U`, and a failed registration is logged instead of ignored. Ubuntu 24.04 restricts unprivileged user namespaces through AppArmor, so the release job loads a narrow profile for the verification executable and gives the SUID helper the ownership a package manager would give it. `--no-sandbox` stays out of the tree: the launch check must prove what a real install does. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(linux): keep the launcher icon after the AppImage unmounts An AppImage mounts its resources in a temporary directory the runtime removes on exit, so a desktop entry that names the packaged icon loses it as soon as OpenBot is not running. The first start now copies the icon to `<data home>/icons` and names the copy. A copy that fails still leaves the entry, because the entry is what registers the invitation scheme. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
206 lines
8.7 KiB
TypeScript
206 lines
8.7 KiB
TypeScript
import { execFileSync } from "node:child_process";
|
|
import { cp, mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { createOpenBotLogger } from "@openbot/logging";
|
|
import { z } from "zod";
|
|
import { type AgentRuntimeLock, loadAgentRuntimeLock } from "./agent-runtime-lock";
|
|
import { rejectNonRegularFiles, sha256 } from "./remote-desktop-runtime-release";
|
|
|
|
const logger = createOpenBotLogger("install-codex-runtime");
|
|
|
|
export type CodexRuntimeTarget = "darwin-arm64" | "linux-x64" | "win32-x64";
|
|
|
|
const packageManifestSchema = z.object({
|
|
layoutVersion: z.literal(1),
|
|
version: z.string(),
|
|
target: z.enum(["aarch64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-musl"]),
|
|
variant: z.literal("codex"),
|
|
entrypoint: z.string(),
|
|
resourcesDir: z.literal("codex-resources"),
|
|
pathDir: z.literal("codex-path"),
|
|
});
|
|
|
|
export async function installCodexRuntime(
|
|
input: {
|
|
sourceRoot?: string;
|
|
outputRoot?: string;
|
|
target?: CodexRuntimeTarget;
|
|
fetchImpl?: typeof fetch;
|
|
lock?: AgentRuntimeLock;
|
|
} = {},
|
|
): Promise<"installed" | "current"> {
|
|
const sourceRoot = input.sourceRoot ?? process.cwd();
|
|
const outputRoot = input.outputRoot ?? resolve(sourceRoot, "build/codex");
|
|
const target = input.target ?? codexRuntimeTarget();
|
|
const fetchImpl = input.fetchImpl ?? fetch;
|
|
const lock = input.lock ?? (await loadAgentRuntimeLock(sourceRoot));
|
|
const artifact = lock.codex.artifacts[target];
|
|
const targetRoot = codexRuntimePath(outputRoot, target);
|
|
|
|
if (await isCurrentInstallation(targetRoot, target, lock)) {
|
|
await writeMetadata(outputRoot, lock, fetchImpl);
|
|
logger.info(`Using verified bundled Codex ${lock.codex.version} for ${target}.`);
|
|
return "current";
|
|
}
|
|
|
|
const response = await fetchImpl(
|
|
`${lock.codex.repository}/releases/download/${encodeURIComponent(lock.codex.tag)}/${artifact.asset}`,
|
|
{ headers: { "User-Agent": "OpenBot-runtime-installer" }, redirect: "follow" },
|
|
);
|
|
if (!response.ok) throw new Error(`Codex runtime download failed with HTTP ${response.status}.`);
|
|
const archiveBytes = Buffer.from(await response.arrayBuffer());
|
|
if (sha256(archiveBytes) !== artifact.assetSha256) {
|
|
throw new Error(`The ${target} Codex runtime archive checksum is invalid.`);
|
|
}
|
|
|
|
const temporaryRoot = await mkdtemp(join(tmpdir(), "openbot-codex-install-"));
|
|
try {
|
|
const archive = join(temporaryRoot, artifact.asset);
|
|
const extracted = join(temporaryRoot, "extracted");
|
|
await writeFile(archive, archiveBytes, { mode: 0o600 });
|
|
validateCodexArchive(archive);
|
|
await mkdir(extracted, { recursive: true });
|
|
execFileSync("tar", ["-xzf", archive, "-C", extracted, "--no-same-owner"], { stdio: "inherit" });
|
|
await rejectNonRegularFiles(extracted);
|
|
await verifyCodexRuntime(extracted, target, lock);
|
|
await installValidatedTree(extracted, targetRoot);
|
|
await verifyCodexRuntime(targetRoot, target, lock);
|
|
} finally {
|
|
await rm(temporaryRoot, { recursive: true, force: true });
|
|
}
|
|
|
|
await writeMetadata(outputRoot, lock, fetchImpl);
|
|
logger.info(`Installed bundled Codex ${lock.codex.version} for ${target}.`);
|
|
return "installed";
|
|
}
|
|
|
|
/** The `target` the Codex package manifest carries for each runtime target OpenBot ships. */
|
|
const CODEX_MANIFEST_TARGETS = {
|
|
"darwin-arm64": "aarch64-apple-darwin",
|
|
"linux-x64": "x86_64-unknown-linux-musl",
|
|
"win32-x64": "x86_64-pc-windows-msvc",
|
|
} as const satisfies Record<CodexRuntimeTarget, string>;
|
|
|
|
export function codexRuntimeTarget(
|
|
platform: string = process.platform,
|
|
architecture: string = process.arch,
|
|
): CodexRuntimeTarget {
|
|
const target = `${platform}-${architecture}`;
|
|
if (target === "darwin-arm64" || target === "linux-x64" || target === "win32-x64") return target;
|
|
throw new Error(`Unsupported bundled Codex target: ${target}`);
|
|
}
|
|
|
|
export function codexRuntimePath(root: string, target: CodexRuntimeTarget): string {
|
|
if (target === "darwin-arm64") return join(root, "mac", "arm64");
|
|
if (target === "linux-x64") return join(root, "linux", "x64");
|
|
return join(root, "win", "x64");
|
|
}
|
|
|
|
export async function verifyCodexRuntime(
|
|
root: string,
|
|
target: CodexRuntimeTarget,
|
|
lock: AgentRuntimeLock,
|
|
): Promise<void> {
|
|
const artifact = lock.codex.artifacts[target];
|
|
const manifest = packageManifestSchema.parse(JSON.parse(await readFile(join(root, "codex-package.json"), "utf8")));
|
|
const expectedTarget = CODEX_MANIFEST_TARGETS[target];
|
|
if (
|
|
manifest.version !== lock.codex.version ||
|
|
manifest.target !== expectedTarget ||
|
|
manifest.entrypoint !== artifact.executable
|
|
) {
|
|
throw new Error("The bundled Codex package manifest does not match the runtime lock.");
|
|
}
|
|
const executable = join(root, ...artifact.executable.split("/"));
|
|
const output = execFileSync(executable, ["--version"], { encoding: "utf8", windowsHide: true }).trim();
|
|
if (!new RegExp(`(?:codex-cli\\s+)?${escapeRegExp(lock.codex.version)}(?:\\s|$)`, "u").test(output)) {
|
|
throw new Error(`Unexpected bundled Codex version: ${output}`);
|
|
}
|
|
await readFile(join(root, "bin", target === "win32-x64" ? "codex-code-mode-host.exe" : "codex-code-mode-host"));
|
|
await readFile(join(root, "codex-path", target === "win32-x64" ? "rg.exe" : "rg"));
|
|
}
|
|
|
|
export function validateCodexArchive(archive: string): string[] {
|
|
const names = execFileSync("tar", ["-tzf", archive], { encoding: "utf8" }).split(/\r?\n/u).filter(Boolean);
|
|
const details = execFileSync("tar", ["-tvzf", archive], { encoding: "utf8" }).split(/\r?\n/u).filter(Boolean);
|
|
if (details.some((line) => !["-", "d"].includes(line.trimStart().charAt(0)))) {
|
|
throw new Error("The Codex runtime archive contains a link or a special file.");
|
|
}
|
|
for (const name of names) validateArchivePath(name);
|
|
if (!names.includes("codex-package.json") || !names.some((name) => /^bin\/codex(?:\.exe)?$/u.test(name))) {
|
|
throw new Error("The Codex runtime archive is incomplete.");
|
|
}
|
|
return names;
|
|
}
|
|
|
|
function validateArchivePath(name: string): void {
|
|
if (name.includes("\0") || name.includes("\\")) throw new Error(`Unsafe Codex archive path: ${name}`);
|
|
const normalized = name.replace(/\/+$/u, "");
|
|
if (!normalized || normalized.startsWith("/") || /^[A-Za-z]:/u.test(normalized)) {
|
|
throw new Error(`Unsafe Codex archive path: ${name}`);
|
|
}
|
|
const parts = normalized.split("/");
|
|
if (parts.some((part) => !part || part === "." || part === "..")) {
|
|
throw new Error(`Unsafe Codex archive path: ${name}`);
|
|
}
|
|
if (!["bin", "codex-package.json", "codex-path", "codex-resources"].includes(parts[0] ?? "")) {
|
|
throw new Error(`Unexpected Codex archive path: ${name}`);
|
|
}
|
|
}
|
|
|
|
async function isCurrentInstallation(
|
|
root: string,
|
|
target: CodexRuntimeTarget,
|
|
lock: AgentRuntimeLock,
|
|
): Promise<boolean> {
|
|
try {
|
|
await verifyCodexRuntime(root, target, lock);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function installValidatedTree(source: string, destination: string): Promise<void> {
|
|
const temporaryTarget = join(dirname(destination), `.${destination.split(/[\\/]/u).at(-1)}.installing`);
|
|
await mkdir(dirname(destination), { recursive: true });
|
|
await rm(temporaryTarget, { recursive: true, force: true });
|
|
await cp(source, temporaryTarget, { recursive: true });
|
|
await rm(destination, { recursive: true, force: true });
|
|
await rename(temporaryTarget, destination);
|
|
}
|
|
|
|
async function writeMetadata(root: string, lock: AgentRuntimeLock, fetchImpl: typeof fetch): Promise<void> {
|
|
const licenseRoot = join(root, "licenses");
|
|
const licensePath = join(licenseRoot, "Codex-Apache-2.0.txt");
|
|
await mkdir(licenseRoot, { recursive: true });
|
|
let currentLicense: string | null = null;
|
|
try {
|
|
currentLicense = sha256(await readFile(licensePath));
|
|
} catch {
|
|
// Download the pinned license below.
|
|
}
|
|
if (currentLicense !== lock.codex.licenseSha256) {
|
|
const response = await fetchImpl(`${lock.codex.repository}/raw/${encodeURIComponent(lock.codex.tag)}/LICENSE`, {
|
|
headers: { "User-Agent": "OpenBot-runtime-installer" },
|
|
redirect: "follow",
|
|
});
|
|
if (!response.ok) throw new Error(`Codex license download failed with HTTP ${response.status}.`);
|
|
const bytes = Buffer.from(await response.arrayBuffer());
|
|
if (sha256(bytes) !== lock.codex.licenseSha256) throw new Error("The Codex license checksum is invalid.");
|
|
await writeFile(licensePath, bytes);
|
|
}
|
|
await writeFile(join(root, "source-manifest.json"), `${JSON.stringify({ name: "codex", ...lock.codex }, null, 2)}\n`);
|
|
}
|
|
|
|
function escapeRegExp(value: string): string {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
await installCodexRuntime({
|
|
target: codexRuntimeTarget(process.argv[2] ?? process.platform, process.argv[3] ?? process.arch),
|
|
});
|
|
}
|