Files
openbot/scripts/runtime-install.ts
Aleksander DygońandClaude Opus 5.5 03c2ff34c2 Remove code comments and add the no-comments rule (#12604)
* Remove code comments and add the no-comments rule

Remove the comments from first-party code and configuration files:
TS/JS, JSX, CSS, SQL migrations, Swift, Kotlin, Gradle, shell,
Docker, systemd, Nix, YAML, TOML, JSONC and GritQL.

Keep only what a tool reads: license headers, shebangs, compiler
and lint directives, JSDoc types in plain .js files, generated file
headers, GritQL scope lines, the install-server.sh help text and the
openbot-boat-pre-stop marker. Vendored code, fixtures and released
schemas keep their comments.

Add the rule to AGENTS.md, and change the docs that asked for
comments. Add two i18n keys that only comments named to
RELEASED_SOURCE_KEYS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep comments that are data in strings

The benchmark task files in opencode-free-models-bench.ts tell the
model what each function must do. The sample file and HTML page in
the two stories are display content. Put their comments back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep released migrations and mobile native inputs unchanged

check:migrations compares each released migration with v0.73.0 byte
for byte, so restore src/backend/migrations. A change to a native
build input of apps/mobile makes a new runtime version, so restore
those files and the extra fingerprint sources.

List these files and the comment markers that a tool reads in
AGENTS.md. Remove the last requests for comments in
src/renderer/AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 12:19:28 +01:00

66 lines
2.5 KiB
TypeScript

import { cp, mkdir, rename, rm } from "node:fs/promises";
import { dirname, join } from "node:path";
import { createOpenBotLogger } from "@openbot/logging";
const logger = createOpenBotLogger("runtime-install");
export async function isCurrentInstallation(verify: () => Promise<void>): Promise<boolean> {
try {
await verify();
return true;
} catch {
return false;
}
}
export async function download(fetchImpl: typeof fetch, url: string, label: string): Promise<Buffer> {
const attempts = 3;
for (let attempt = 1; ; attempt += 1) {
let response: Response | undefined;
let failure: unknown;
try {
response = await fetchImpl(url, {
headers: { "User-Agent": "OpenBot-runtime-installer" },
redirect: "follow",
});
if (response.ok) return Buffer.from(await response.arrayBuffer());
} catch (error) {
failure = error;
}
if (response && !response.ok) {
failure = new Error(`${label} download failed with HTTP ${response.status}.`);
if (response.status !== 429 && response.status < 500) throw failure;
await response.body?.cancel();
}
if (attempt === attempts) throw failure;
logger.warn(`${label} download failed (attempt ${attempt} of ${attempts}): ${String(failure)}`);
await new Promise((resolveDelay) => setTimeout(resolveDelay, attempt * 5_000));
}
}
export function safeArchivePathParts(name: string, label: string): string[] {
if (name.includes("\0") || name.includes("\\")) throw new Error(`Unsafe ${label} archive path: ${name}`);
const normalized = name.replace(/\/+$/u, "");
if (!normalized || normalized.startsWith("/") || /^[A-Za-z]:/u.test(normalized)) {
throw new Error(`Unsafe ${label} archive path: ${name}`);
}
const parts = normalized.split("/");
if (parts.some((part) => !part || part === "." || part === "..")) {
throw new Error(`Unsafe ${label} archive path: ${name}`);
}
return parts;
}
export 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);
}
export function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
}