NewsCrawler.org

Linting ADRs with Rego: the regomark CLI

ADRをregoでlintする
Image: zenn.dev

The author records design decisions as Architecture Decision Records (ADR)[1] in docs/adr/ and has Claude Code write many of them, but AI-written ADRs gradually drift from the template even when one is provided. Decision sections fill up with screen menu lists, constants or struct definitions, Status stays Proposed while the implementation goes a different way, and changed decisions lead to old ADRs being rewritten or new ADRs overriding old ones without any mark. After rereading the ADRs in the author's 7 repositories, the drifted content turned out to be material that does not belong in an ADR, while the decisions and the guarantees they protect had not gone stale.

Keeping AI-written ADRs in shape is discussed at other companies as well: one team compiled guidelines from past review comments and references them from an ADR-writing skill, a Claude Code rule and CI-based AI review, and another provides a Claude Code skill that writes ADRs from a template and a guideline. Guidelines and skills remain requests to an AI, however, with no guarantee of compliance, and AI review is itself an LLM that can miss violations or say different things about the same ADR. The author therefore turned the rules into policies written in Rego[2]: structural rules — presence and order of sections, Status values, references between ADRs, link targets — are checked mechanically and any deny fails CI, while semantic rules, such as whether an ADR has turned into a specification, are put to an LLM as questions and reported as warnings on the PR.

Because conftest[3], the policy checker built on OPA[4], cannot read Markdown, the author's earlier setup converted Markdown to AST JSON with remark, added filenames with jq and passed the result to conftest via a shell script, and that glue could overlook files whose conversion failed and let the check pass on the remaining files; Rego also cannot verify whether a link target exists. So the author wrote regomark, a single binary that parses Markdown into top-level blocks and links with line numbers, resolves link targets against the repository, passes the policy's questions together with the quoted source text to an LLM command (the sample config uses claude -p with model sonnet and max_questions 200 per run), and evaluates the policies with an embedded OPA. regomark itself contains no ADR-specific code: all rules and all LLM questions live in the Rego policies, which run unchanged under plain opa test, opa check --strict and Regal because regomark adds no custom built-in functions. The policy currently holds 14 structural rules — filenames, H1, the required Status, Context, Decision and Consequences sections and their order, Status values, replacement references without cycles, and relative links to files that exist — while semantic questions such as whether the Decision section contains function names or constants are answered yes or no with a reason and the line numbers used as evidence. Violations are printed per file with line numbers and rule IDs; the exit code is 0 with no deny, 1 with a deny and 2 when a config or policy error prevents the check, warnings leave the exit code unchanged, and --format github attaches findings to the PR diff as GitHub Actions annotations.

Read the original zenn.dev

Sources

  • Zenn JA

    ADRをregoでlintする

    62 likes24 bookmarks0 comments

Published: First seen: Читать по-русски

Open as a page