From 6353dfb26fa07246df44caf822e65a6b5cb8be1a Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 7 Nov 2026 07:40:27 -0800 Subject: [PATCH 1/8] Generate the Central CodeRabbit and Qodo Settings From the Hub Add scripts/central_config.py, which writes the two account-wide bot settings repositories from the hub. Each README is a hand-authored source under repo-config/central/, and the config file text is a constant rendered by the script, so no generated tree is committed. A central file with automatic review off silences the bot on every repository that lacks its own file, which happened once to CodeRabbit. So the config file is written only while every live registry repository under the owner carries its own file on its default branch, setting the same key to a bool, and is removed when that stops holding. The precondition, write and check subcommands share that gate. Document the section in docs/repo-config.md and point to it from the reviewer reference. Co-Authored-By: Claude Sonnet 5.5 --- docs/pr-reviewer-reference.md | 5 + docs/repo-config.md | 20 + repo-config/central/coderabbit/README.md | 39 ++ .../central/pr-agent-settings/README.md | 39 ++ scripts/central_config.py | 324 ++++++++++++++++ tests/test_central_config.py | 353 ++++++++++++++++++ tests/test_cli_usage.py | 7 + 7 files changed, 787 insertions(+) create mode 100644 repo-config/central/coderabbit/README.md create mode 100644 repo-config/central/pr-agent-settings/README.md create mode 100755 scripts/central_config.py create mode 100755 tests/test_central_config.py diff --git a/docs/pr-reviewer-reference.md b/docs/pr-reviewer-reference.md index ed5ff3b29..1710eeb97 100644 --- a/docs/pr-reviewer-reference.md +++ b/docs/pr-reviewer-reference.md @@ -77,6 +77,7 @@ Each reviewer's behavior is shaped by a committed file rather than accepted as g - **CodeRabbit** is configured in `.coderabbit.yaml`, whose [settings reference][coderabbit-config] names each option. Its automatic review is off, since this repository's review policy has `wait` ask CodeRabbit explicitly instead. The file still lists `develop` as a base, the setting that governs where a repository left on automatic review is reviewed. No pause follows five reviewed commits, since a fleet pull request routinely passes five pushes and the pause reads as a reviewer that stopped. A path instruction for Markdown asks for false, stale, unverifiable, or unfollowable claims only. That is because CI lints style and the local review pass reads canonical prose whole. Sequence diagrams, suggested labels and reviewers, and the in-progress fortune are off. The markdownlint, actionlint, shellcheck, and ruff tools are off, since CI runs the same four and fails the pull request on them. - **Qodo** is configured in `.pr_agent.toml`, whose [configuration reference][qodo-config] names each option. An issues guideline asks for a reproduction with any claimed crash. That guideline came after a claimed `IsADirectoryError` on this repository's build was disproven by running it. A compliance guideline asks for the rule's own sentence and routes a rule against unchanged text to the summary. Informational findings go to the [summary][qodo-verbosity] rather than a thread, since a thread blocks the merge until resolved. Images are off so a finding's title is plain text a matcher can see. Qodo's [review standards][qodo-rules] import from `AGENTS.md`, `CLAUDE.md`, `copilot-instructions.md`, and `SKILL.md` files when changes merge. Each is scoped to its folder at any depth. Only new rules are added, so an edited or deleted rule is changed in its portal instead. This repository sits below Qodo's star gate and gets no automatic Qodo review. - **Which reviewer runs, and when**, is the repository's review policy, the `review` section of `.github/agent-policy.json`, or the hub default `spec/agent-policy.default.json` where it states none. `scripts/README.md` "`pr_review.py`" describes how `wait` applies it. A bot's own automatic trigger is a setting the policy does not read. `repo-config/configure.sh apply --checkout` derives it from the policy rendered from the registry. That covers Copilot's ruleset rule, CodeRabbit, and Qodo. A repository's `.coderabbit.yaml` replaces CodeRabbit's central and UI settings rather than merging with them, unless it sets `inheritance: true`. So the rendered file sets `auto_pause_after_reviewed_commits` to `0` itself, or CodeRabbit's default pause after five reviewed commits applies. `auto` says only that the bot may start on its own. `explicit` assumes it does not, so turn the bot's own trigger off before moving it to `explicit`. Otherwise it reviews twice. For Copilot, `wait` also notes any request already pending when it starts. That includes one an earlier `wait` sent, so the note points at a trigger left on only where no session sent the request. +- **Central settings**: the account-wide `coderabbit` and `pr-agent-settings` repositories turn automatic review off, and only while every fleet repository carries its own file. [Repository Configuration "Central Bot Settings"][repo-config-central] describes the gate. - **GitHub Copilot**: the carried `.github/copilot-instructions.md`, which bootstraps the `fleet-code-review` Skill, is the lever this repository uses. GitHub also documents path-scoped `.github/instructions/*.instructions.md` files, unused here. ## Plan and Repository Scope @@ -96,6 +97,10 @@ Private repositories remain Copilot-only unless a candidate's approved plan, dat [pr-892]: https://github.com/ptr727/ProjectTemplate/pull/892 [stall-issue]: https://github.com/ptr727/ProjectTemplate/issues/1741 + + +[repo-config-central]: repo-config.md#central-bot-settings + [coderabbit-auto-review]: https://docs.coderabbit.ai/configuration/auto-review diff --git a/docs/repo-config.md b/docs/repo-config.md index cdb734d5e..9822a814a 100644 --- a/docs/repo-config.md +++ b/docs/repo-config.md @@ -34,6 +34,26 @@ repo-config/configure.sh apply owner/repo release|operational Then validate the result with `repo-config/configure.sh check owner/repo release|operational`, run from the same checkout. The command asserts every applied ruleset, setting, label, security feature, and the fleet project link, plus the deployment environments described below. It exits non-zero on drift (the settings checks are driven by the committed payloads, and the ruleset checks by the payloads composed for the repo). Or import each ruleset by hand from the payloads `configure.sh` composes for the repo. Write them with `uv run --no-project --script scripts/agent_policy.py rulesets --registry registry/repos.json --name --model --out-dir `. Then run `gh api -X POST repos///rulesets --input /.json` for each of `develop` and `main`. `gh ruleset` is read-only, so creation goes through `gh api`. [`repo-config/README.md` "Rulesets"][repo-config-readme-rulesets] says what the composition changes. The required check binds by name and only turns green after the repo's PR workflow runs once. To edit a live ruleset, GET it, change the field, and PUT the whole writable subset back (a partial PUT `422`s). +## Central Bot Settings + +CodeRabbit reads a repository named `coderabbit` under the owner as central configuration, and Qodo reads `pr-agent-settings`. Each holds a README and one config file that turns automatic review off account-wide. A repository carrying its own `.coderabbit.yaml` or `.pr_agent.toml` uses that file instead. + +`scripts/central_config.py` writes both repositories from the hub. The READMEs are hand-authored sources under `repo-config/central/`, and the config text is a constant in the script. The two settings repositories are not registry entries. + +A central file with automatic review off silences the bot on every repository that lacks its own file. So the config file exists only while every live registry repository under the owner carries its own file. That file sits on its default branch and sets the same key to a bool. That key is `reviews.auto_review.enabled` for CodeRabbit and `config.disable_auto_feedback` for Qodo. An earlier central file without this gate silenced CodeRabbit on the repositories that had no file of their own yet. + +- `precondition` prints `ok` or `FAIL` per repository. It exits 0 when the gate holds, 1 when it does not, and 2 when a read could not run. +- `write` puts the README, and the config file only while the gate holds, into a checkout. It removes a config file the gate no longer allows and prints a `withheld` line naming the repositories that lack their own file. It never stages or commits, and `--dry-run` writes nothing. +- `check` reads the settings repository at a ref, `main` by default, and reports drift from what `write` produces. A config file present while the gate fails is drift. + +```sh +uv run --no-project --script scripts/central_config.py precondition --repo ptr727/coderabbit --registry registry/repos.json +uv run --no-project --script scripts/central_config.py write --repo ptr727/coderabbit --registry registry/repos.json --checkout +uv run --no-project --script scripts/central_config.py check --repo ptr727/pr-agent-settings --registry registry/repos.json --ref main +``` + +Carrying the result into a settings repository is a pull request there, and it needs the maintainer's go-ahead. + ## Deployment Environments `check` asserts that every environment the registry entry's `environments` declares exists and carries the declared deployment-branch policy, and `apply` writes none. The asymmetry is deliberate. An environment's secrets and variables are credentials that exist nowhere in the hub. So an `apply` could create the environment and set its policy and still leave it unable to publish, while reporting success. Their names are enumerable through the API, and their values in the case of a variable. But no tool here queries those stores. That is a choice about what this script owns rather than a limit the API imposes. The policy is checkable on its own and worth checking, because it decides which refs may deploy at all. On an OIDC publish that is half the gate: a ref the policy excludes mints no token. diff --git a/repo-config/central/coderabbit/README.md b/repo-config/central/coderabbit/README.md new file mode 100644 index 000000000..b7c5d5339 --- /dev/null +++ b/repo-config/central/coderabbit/README.md @@ -0,0 +1,39 @@ +# coderabbit + +CodeRabbit's organization-wide configuration for the `ptr727` repositories. + +## Purpose + +[CodeRabbit][coderabbit-link] reads a repository named `coderabbit` under an organization or account as that owner's central configuration. A repository that carries no `.coderabbit.yaml` of its own uses the `.coderabbit.yaml` here. A repository that carries one uses its own file instead. + +A fleet repository chooses which reviewers run, on which branches, and when, in its own `.github/agent-policy.json`. That file is rendered from the [ProjectTemplate][projecttemplate-link] registry, together with the repository's `.coderabbit.yaml` and `.pr_agent.toml`. So the default here covers only a repository that has not received its rendered files yet. It turns automatic review off, so it starts no review nobody asked for. + +## Status + +A central default with automatic review off silences CodeRabbit on every repository that lacks its own file. So `.coderabbit.yaml` is present here only while every fleet repository carries its own `.coderabbit.yaml` on its default branch, setting `reviews.auto_review.enabled`. [`scripts/central_config.py`][central-config-link] `write` adds the file when that holds and removes it when it does not. + +## Where the Rules Live + +This repository holds configuration only. The rules it serves live in ProjectTemplate: + +- [Pull Request Reviewer Reference][reviewer-reference-link] describes each reviewer bot and how its configuration is committed. Its "Review Configuration" section covers the review policy. +- [`spec/agent-policy.schema.json`][agent-policy-schema-link] defines the policy file, and [`spec/agent-policy.default.json`][agent-policy-default-link] is the default a repository inherits where its own file states none. +- [`GOVERNANCE.md`][governance-link] "PR Review Etiquette" governs how a review is requested, triaged, and resolved. +- [Repository Configuration][repo-config-link] describes `repo-config/configure.sh`, which applies each repository's bot settings. + +## Changing the Configuration + +ProjectTemplate writes this repository with [`scripts/central_config.py`][central-config-link]. Make a change there and carry it here by a pull request. Never edit this repository in place. The [settings reference][coderabbit-config-link] names each option. + + +[coderabbit-config-link]: https://docs.coderabbit.ai/reference/configuration +[coderabbit-link]: https://www.coderabbit.ai +[projecttemplate-link]: https://github.com/ptr727/ProjectTemplate + + +[agent-policy-default-link]: https://github.com/ptr727/ProjectTemplate/blob/main/spec/agent-policy.default.json +[agent-policy-schema-link]: https://github.com/ptr727/ProjectTemplate/blob/main/spec/agent-policy.schema.json +[central-config-link]: https://github.com/ptr727/ProjectTemplate/blob/main/scripts/central_config.py +[governance-link]: https://github.com/ptr727/ProjectTemplate/blob/main/GOVERNANCE.md#pr-review-etiquette +[repo-config-link]: https://github.com/ptr727/ProjectTemplate/blob/main/docs/repo-config.md +[reviewer-reference-link]: https://github.com/ptr727/ProjectTemplate/blob/main/docs/pr-reviewer-reference.md diff --git a/repo-config/central/pr-agent-settings/README.md b/repo-config/central/pr-agent-settings/README.md new file mode 100644 index 000000000..ce8a70e26 --- /dev/null +++ b/repo-config/central/pr-agent-settings/README.md @@ -0,0 +1,39 @@ +# pr-agent-settings + +Qodo's organization-wide configuration for the `ptr727` repositories. + +## Purpose + +[Qodo][qodo-link] reads a repository named `pr-agent-settings` under an organization or account as that owner's central configuration. It reads `.pr_agent.toml` from this repository's default branch for any repository that carries no `.pr_agent.toml` of its own on its default branch. A repository that carries one uses its own file instead. + +A fleet repository chooses which reviewers run, on which branches, and when, in its own `.github/agent-policy.json`. That file is rendered from the [ProjectTemplate][projecttemplate-link] registry, together with the repository's `.coderabbit.yaml` and `.pr_agent.toml`. So the default here covers only a repository that has not received its rendered files yet. It turns automatic feedback off, so it starts no review nobody asked for. + +## Status + +Qodo reads a repository's own file only from its default branch. So a central default with automatic feedback off silences Qodo wherever a repository's own file has not reached that branch. `.pr_agent.toml` is therefore present here only while every fleet repository carries its own `.pr_agent.toml` on its default branch, setting `config.disable_auto_feedback`. [`scripts/central_config.py`][central-config-link] `write` adds the file when that holds and removes it when it does not. + +## Where the Rules Live + +This repository holds configuration only. The rules it serves live in ProjectTemplate: + +- [Pull Request Reviewer Reference][reviewer-reference-link] describes each reviewer bot and how its configuration is committed. Its "Review Configuration" section covers the review policy. +- [`spec/agent-policy.schema.json`][agent-policy-schema-link] defines the policy file, and [`spec/agent-policy.default.json`][agent-policy-default-link] is the default a repository inherits where its own file states none. +- [`GOVERNANCE.md`][governance-link] "PR Review Etiquette" governs how a review is requested, triaged, and resolved. +- [Repository Configuration][repo-config-link] describes `repo-config/configure.sh`, which applies each repository's bot settings. + +## Changing the Configuration + +ProjectTemplate writes this repository with [`scripts/central_config.py`][central-config-link]. Make a change there and carry it here by a pull request. Never edit this repository in place. The [configuration reference][qodo-config-link] names each option. + + +[projecttemplate-link]: https://github.com/ptr727/ProjectTemplate +[qodo-config-link]: https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/ +[qodo-link]: https://www.qodo.ai + + +[agent-policy-default-link]: https://github.com/ptr727/ProjectTemplate/blob/main/spec/agent-policy.default.json +[agent-policy-schema-link]: https://github.com/ptr727/ProjectTemplate/blob/main/spec/agent-policy.schema.json +[central-config-link]: https://github.com/ptr727/ProjectTemplate/blob/main/scripts/central_config.py +[governance-link]: https://github.com/ptr727/ProjectTemplate/blob/main/GOVERNANCE.md#pr-review-etiquette +[repo-config-link]: https://github.com/ptr727/ProjectTemplate/blob/main/docs/repo-config.md +[reviewer-reference-link]: https://github.com/ptr727/ProjectTemplate/blob/main/docs/pr-reviewer-reference.md diff --git a/scripts/central_config.py b/scripts/central_config.py new file mode 100755 index 000000000..81feb17ae --- /dev/null +++ b/scripts/central_config.py @@ -0,0 +1,324 @@ +#!/usr/bin/env python3 +# /// script +# requires-python = ">=3.13" +# dependencies = ["editorconfig>=0.17", "ruamel.yaml>=0.18"] +# /// +"""Write and check the central bot-settings repositories from the hub. + +CodeRabbit reads a repository named `coderabbit` under the owner as central configuration, and Qodo reads `pr-agent-settings`. +A repository carrying its own file ignores the central one, so a central file is safe only once every fleet repository carries its own. +The central file therefore exists only while every registry repository sets the key the central file sets, in its own file on its default branch. +`precondition` reports that gate, `write` puts the settings repository's files into a checkout, and `check` reads them back at a ref. +The README comes from `repo-config/central//README.md`, and the config text is a constant in this file. + +The YAML parser is imported inside the code that needs it. + +Exit codes: 0 ok, 1 a refusal, a failed precondition or drift, 2 a read or the command could not run. +""" + +from __future__ import annotations + +import argparse +import sys +import tomllib +from pathlib import Path +from typing import Any, NamedTuple + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +import gh_graphql +from agent_policy import ( + TOML_PATH, + YAML_PATH, + Reader, + Refusal, + Result, + Unreadable, + current_text, + gh_reader, + gh_rest, + keep_endings, + load_registry, + verify_checkout, +) + +CENTRAL_DIR = Path(__file__).resolve().parents[1] / "repo-config" / "central" +README_PATH = "README.md" +GENERATED = "# Generated by ProjectTemplate scripts/central_config.py, so change it there rather than here.\n" + + +class Settings(NamedTuple): + """One settings repository: the bot it configures and the file and key the gate reads.""" + + bot: str + config: str + key: tuple[str, ...] + text: str + + +TABLE: dict[str, Settings] = { + "coderabbit": Settings( + bot="CodeRabbit", + config=YAML_PATH, + key=("reviews", "auto_review", "enabled"), + text=GENERATED + + "# A repository carrying its own .coderabbit.yaml uses that file instead of this one.\n" + + "reviews:\n auto_review:\n enabled: false\n", + ), + "pr-agent-settings": Settings( + bot="Qodo", + config=TOML_PATH, + key=("config", "disable_auto_feedback"), + text=GENERATED + + "# A repository carrying its own .pr_agent.toml overrides what it sets here.\n" + + "[config]\ndisable_auto_feedback = true\n", + ), +} + + +def settings_for(repo: str) -> tuple[str, str, Settings]: + """The owner, the name and the table entry for `repo`, or a Refusal.""" + owner, _, name = repo.partition("/") + if not owner or name not in TABLE: + raise Refusal(f"{repo} is not a settings repository, expected OWNER/{{{'|'.join(TABLE)}}}") + return owner, name, TABLE[name] + + +def source_readme(name: str) -> str: + """The hand-authored README for the settings repository, as LF text.""" + path = CENTRAL_DIR / name / README_PATH + text = current_text(path) + if text is None: + raise Refusal(f"{path} is missing") + return text.replace("\r\n", "\n") + + +def fleet_repos(registry_data: Any, owner: str) -> list[str]: + """The `owner/name` of every live registry repository under `owner`.""" + if not isinstance(registry_data, dict): + raise Refusal("the registry file is absent or not an object") + found = [] + for entry in registry_data.get("repos", []): + if not isinstance(entry, dict) or entry.get("status") == "archived": + continue + parts = str(entry.get("url", "")).rstrip("/").split("/") + if len(parts) < 2 or parts[-2].lower() != owner.lower(): + continue + found.append(f"{parts[-2]}/{parts[-1]}") + return found + + +def key_problem(settings: Settings, text: str) -> str | None: + """Why `text` does not set the key to a bool, or None where it does.""" + try: + if settings.config == YAML_PATH: + from ruamel.yaml import YAML, YAMLError + + try: + doc = YAML(typ="safe").load(text) + except YAMLError: + return f"{settings.config} does not parse" + else: + doc = tomllib.loads(text) + except tomllib.TOMLDecodeError: + return f"{settings.config} does not parse" + node: Any = doc + for part in settings.key: + node = node.get(part) if isinstance(node, dict) else None + dotted = ".".join(settings.key) + if node is None: + return f"{settings.config} does not set {dotted}" + if not isinstance(node, bool): + return f"{settings.config} sets {dotted} to a value that is not a bool" + return None + + +def own_file( + slug: str, settings: Settings, run: gh_graphql.Runner = gh_graphql.run_subprocess +) -> Result: + """Whether `slug` carries its own config on its default branch that sets the key.""" + proc = gh_rest(f"repos/{slug}", ".default_branch", run) + branch = proc.stdout.strip() + if proc.returncode != 0 or not branch: + return Result(False, f"{slug}: default branch is unreadable ({proc.stderr.strip()})", True) + try: + text = gh_reader(slug, branch, run)(settings.config) + except Unreadable as exc: + return Result(False, f"{slug}: {settings.config} is unreadable ({exc})", True) + if text is None: + return Result(False, f"{slug}: {settings.config} is absent on {branch}") + problem = key_problem(settings, text) + if problem is not None: + return Result(False, f"{slug}: {problem}") + return Result(True, f"{slug}: {settings.config} sets {'.'.join(settings.key)} on {branch}") + + +def precondition( + repo: str, registry_data: Any, run: gh_graphql.Runner = gh_graphql.run_subprocess +) -> list[Result]: + """One result per live registry repository under the settings repository's owner.""" + owner, _, settings = settings_for(repo) + return [own_file(slug, settings, run) for slug in fleet_repos(registry_data, owner)] + + +def lacking(results: list[Result]) -> str: + """The failed repositories as the withheld line lists them.""" + return ", ".join(r.msg.split(":", 1)[0].split("/", 1)[-1] for r in results if not r.ok) + + +def require_readable(results: list[Result]) -> None: + unread = [r.msg for r in results if r.unreadable] + if unread: + raise Unreadable("; ".join(unread)) + + +def write( + repo: str, + registry_data: Any, + checkout: Path, + dry_run: bool = False, + run: gh_graphql.Runner = gh_graphql.run_subprocess, +) -> list[str]: + """Put the README and the gated config into `checkout`, returning one status line per file. + + Everything is planned first, so a refusal or an unreadable repository leaves the checkout untouched. + """ + _, name, settings = settings_for(repo) + verify_checkout(checkout, repo) + results = precondition(repo, registry_data, run) + require_readable(results) + readme = keep_endings(checkout / README_PATH, source_readme(name)) + holds = all(r.ok for r in results) + config = checkout / settings.config + wanted = keep_endings(config, settings.text) if holds else None + lines = [] + if current_text(checkout / README_PATH) == readme: + lines.append(f"unchanged {README_PATH}") + else: + lines.append(f"{'would write' if dry_run else 'wrote'} {README_PATH}") + present = current_text(config) + if present is not None and wanted is None: + lines.append(f"{'would remove' if dry_run else 'removed'} {settings.config}") + elif present == wanted: + lines.append(f"unchanged {settings.config}") + else: + lines.append(f"{'would write' if dry_run else 'wrote'} {settings.config}") + if not holds: + lines.append( + f"withheld {settings.config}: {sum(not r.ok for r in results)} repo(s) lack their own " + f"file setting {'.'.join(settings.key)}: {lacking(results)}" + ) + if not dry_run: + if readme is not None and lines[0].startswith("wrote"): + (checkout / README_PATH).write_text(readme, encoding="utf-8", newline="") + if wanted is None: + config.unlink(missing_ok=True) + elif present != wanted: + config.write_text(wanted, encoding="utf-8", newline="") + return lines + + +def check( + repo: str, + registry_data: Any, + ref: str, + run: gh_graphql.Runner = gh_graphql.run_subprocess, +) -> list[Result]: + """What the settings repository holds at `ref` against what `write` would put there.""" + _, name, settings = settings_for(repo) + read: Reader = gh_reader(repo, ref, run) + results = [] + try: + readme = read(README_PATH) + config = read(settings.config) + except Unreadable as exc: + return [Result(False, f"{repo} at {ref} is unreadable ({exc})", True)] + if readme is None: + results.append(Result(False, f"{README_PATH} is missing, run write to create it")) + else: + same = readme.replace("\r\n", "\n") == source_readme(name) + results.append( + Result(same, f"{README_PATH} {'equals' if same else 'differs from'} the source") + ) + pre = precondition(repo, registry_data, run) + if any(r.unreadable for r in pre): + return results + [Result(False, r.msg, True) for r in pre if r.unreadable] + if all(r.ok for r in pre): + if config is None: + results.append(Result(False, f"{settings.config} is missing, run write to create it")) + else: + same = config.replace("\r\n", "\n") == settings.text + msg = f"{settings.config} {'equals' if same else 'differs from'} the generated text" + results.append(Result(same, msg)) + return results + who = f"{sum(not r.ok for r in pre)} repo(s) lack their own file: {lacking(pre)}" + if config is None: + results.append(Result(True, f"{settings.config} is withheld while {who}")) + else: + msg = f"{settings.config} is present and silences {settings.bot} on {who}, run write to remove it" + results.append(Result(False, msg)) + return results + + +def build_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser( + prog="central_config.py", + description="Write and check the central CodeRabbit and Qodo settings repositories.", + epilog="Exit codes: 0 ok, 1 a refusal, a failed precondition or drift, 2 a read or the command could not run.", + ) + sub = parser.add_subparsers(dest="command", required=True) + for cmd, text in ( + ( + "precondition", + "report whether every registry repository carries its own file setting the key", + ), + ( + "write", + "write the README and the gated config into a checkout, never staging or committing", + ), + ("check", "compare the settings repository at a ref with what write would produce"), + ): + one = sub.add_parser(cmd, help=text, description=text) + one.add_argument("--repo", required=True, help="OWNER/NAME of the settings repository") + one.add_argument("--registry", required=True, help="path to registry/repos.json") + if cmd == "write": + one.add_argument("--checkout", required=True, help="the settings repository checkout") + one.add_argument( + "--dry-run", action="store_true", help="plan every file and write none" + ) + if cmd == "check": + one.add_argument("--ref", default="main", help="the branch or commit to read") + return parser + + +def run_command(args: argparse.Namespace, run: gh_graphql.Runner) -> int: + registry_data = load_registry(args.registry) + if args.command == "write": + for line in write(args.repo, registry_data, Path(args.checkout), args.dry_run, run): + print(line) + return 0 + if args.command == "precondition": + results = precondition(args.repo, registry_data, run) + else: + results = check(args.repo, registry_data, args.ref, run) + for result in results: + print(f" {'ok ' if result.ok else 'FAIL'} {result.msg}") + if any(result.unreadable for result in results): + return 2 + return 0 if all(result.ok for result in results) else 1 + + +def main(argv: list[str] | None = None, run: gh_graphql.Runner = gh_graphql.run_subprocess) -> int: + args = build_parser().parse_args(argv) + try: + return run_command(args, run) + except Refusal as exc: + print(f"central_config.py: {exc}", file=sys.stderr) + return 1 + except (OSError, ImportError, Unreadable, gh_graphql.GraphQLError) as exc: + print(f"central_config.py: could not run ({exc})", file=sys.stderr) + return 2 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_central_config.py b/tests/test_central_config.py new file mode 100755 index 000000000..befe3eb3e --- /dev/null +++ b/tests/test_central_config.py @@ -0,0 +1,353 @@ +#!/usr/bin/env python3 +"""Exercise scripts/central_config.py against a constructed registry and stand-in gh runners. + +The script writes a central bot-settings file only while every fleet repository carries its own. +So each case pins one state of that gate, and no case reaches the network. +""" + +from __future__ import annotations + +import base64 +import contextlib +import io +import json +import sys +import tempfile +import tomllib +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "scripts")) +sys.path.insert(0, str(ROOT / "tests")) + +import central_config +from agent_policy import Refusal, Unreadable +from test_agent_policy import make_checkout + +CODERABBIT = "Acme/coderabbit" +QODO = "Acme/pr-agent-settings" +GOOD_YAML = "reviews:\n auto_review:\n enabled: true\n" +GOOD_TOML = "[config]\ndisable_auto_feedback = false\n" + + +def registry(*entries: tuple[str, str]) -> dict[str, object]: + """Registry entries as (url owner/name, status).""" + return { + "repos": [ + {"name": slug.split("/")[1], "url": f"https://github.com/{slug}", "status": status} + for slug, status in entries + ] + } + + +FLEET = registry(("Acme/Widget", "cataloged"), ("Acme/Gadget", "cataloged")) + + +class FakeGh: + """A gh runner answering default-branch and contents reads from a table of files.""" + + def __init__(self, files: dict[str, dict[str, str | Exception]] | None = None) -> None: + self.files = files or {} + self.broken: set[str] = set() + + def __call__(self, argv: list[str]) -> tuple[int, str, str]: + path = argv[2] + if path.startswith("repos/") and "/contents/" not in path: + slug = path.removeprefix("repos/") + return (1, "", "HTTP 500") if slug in self.broken else (0, "trunk\n", "") + head, _, rest = path.partition("/contents/") + slug = head.removeprefix("repos/") + name = rest.split("?")[0] + got = self.files.get(slug, {}).get(name) + if isinstance(got, Exception): + return 1, "", "gh: Server Error (HTTP 500)" + if got is None: + return 1, "", "gh: Not Found (HTTP 404)" + return 0, json.dumps(base64.encodebytes(got.encode()).decode()), "" + + +def fleet_files(yaml_text: str | None = GOOD_YAML, toml_text: str | None = GOOD_TOML) -> FakeGh: + files: dict[str, dict[str, str | Exception]] = {} + for slug in ("Acme/Widget", "Acme/Gadget"): + files[slug] = {} + if yaml_text is not None: + files[slug][".coderabbit.yaml"] = yaml_text + if toml_text is not None: + files[slug][".pr_agent.toml"] = toml_text + return FakeGh(files) + + +class TableCase(unittest.TestCase): + def test_each_config_text_sets_exactly_its_key_to_the_central_value(self) -> None: + for name, settings in central_config.TABLE.items(): + with self.subTest(name=name): + self.assertTrue(settings.text.endswith("\n")) + self.assertNotIn("\r", settings.text) + if settings.config == ".coderabbit.yaml": + from ruamel.yaml import YAML + + doc = YAML(typ="safe").load(settings.text) + else: + doc = tomllib.loads(settings.text) + node = doc + for part in settings.key[:-1]: + self.assertEqual(list(node), [part]) + node = node[part] + self.assertEqual(node, {settings.key[-1]: node[settings.key[-1]]}) + self.assertIs(node[settings.key[-1]], name == "pr-agent-settings") + + def test_every_readme_source_exists(self) -> None: + for name in central_config.TABLE: + with self.subTest(name=name): + self.assertIn("# " + name, central_config.source_readme(name)) + + def test_an_unlisted_repo_is_refused(self) -> None: + for repo in ("Acme/Widget", "Acme", "/coderabbit"): + with self.subTest(repo=repo), self.assertRaises(Refusal): + central_config.settings_for(repo) + + +class PreconditionCase(unittest.TestCase): + def holds(self, gh: FakeGh, data: object = FLEET) -> list[central_config.Result]: + return central_config.precondition(CODERABBIT, data, gh) + + def test_it_holds_where_every_repo_sets_the_key(self) -> None: + results = self.holds(fleet_files()) + self.assertEqual(len(results), 2) + self.assertTrue(all(r.ok for r in results)) + + def test_each_failure_is_named(self) -> None: + cases = { + "absent": None, + "unparseable": "reviews: [unclosed\n", + "key missing": "reviews:\n auto_review:\n drafts: false\n", + "non-bool": "reviews:\n auto_review:\n enabled: 'no'\n", + } + for label, text in cases.items(): + with self.subTest(label=label): + gh = fleet_files(yaml_text=text) + results = self.holds(gh) + self.assertTrue(all(not r.ok and not r.unreadable for r in results)) + self.assertIn("Acme/Widget", results[0].msg) + + def test_one_failing_repo_fails_only_itself(self) -> None: + gh = fleet_files() + del gh.files["Acme/Gadget"][".coderabbit.yaml"] + self.assertEqual([r.ok for r in self.holds(gh)], [True, False]) + + def test_archived_and_other_owner_entries_are_ignored(self) -> None: + data = registry( + ("Acme/Widget", "cataloged"), + ("Acme/Old", "archived"), + ("Other/Stranger", "cataloged"), + ("ACME/Gadget", "cataloged"), + ) + results = self.holds(fleet_files(), data) + self.assertEqual(len(results), 2) + + def test_the_qodo_key_must_be_a_bool_too(self) -> None: + gh = fleet_files(toml_text="[config]\ndisable_auto_feedback = 1\n") + results = central_config.precondition(QODO, FLEET, gh) + self.assertTrue(all(not r.ok for r in results)) + self.assertTrue(all(r.ok for r in central_config.precondition(QODO, FLEET, fleet_files()))) + + def test_an_unreadable_read_is_marked(self) -> None: + gh = fleet_files() + gh.files["Acme/Widget"][".coderabbit.yaml"] = RuntimeError("x") + self.assertTrue(self.holds(gh)[0].unreadable) + gh = fleet_files() + gh.broken.add("Acme/Gadget") + self.assertTrue(self.holds(gh)[1].unreadable) + + def test_a_missing_registry_is_refused(self) -> None: + with self.assertRaises(Refusal): + self.holds(fleet_files(), None) + + +class WriteCase(unittest.TestCase): + def setUp(self) -> None: + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.checkout = make_checkout(self.tmp.name, "https://github.com/Acme/coderabbit.git") + + def write(self, gh: FakeGh, dry_run: bool = False, repo: str = CODERABBIT) -> list[str]: + return central_config.write(repo, FLEET, self.checkout, dry_run, gh) + + def test_the_readme_and_the_config_are_written_where_the_gate_holds(self) -> None: + lines = self.write(fleet_files()) + self.assertEqual(lines, ["wrote README.md", "wrote .coderabbit.yaml"]) + text = central_config.TABLE["coderabbit"].text + self.assertEqual((self.checkout / ".coderabbit.yaml").read_text(encoding="utf-8"), text) + self.assertEqual( + (self.checkout / "README.md").read_text(encoding="utf-8"), + central_config.source_readme("coderabbit"), + ) + + def test_a_second_write_reports_unchanged(self) -> None: + self.write(fleet_files()) + self.assertEqual( + self.write(fleet_files()), ["unchanged README.md", "unchanged .coderabbit.yaml"] + ) + + def test_a_failing_gate_removes_the_config_and_says_why(self) -> None: + self.write(fleet_files()) + gh = fleet_files() + del gh.files["Acme/Gadget"][".coderabbit.yaml"] + lines = self.write(gh) + self.assertEqual(lines[1], "removed .coderabbit.yaml") + self.assertEqual( + lines[2], + "withheld .coderabbit.yaml: 1 repo(s) lack their own file setting " + "reviews.auto_review.enabled: Gadget", + ) + self.assertFalse((self.checkout / ".coderabbit.yaml").exists()) + + def test_a_failing_gate_with_no_file_writes_none(self) -> None: + lines = self.write(fleet_files(yaml_text=None)) + self.assertEqual(lines[:2], ["wrote README.md", "unchanged .coderabbit.yaml"]) + self.assertIn("2 repo(s) lack", lines[2]) + self.assertFalse((self.checkout / ".coderabbit.yaml").exists()) + + def test_a_dry_run_writes_and_removes_nothing(self) -> None: + lines = self.write(fleet_files(), dry_run=True) + self.assertEqual(lines, ["would write README.md", "would write .coderabbit.yaml"]) + self.assertEqual( + sorted(p.name for p in self.checkout.iterdir() if p.is_file()), [".editorconfig"] + ) + self.write(fleet_files()) + gh = fleet_files(yaml_text=None) + self.assertEqual(self.write(gh, dry_run=True)[1], "would remove .coderabbit.yaml") + self.assertTrue((self.checkout / ".coderabbit.yaml").exists()) + + def test_a_wrong_origin_refuses_and_leaves_the_checkout_alone(self) -> None: + with self.assertRaises(Refusal): + self.write(fleet_files(), repo=QODO) + self.assertEqual( + sorted(p.name for p in self.checkout.iterdir() if p.is_file()), [".editorconfig"] + ) + + def test_an_unreadable_repo_stops_the_write_before_any_file_is_touched(self) -> None: + gh = fleet_files() + gh.broken.add("Acme/Widget") + with self.assertRaises(Unreadable): + self.write(gh) + self.assertEqual( + sorted(p.name for p in self.checkout.iterdir() if p.is_file()), [".editorconfig"] + ) + + def test_crlf_follows_the_editorconfig_for_new_files_and_the_file_for_old_ones(self) -> None: + (self.checkout / ".editorconfig").write_text( + "root = true\n\n[*]\nend_of_line = crlf\n", encoding="utf-8" + ) + self.write(fleet_files()) + for name in ("README.md", ".coderabbit.yaml"): + out = (self.checkout / name).read_bytes() + self.assertIn(b"\r\n", out) + self.assertNotIn(b"\n", out.replace(b"\r\n", b"")) + self.assertEqual( + self.write(fleet_files()), ["unchanged README.md", "unchanged .coderabbit.yaml"] + ) + (self.checkout / "README.md").write_bytes( + central_config.source_readme("coderabbit").encode() + ) + self.assertEqual(self.write(fleet_files())[0], "unchanged README.md") + + +class CheckCase(unittest.TestCase): + def run_check( + self, remote: dict[str, str | Exception], gh: FakeGh + ) -> list[central_config.Result]: + gh.files[CODERABBIT] = remote + return central_config.check(CODERABBIT, FLEET, "main", gh) + + def readme(self) -> str: + return central_config.source_readme("coderabbit") + + def test_a_holding_gate_wants_the_constant(self) -> None: + text = central_config.TABLE["coderabbit"].text + results = self.run_check( + {"README.md": self.readme(), ".coderabbit.yaml": text}, fleet_files() + ) + self.assertTrue(all(r.ok for r in results)) + stale = self.run_check( + {"README.md": self.readme(), ".coderabbit.yaml": "x: 1\n"}, fleet_files() + ) + self.assertFalse(stale[1].ok) + missing = self.run_check({"README.md": self.readme()}, fleet_files()) + self.assertFalse(missing[1].ok) + self.assertIn("run write", missing[1].msg) + + def test_a_failing_gate_wants_the_file_absent(self) -> None: + gh = fleet_files(yaml_text=None) + absent = self.run_check({"README.md": self.readme()}, gh) + self.assertTrue(all(r.ok for r in absent)) + self.assertIn("withheld while 2 repo(s) lack their own file", absent[1].msg) + text = central_config.TABLE["coderabbit"].text + present = self.run_check({"README.md": self.readme(), ".coderabbit.yaml": text}, gh) + self.assertFalse(present[1].ok) + self.assertIn("silences CodeRabbit", present[1].msg) + + def test_readme_drift_fails_and_crlf_does_not(self) -> None: + text = central_config.TABLE["coderabbit"].text + drift = self.run_check({"README.md": "other\n", ".coderabbit.yaml": text}, fleet_files()) + self.assertFalse(drift[0].ok) + crlf = self.readme().replace("\n", "\r\n") + same = self.run_check({"README.md": crlf, ".coderabbit.yaml": text}, fleet_files()) + self.assertTrue(same[0].ok) + gone = self.run_check({".coderabbit.yaml": text}, fleet_files()) + self.assertFalse(gone[0].ok) + + def test_an_unreadable_read_is_marked(self) -> None: + results = self.run_check({"README.md": RuntimeError("x")}, fleet_files()) + self.assertTrue(results[0].unreadable) + gh = fleet_files() + gh.broken.add("Acme/Widget") + results = self.run_check({"README.md": self.readme()}, gh) + self.assertTrue(any(r.unreadable for r in results)) + + +class MainCase(unittest.TestCase): + def invoke(self, argv: list[str], gh: FakeGh) -> tuple[int, str]: + out = io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()): + return central_config.main(argv, gh), out.getvalue() + + def setUp(self) -> None: + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.registry = Path(self.tmp.name) / "repos.json" + self.registry.write_text(json.dumps(FLEET), encoding="utf-8") + + def argv(self, command: str, repo: str = CODERABBIT) -> list[str]: + return [command, "--repo", repo, "--registry", str(self.registry)] + + def test_precondition_exit_codes(self) -> None: + code, out = self.invoke(self.argv("precondition"), fleet_files()) + self.assertEqual(code, 0) + self.assertEqual(out.count(" ok "), 2) + code, out = self.invoke(self.argv("precondition"), fleet_files(yaml_text=None)) + self.assertEqual((code, out.count(" FAIL ")), (1, 2)) + gh = fleet_files() + gh.broken.add("Acme/Widget") + self.assertEqual(self.invoke(self.argv("precondition"), gh)[0], 2) + + def test_a_refusal_exits_1_and_a_missing_registry_too(self) -> None: + self.assertEqual(self.invoke(self.argv("precondition", "Acme/Widget"), fleet_files())[0], 1) + argv = [ + "precondition", + "--repo", + CODERABBIT, + "--registry", + str(Path(self.tmp.name) / "none"), + ] + self.assertEqual(self.invoke(argv, fleet_files())[0], 1) + + def test_an_unknown_argument_is_refused(self) -> None: + with self.assertRaises(SystemExit) as ctx, contextlib.redirect_stderr(io.StringIO()): + central_config.main([*self.argv("precondition"), "--bogus-flag"]) + self.assertEqual(ctx.exception.code, 2) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_cli_usage.py b/tests/test_cli_usage.py index 9be86cf0c..3506ddad1 100755 --- a/tests/test_cli_usage.py +++ b/tests/test_cli_usage.py @@ -86,6 +86,13 @@ ), "repo-config/configure.sh": ("check",), "scripts/canonical_review.py": ("list",), + "scripts/central_config.py": ( + "precondition", + "--repo", + "Example/coderabbit", + "--registry", + "registry/repos.json", + ), "scripts/carry.py": ("check", "Example", "--target", "."), "scripts/handoff.py": ("current", "--repo", "Example/Example"), "scripts/local_review.py": ("status",), From 3a77be2c226994ec634ee496ace9eeb25ed1ac44 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 7 Nov 2026 07:43:14 -0800 Subject: [PATCH 2/8] Say Whom the Central Default Reaches Once the Gate Admits It Once the file is present, every registry repository already carries its own, so the central default reaches only a repository the registry renders nothing for. Co-Authored-By: Claude Opus 5.5 --- repo-config/central/coderabbit/README.md | 2 +- repo-config/central/pr-agent-settings/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/repo-config/central/coderabbit/README.md b/repo-config/central/coderabbit/README.md index b7c5d5339..42d70251a 100644 --- a/repo-config/central/coderabbit/README.md +++ b/repo-config/central/coderabbit/README.md @@ -6,7 +6,7 @@ CodeRabbit's organization-wide configuration for the `ptr727` repositories. [CodeRabbit][coderabbit-link] reads a repository named `coderabbit` under an organization or account as that owner's central configuration. A repository that carries no `.coderabbit.yaml` of its own uses the `.coderabbit.yaml` here. A repository that carries one uses its own file instead. -A fleet repository chooses which reviewers run, on which branches, and when, in its own `.github/agent-policy.json`. That file is rendered from the [ProjectTemplate][projecttemplate-link] registry, together with the repository's `.coderabbit.yaml` and `.pr_agent.toml`. So the default here covers only a repository that has not received its rendered files yet. It turns automatic review off, so it starts no review nobody asked for. +A fleet repository chooses which reviewers run, on which branches, and when, in its own `.github/agent-policy.json`. That file is rendered from the [ProjectTemplate][projecttemplate-link] registry, together with the repository's `.coderabbit.yaml` and `.pr_agent.toml`. So once present, the default here reaches only a repository the registry renders no files for, such as a new one. It turns automatic review off, so it starts no review nobody asked for. ## Status diff --git a/repo-config/central/pr-agent-settings/README.md b/repo-config/central/pr-agent-settings/README.md index ce8a70e26..5e3e11158 100644 --- a/repo-config/central/pr-agent-settings/README.md +++ b/repo-config/central/pr-agent-settings/README.md @@ -6,7 +6,7 @@ Qodo's organization-wide configuration for the `ptr727` repositories. [Qodo][qodo-link] reads a repository named `pr-agent-settings` under an organization or account as that owner's central configuration. It reads `.pr_agent.toml` from this repository's default branch for any repository that carries no `.pr_agent.toml` of its own on its default branch. A repository that carries one uses its own file instead. -A fleet repository chooses which reviewers run, on which branches, and when, in its own `.github/agent-policy.json`. That file is rendered from the [ProjectTemplate][projecttemplate-link] registry, together with the repository's `.coderabbit.yaml` and `.pr_agent.toml`. So the default here covers only a repository that has not received its rendered files yet. It turns automatic feedback off, so it starts no review nobody asked for. +A fleet repository chooses which reviewers run, on which branches, and when, in its own `.github/agent-policy.json`. That file is rendered from the [ProjectTemplate][projecttemplate-link] registry, together with the repository's `.coderabbit.yaml` and `.pr_agent.toml`. So once present, the default here reaches only a repository the registry renders no files for, such as a new one. It turns automatic feedback off, so it starts no review nobody asked for. ## Status From 802d7a38346f22e5c8be172e49b1e0ddb334a0ca Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 7 Nov 2026 08:02:37 -0800 Subject: [PATCH 3/8] Refuse an Empty Fleet and Register the Settings Repositories as Excluded The gate held vacuously where the registry listed no live repository under the owner, so a mistyped owner would land the central auto-off file. It now refuses. It skips excluded entries as well as archived ones, and it reads each entry's URL through gh_graphql's ORIGIN pattern, so a URL ending in .git resolves. The fleet membership audit reports every owned repository with no registry entry as a defect. So both settings repositories get an excluded entry, which keeps them out of audit scope. scripts/README.md now documents the script. Co-Authored-By: Claude Opus 5.5 --- docs/repo-config.md | 4 ++-- registry/repos.json | 12 ++++++++++++ scripts/README.md | 15 ++++++++++++++- scripts/central_config.py | 25 +++++++++++++++++-------- tests/test_central_config.py | 29 +++++++++++++++++++++++++++++ tests/test_cli_usage.py | 2 +- 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/docs/repo-config.md b/docs/repo-config.md index 9822a814a..4b24bf807 100644 --- a/docs/repo-config.md +++ b/docs/repo-config.md @@ -38,9 +38,9 @@ Then validate the result with `repo-config/configure.sh check owner/repo release CodeRabbit reads a repository named `coderabbit` under the owner as central configuration, and Qodo reads `pr-agent-settings`. Each holds a README and one config file that turns automatic review off account-wide. A repository carrying its own `.coderabbit.yaml` or `.pr_agent.toml` uses that file instead. -`scripts/central_config.py` writes both repositories from the hub. The READMEs are hand-authored sources under `repo-config/central/`, and the config text is a constant in the script. The two settings repositories are not registry entries. +`scripts/central_config.py` writes both repositories from the hub. The READMEs are hand-authored sources under `repo-config/central/`, and the config text is a constant in the script. Each settings repository has a registry entry with `status: "excluded"`, so the fleet audit expects no baseline from it. -A central file with automatic review off silences the bot on every repository that lacks its own file. So the config file exists only while every live registry repository under the owner carries its own file. That file sits on its default branch and sets the same key to a bool. That key is `reviews.auto_review.enabled` for CodeRabbit and `config.disable_auto_feedback` for Qodo. An earlier central file without this gate silenced CodeRabbit on the repositories that had no file of their own yet. +A central file with automatic review off silences the bot on every repository that lacks its own file. So the config file exists only while every live registry repository under the owner carries its own file. A live repository is any entry that is neither archived nor excluded, and a registry listing none under the owner refuses rather than passing. That file sits on its default branch and sets the same key to a bool. That key is `reviews.auto_review.enabled` for CodeRabbit and `config.disable_auto_feedback` for Qodo. An earlier central file without this gate silenced CodeRabbit on the repositories that had no file of their own yet. - `precondition` prints `ok` or `FAIL` per repository. It exits 0 when the gate holds, 1 when it does not, and 2 when a read could not run. - `write` puts the README, and the config file only while the gate holds, into a checkout. It removes a config file the gate no longer allows and prints a `withheld` line naming the repositories that lack their own file. It never stages or commits, and `--dry-run` writes nothing. diff --git a/registry/repos.json b/registry/repos.json index ef87146d2..a119e31da 100644 --- a/registry/repos.json +++ b/registry/repos.json @@ -356,6 +356,18 @@ "url": "https://github.com/ptr727/GoogleTo1Password", "status": "archived", "driftNotes": ["Archived on GitHub. Found missing from the registry by the fleet membership check (ptr727/ProjectTemplate#550). No further conformance work is expected while archived."] + }, + { + "name": "coderabbit", + "url": "https://github.com/ptr727/coderabbit", + "status": "excluded", + "exclusionReason": "CodeRabbit's central configuration for the owner, not a fleet project. Its whole content is written by scripts/central_config.py, which docs/repo-config.md \"Central Bot Settings\" describes, so it owes no fleet baseline." + }, + { + "name": "pr-agent-settings", + "url": "https://github.com/ptr727/pr-agent-settings", + "status": "excluded", + "exclusionReason": "Qodo's central configuration for the owner, not a fleet project. Its whole content is written by scripts/central_config.py, which docs/repo-config.md \"Central Bot Settings\" describes, so it owes no fleet baseline." } ] } diff --git a/scripts/README.md b/scripts/README.md index e60dcefaa..409a50967 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -4,7 +4,7 @@ The fleet's checks and review tooling, run by hand, with the deterministic ones **Hosted here and reached, never carried.** These are not declared in [`spec/files.json`][files], so the audit does not expect a downstream repo to ship them, the same footing as `spec/audit.py`. That is the fleet model rather than an omission: a gate holding no per-repo content has one canonical implementation for the fleet. The prose and repository gate implementations live beside their composite actions under `.github/actions/`. That placement lets reusable workflows reach the implementation at their pinned hub commit through `$/.github/actions/` without checking out the hub. The same-named files in `scripts/` are thin local entry points that call those action-owned implementations. They let maintainers and hooks retain the established commands from a hub checkout without creating a second copy of either gate. A repository that cannot reach the hub reports a local check as not run rather than reconstructing it. That repository does so because a rebuilt gate encodes its author's reading of the rule and agrees with no other repository. -Python only, and standard library only. The exceptions are markdown-it-py, PyYAML, ruamel.yaml, tomlkit, and EditorConfig. `backlog_metrics.py`, `build_dist.py`, `canonical_review.py`, `carry.py`, `pr_review.py`, `pr_review_copilot.py`, and `pr_cleanup.py` declare markdown-it-py in their inline script metadata, and `build_dist.py` declares PyYAML as well. `build_dist.py` and `carry.py` import markdown-it-py only on the path that reads a region. `build_dist.py` imports PyYAML only on the path that measures a skill description. That is because `skills_install.py` and `handoff.py` import them under a plain `python3`. Every check script is read-only and exits non-zero on a finding. `build_dist.py`, `local_review.py`, `canonical_review.py`, `handoff.py`, `agent_policy.py`, and `skills_install.py` below are the exceptions. A generator, two recorders, an installer, the handoff chain, and the agent policy writer all exist to write. `build_dist.py --check` and `skills_install.py --report` are read-only modes for CI and for asking without changing anything. `local_review.py status` and `check` answer without recording anything, but they are not read-only in that same sense. Reading the working tree stages it, which writes inside `.git` and runs any `filter.*.clean` the repository configures. Only the receipt is left untouched. `canonical_review.py` reads files rather than staging them, so its `list`, `status`, `sweep`, and `report` are read-only outright, and `record` alone writes. +Python only, and standard library only. The exceptions are markdown-it-py, PyYAML, ruamel.yaml, tomlkit, and EditorConfig. `backlog_metrics.py`, `build_dist.py`, `canonical_review.py`, `carry.py`, `pr_review.py`, `pr_review_copilot.py`, and `pr_cleanup.py` declare markdown-it-py in their inline script metadata, and `build_dist.py` declares PyYAML as well. `build_dist.py` and `carry.py` import markdown-it-py only on the path that reads a region. `build_dist.py` imports PyYAML only on the path that measures a skill description. That is because `skills_install.py` and `handoff.py` import them under a plain `python3`. Every check script is read-only and exits non-zero on a finding. `build_dist.py`, `local_review.py`, `canonical_review.py`, `handoff.py`, `agent_policy.py`, `central_config.py`, and `skills_install.py` below are the exceptions. A generator, two recorders, an installer, the handoff chain, and the two settings writers all exist to write. `build_dist.py --check` and `skills_install.py --report` are read-only modes for CI and for asking without changing anything. `local_review.py status` and `check` answer without recording anything, but they are not read-only in that same sense. Reading the working tree stages it, which writes inside `.git` and runs any `filter.*.clean` the repository configures. Only the receipt is left untouched. `canonical_review.py` reads files rather than staging them, so its `list`, `status`, `sweep`, and `report` are read-only outright, and `record` alone writes. The directory separates its kinds by name and by tree. A gate checks and exits non-zero on a finding, and its name carries a `_lint` or `_gate` suffix saying what it gates. The `prose_lint.py` and `repo_gate.py` entry points delegate to the action-owned implementations that gate this tree in CI, and `host_gate.py` gates the machine it runs on. A utility does work rather than gating and carries no suffix: `backlog_metrics.py`, `build_dist.py`, `canonical_review.py`, `handoff.py`, `local_review.py`, `pr_cleanup.py`, `pr_review.py`, `pr_review_copilot.py`, `skills_install.py`. `gh_graphql.py` is a library with no command line, the GraphQL transport and cursor walker that `backlog_metrics.py`, `handoff.py`, `pr_cleanup.py`, and `pr_review.py` import from beside them. `pr_review_checks.py`, `pr_review_check_lines.py`, `pr_review_rounds.py`, and `pr_review_digest.py` are libraries with no command line as well. They are the pure readers `pr_review.py` imports for the head's checks, its review rounds, and the digest rendered from both. `pr_review_policy.py` reads and validates a repository's review policy, and `pr_review_side.py` reads and asks the comment-triggered reviewers, its one write handed in by `pr_review.py`. `pr_review_payload.py` reads the policy's key and each bot's entry off a payload, for the readers that may not load `pr_review_policy.py`. The digest takes its lines about the checks from `pr_review_check_lines.py`. The unit tests live apart at the repository root under [`tests/`][tests], one `test_