Inspiration

Every codebase is built on decisions. Teams write them down as architecture decision records (ADRs), and they write tests to enforce them. But the two rarely meet at review time. A patch can look harmless, pass a quick read, and still quietly break a rule the team agreed on months ago. Reviewers, human or AI, have to remember which decision governs which file and which test guards it.

I wanted a tool that answers one question for any patch: does this break a decision the repo already made, and what did the tests actually observe?

What it does

Patch Precedent links a code change to the architecture decisions behind the files it touches, and to the tests that guard those decisions, in one Relate graph.

  • Cite: it scans every ADR mention in Relate's own source and merges it with hand-reviewed rules and the checks that enforce them.
  • Replay: each patch runs against the unmodified upstream test harness in its own clean checkout.
  • Explain: one Cypher query joins the patch, the file, the decision, the implementing commit and every observed test result.

It runs on two real decisions in Relate's repository with six patches:

  • ADR-0585 (the installer downloads release assets over the direct route). Two of three patches break it. The token-header patch sends GITHUB_TOKEN as an Authorization header. Only check #64, the one linked to that clause, catches it, out of 194 checks.
  • ADR-0580 (a post-release advance never rotates CHANGELOG.md). A patch that always rotates looks harmless, but it fails check #2. A docs-only patch is the control.

The same graph is exposed to coding agents as a read-only MCP tool, precedent_for_patch(diff).

How I built it

  • Relate as an embedded single-file store. All evidence lives in data/precedent.rl, opened in-process with relate.connect (relate-db 1.1.0). There's no server.
  • The schema: (File)-[:CITES]->(Decision)-[:CHECKED_BY]->(Check) and (Commit)-[:IMPLEMENTS]->(Decision). Each replay adds (Patch)-[:PRODUCED]->(Observation)-[:FOR_CHECK]->(Check) in its own copy.
  • Cypher everywhere, with bound parameters. The store is built with UNWIND/MERGE, and the demo, explain, the MCP tool and the website all ask their questions as MATCH queries.
  • Read-only opens for the committed store. Relate's own MCP server (relate serve --mcp stdio --read-only) serves the same graph.
  • Python 3.12 with uv, a Rich terminal UI, and a static website generated with Jinja2 from the committed evidence and a recorded demo run.

Does the graph help? (measured)

Claude Sonnet reviewed each of the 6 patches 3 times with the graph tool and 3 times without it: same prompt, same file tools, same turn limit.

Without graph With graph
Verdict correct 16/18 18/18
Exactly the right decisions 13/18 18/18
Unsupported claims 4 0
Mean turns 6.2 2.1
Cost $0.73 $0.38

An honest caveat: the graph tool returns Patch Precedent's own replay of these same six patches. So this shows whether an agent uses that evidence, not how well the graph generalises.

Challenges I ran into

  • Keeping evidence separate from observation. Opening a Relate file read-write rewrites it, even for a read-only query. So the committed store is only ever opened read-only, and every replay writes to its own copy. git status stays clean after a demo.
  • Trusting only what was observed. Verdicts come from the harness's real output joined to the graph, and nothing is hard-coded by file name. If the harness skips a check on your machine, the run is reported as inconclusive instead of passing.
  • Agents mangle diffs. In 3 of 18 runs the agent changed the patch while copying it into the tool call. I made matching key on the changed lines only, ignoring whitespace and context.
  • A fair evaluation. Both arms get identical prompts and tools, every run's transcript is published, and the caveats sit on the results page itself.

What I learned

The rule and the test that enforces it are usually written by different people at different times. Joining them in a graph is what makes "is this safe?" answerable in one query. Giving an agent that join cut its turns by about two-thirds and removed its unsupported claims.

Built with AI

I built Patch Precedent with Claude Code: Claude Opus planned and reviewed, and Claude Sonnet subagents wrote the code, tests and docs. The title drawing started from a Google Gemini draft. I chose the idea, approved the plan, and made the integration, licensing and publication decisions. Details are in the README's "AI tools used" section.

Built With

Share this project:

Updates

Submission history