Files
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

397 lines
14 KiB
TypeScript

// copyright, which gives more than the license, and it continues to apply to the contributions of
import { execFileSync } from "node:child_process";
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname } from "node:path";
const TRUSTED_ASSOCIATIONS = new Set(["OWNER", "MEMBER"]);
const TRUSTED_PERMISSIONS = new Set(["admin", "maintain", "write"]);
const AGREEMENT_PATH = "CLA.md";
const AGREEMENT_NAME = "OpenBot Contributor License Agreement";
const EARLIER_ACCEPTED_VERSIONS = ["1.0"];
const CLA_PAGE_URL = "https://openbot.run/cla";
const LICENSES_EMAIL = "licenses@openbot.run";
const SIGNATURES_BRANCH = "cla-signatures";
const SIGNATURES_FILE = "signatures.json";
const STATUS_CONTEXT = "CLA";
const COMMENT_MARKER = "<!-- cla -->";
const COMMENT_AUTHOR = "github-actions[bot]";
const MAX_COMMITS = 250;
const SAVE_ATTEMPTS = 3;
const REPORT_PATH = ".openbot-build/cla/report.json";
const args = process.argv.slice(2);
const dryRun = args.includes("--dry-run");
const [command, ...positional] = args.filter((arg) => !arg.startsWith("--"));
const repository =
process.env.GITHUB_REPOSITORY || gh(["repo", "view", "--json", "nameWithOwner", "--jq", ".nameWithOwner"]);
const writes: string[] = [];
function fail(message: string): never {
process.stderr.write(`${message}\n`);
process.exit(1);
}
function gh(ghArgs: readonly string[], input?: string): string {
return execFileSync("gh", ghArgs, {
encoding: "utf8",
input,
stdio: ["pipe", "pipe", "pipe"],
maxBuffer: 64 * 1024 * 1024,
}).replace(/\n+$/, "");
}
function read(path: string, jq: string): string {
return gh(["api", path, "--jq", jq]);
}
function readLines(path: string, jq: string): string[] {
return gh(["api", "--paginate", path, "--jq", jq])
.split("\n")
.filter((line) => line !== "");
}
function failedWith(error: unknown, statuses: readonly number[]): boolean {
const stderr = error instanceof Error && "stderr" in error ? String(error.stderr) : "";
return statuses.some((status) => stderr.includes(`HTTP ${status}`));
}
function column(values: readonly string[], index: number): string {
const value = values[index];
if (value === undefined) fail(`Unexpected value from GitHub: ${values.join("\t")}`);
return value;
}
function isTrusted(login: string, association: string): boolean {
if (TRUSTED_ASSOCIATIONS.has(association)) return true;
try {
return TRUSTED_PERMISSIONS.has(read(`repos/${repository}/collaborators/${login}/permission`, ".permission"));
} catch {
return false;
}
}
function write(description: string, ghArgs: readonly string[], input?: string): void {
writes.push(description);
if (!dryRun) gh(ghArgs, input);
}
function parseNumber(value: string | undefined): number {
const number = Number(value);
if (!Number.isSafeInteger(number) || number <= 0) fail(`Expected a pull request number, got "${value}".`);
return number;
}
function loadAgreement(): string {
const text = readFileSync(AGREEMENT_PATH, "utf8");
if (!text.startsWith(`# ${AGREEMENT_NAME}\n`)) fail(`${AGREEMENT_PATH} is not the ${AGREEMENT_NAME}.`);
const version = /^Version: (\S+)$/m.exec(text)?.[1];
if (version === undefined) fail(`${AGREEMENT_PATH} has no "Version:" line.`);
return version;
}
interface Person {
readonly login: string;
readonly id: number;
}
interface Signature {
readonly login: string;
readonly userId: number;
readonly version: string;
readonly signedAt: string;
readonly pullRequest: number;
readonly method: "checkbox" | "comment" | "email";
readonly url: string;
readonly text: string;
}
interface SignatureStore {
readonly signatures: readonly Signature[];
readonly sha: string | undefined;
readonly branchExists: boolean;
}
function loadStore(): SignatureStore {
try {
const row = read(
`repos/${repository}/contents/${SIGNATURES_FILE}?ref=${SIGNATURES_BRANCH}`,
'[.sha, (.content | gsub("\\n"; ""))] | @tsv',
).split("\t");
const parsed: { signatures: Signature[] } = JSON.parse(Buffer.from(column(row, 1), "base64").toString("utf8"));
return { signatures: parsed.signatures, sha: column(row, 0), branchExists: true };
} catch (error) {
if (!failedWith(error, [404])) throw error;
}
try {
read(`repos/${repository}/git/ref/heads/${SIGNATURES_BRANCH}`, ".object.sha");
return { signatures: [], sha: undefined, branchExists: true };
} catch (error) {
if (!failedWith(error, [404])) throw error;
return { signatures: [], sha: undefined, branchExists: false };
}
}
function hasSigned(signatures: readonly Signature[], id: number, version: string): boolean {
return signatures.some(
(signature) =>
signature.userId === id &&
(signature.version === version || EARLIER_ACCEPTED_VERSIONS.includes(signature.version)),
);
}
function saveStore(store: SignatureStore, signatures: readonly Signature[], message: string): void {
const content = `${JSON.stringify({ signatures }, null, 2)}\n`;
if (!store.branchExists) {
const tree = gh(
["api", "-X", "POST", `repos/${repository}/git/trees`, "--input", "-", "--jq", ".sha"],
JSON.stringify({ tree: [{ path: SIGNATURES_FILE, mode: "100644", type: "blob", content }] }),
);
const commit = gh(
["api", "-X", "POST", `repos/${repository}/git/commits`, "--input", "-", "--jq", ".sha"],
JSON.stringify({ message, tree, parents: [] }),
);
gh(
["api", "-X", "POST", `repos/${repository}/git/refs`, "--input", "-"],
JSON.stringify({ ref: `refs/heads/${SIGNATURES_BRANCH}`, sha: commit }),
);
return;
}
gh(
["api", "-X", "PUT", `repos/${repository}/contents/${SIGNATURES_FILE}`, "--input", "-"],
JSON.stringify({
message,
branch: SIGNATURES_BRANCH,
content: Buffer.from(content).toString("base64"),
...(store.sha === undefined ? {} : { sha: store.sha }),
}),
);
}
function recordSignatures(added: readonly Signature[], version: string): void {
const message = `Record CLA ${version} signatures: ${added.map((signature) => signature.login).join(", ")}`;
writes.push(`${message}\n${added.map((signature) => signature.url).join("\n")}`);
if (dryRun) return;
for (let attempt = 1; ; attempt += 1) {
const store = loadStore();
const missing = added.filter((signature) => !hasSigned(store.signatures, signature.userId, version));
if (missing.length === 0) return;
try {
saveStore(store, [...store.signatures, ...missing], message);
return;
} catch (error) {
if (attempt === SAVE_ATTEMPTS || !failedWith(error, [409, 422])) throw error;
}
}
}
interface PullRequest {
readonly number: number;
readonly author: Person;
readonly authorIsBot: boolean;
readonly association: string;
readonly sha: string;
readonly state: string;
readonly commits: number;
readonly url: string;
}
function loadPullRequest(number: number): PullRequest {
const row = read(
`repos/${repository}/pulls/${number}`,
"[.user.login, .user.id, .user.type, .author_association, .head.sha, .state, .commits, .html_url] | @tsv",
).split("\t");
return {
number,
author: { login: column(row, 0), id: Number(column(row, 1)) },
authorIsBot: column(row, 2) === "Bot",
association: column(row, 3),
sha: column(row, 4),
state: column(row, 5),
commits: Number(column(row, 6)),
url: column(row, 7),
};
}
function requiredSigners(pr: PullRequest): { readonly signers: Person[]; readonly unlinked: string[] } {
const people = new Map<number, Person>();
const unlinked: string[] = [];
if (!pr.authorIsBot) people.set(pr.author.id, pr.author);
const rows = readLines(
`repos/${repository}/pulls/${pr.number}/commits?per_page=100`,
'.[] | [(.author.login // ""), (.author.id // 0 | tostring), (.author.type // ""), .sha] | @tsv',
).map((line) => line.split("\t"));
for (const row of rows) {
const login = column(row, 0);
if (login === "") unlinked.push(column(row, 3).slice(0, 12));
else if (column(row, 2) !== "Bot") people.set(Number(column(row, 1)), { login, id: Number(column(row, 1)) });
}
const signers = [...people.values()].filter(
(person) => !isTrusted(person.login, person.id === pr.author.id ? pr.association : ""),
);
return { signers, unlinked };
}
function upsertStickyComment(number: number, body: string, createIfMissing: boolean): void {
const text = `${COMMENT_MARKER}\n${body}`;
const [existing] = readLines(
`repos/${repository}/issues/${number}/comments?per_page=100`,
`.[] | select(.user.login == "${COMMENT_AUTHOR}" and (.body | contains("${COMMENT_MARKER}"))) | .id`,
);
if (existing !== undefined) {
write(
`edit CLA comment on #${number}:\n${body}`,
["api", "-X", "PATCH", `repos/${repository}/issues/comments/${existing}`, "-F", "body=@-"],
text,
);
} else if (createIfMissing) {
write(
`comment on #${number}:\n${body}`,
["api", "-X", "POST", `repos/${repository}/issues/${number}/comments`, "-F", "body=@-"],
text,
);
}
}
function setStatus(sha: string, state: "success" | "failure", description: string): void {
write(`status ${state} on ${sha.slice(0, 12)}: ${description}`, [
"api",
"-X",
"POST",
`repos/${repository}/statuses/${sha}`,
"-f",
`state=${state}`,
"-f",
`context=${STATUS_CONTEXT}`,
"-f",
`description=${description}`,
"-f",
`target_url=${CLA_PAGE_URL}`,
]);
}
function requestComment(pr: PullRequest, unsigned: readonly Person[], unlinked: readonly string[]): string {
const lines: string[] = [];
if (unsigned.length > 0) {
lines.push(
`${unsigned.map((person) => `@${person.login}`).join(", ")}, thank you for the contribution. Before we can merge it, each author from outside the organization must sign the [${AGREEMENT_NAME}](${CLA_PAGE_URL}). With the agreement, you keep the copyright in your contributions and give OpenBot a license to use them.`,
"",
`To sign, download the agreement as a PDF from [openbot.run/cla](${CLA_PAGE_URL}). Fill it in, sign it, and send it to ${LICENSES_EMAIL}. In the email, write your GitHub login and the link to this pull request: ${pr.url}`,
"",
"A maintainer records your signature, and then this check runs again. You sign one time. The signature applies to all your contributions to OpenBot.",
);
}
if (unlinked.length > 0) {
if (lines.length > 0) lines.push("");
lines.push(
`The author email of these commits is not linked to a GitHub account, so we cannot find who must sign: ${unlinked.map((sha) => `\`${sha}\``).join(", ")}. Add the email to your GitHub account, or change the commit author and push again.`,
);
}
return lines.join("\n");
}
interface Decision {
readonly number: number;
readonly state: string;
readonly signers: readonly string[];
readonly unsigned: readonly string[];
readonly unlinked: readonly string[];
readonly result: "skipped" | "pass" | "fail";
readonly reason: string;
}
function checkPullRequest(number: number): Decision {
const version = loadAgreement();
const pr = loadPullRequest(number);
if (pr.state !== "open") {
return {
number,
state: pr.state,
signers: [],
unsigned: [],
unlinked: [],
result: "skipped",
reason: `pull request is ${pr.state}`,
};
}
const { signers, unlinked } = requiredSigners(pr);
const store = loadStore();
const unsigned = signers.filter((person) => !hasSigned(store.signatures, person.id, version));
const tooManyCommits = pr.commits > MAX_COMMITS;
const passed = unsigned.length === 0 && unlinked.length === 0 && !tooManyCommits;
const reason = tooManyCommits
? `More than ${MAX_COMMITS} commits. Squash the commits so that the authors can be checked.`
: unsigned.length > 0
? `Not signed by ${unsigned.map((person) => person.login).join(", ")}.`
: unlinked.length > 0
? "A commit author has no GitHub account."
: signers.length === 0
? "No author must sign."
: "All authors signed.";
setStatus(pr.sha, passed ? "success" : "failure", reason.slice(0, 140));
if (passed) {
upsertStickyComment(number, "All authors signed the agreement. The CLA check passes.", false);
} else if (tooManyCommits) {
upsertStickyComment(number, reason, true);
} else {
upsertStickyComment(number, requestComment(pr, unsigned, unlinked), true);
}
return {
number,
state: pr.state,
signers: signers.map((person) => person.login),
unsigned: unsigned.map((person) => person.login),
unlinked,
result: passed ? "pass" : "fail",
reason,
};
}
function recordEmailSignature(login: string, number: number): string {
const version = loadAgreement();
const user = read(`users/${login}`, "[.login, .id, .type] | @tsv").split("\t");
if (column(user, 2) !== "User") fail(`${login} is not a GitHub user.`);
const pr = loadPullRequest(number);
recordSignatures(
[
{
login: column(user, 0),
userId: Number(column(user, 1)),
version,
signedAt: new Date().toISOString(),
pullRequest: number,
method: "email",
url: pr.url,
text: `Signed PDF of the ${AGREEMENT_NAME} ${version}, sent to ${LICENSES_EMAIL}.`,
},
],
version,
);
return column(user, 0);
}
let recorded: string | undefined;
let decision: Decision;
if (command === "pr" && positional.length === 1) {
decision = checkPullRequest(parseNumber(positional[0]));
} else if (command === "record" && positional.length === 2 && positional[0] !== undefined) {
const number = parseNumber(positional[1]);
recorded = recordEmailSignature(positional[0], number);
decision = checkPullRequest(number);
} else {
fail(
"Usage: bun scripts/cla.ts pr <number> [--dry-run]\n bun scripts/cla.ts record <login> <number> [--dry-run]",
);
}
const report = { repository, command, dryRun, recorded, decision, writes };
if (dryRun) {
mkdirSync(dirname(REPORT_PATH), { recursive: true });
writeFileSync(REPORT_PATH, `${JSON.stringify(report, null, 2)}\n`);
}
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);