# Pariter: write and check an app's business rules

For a coding agent working in an app's repository. Free, no account, nothing is sent to Pariter: you read the
code on the owner's own assistant and write two files into the repository.

- Without the Pariter connector: follow "Write the app's rulebook" below and skip step 9 and the check_push
  bullet in step 6. Then use "Check a change" before each change you make.
- With the connector (open to anyone, https://pariter.ai/docs#connector): its rulebook_method tool returns this same method and its tools
  take steps 6 and 9.
- What Pariter adds that a self-check cannot: an independent check of a push by a model that did not write it,
  and one email when a rule breaks (one proof alert free; every push is paid, not on sale yet). See https://pariter.ai/docs.

# Write the app's rulebook

Answer one question about the repo you are in: what are this app's business rules, and does the code actually
enforce each one? Then write them down where the owner and every later coding session will read them.

## Ground rules
- Read the code; run nothing and call nothing. No deployed address, database, host or payment provider. Do not start
  the app. Write only the files below and the block in CLAUDE.md / AGENTS.md.
- The owner's words. Each rule is one sentence a business owner would agree with: "A customer sees only their own
  orders", "Only an admin changes prices", "A refund never exceeds what was paid". Code names come after.
- Enforced means you saw it. "yes" only when you can point to the line that refuses the wrong person or the wrong
  value. "partly" when some paths check and some do not. "no" when you traced the path and nothing stops it.
  "unclear" when the check lives outside the repo or you could not trace it. Never guess "yes".
- Never call the app "secure" or "safe". Say which rules are enforced and which are not.

## Steps
1. Who and what. Read the README, the data models or schema, and the routes, API handlers or server actions. Name
   the kinds of people (stranger, signed-in user, owner of a row, team member, admin) and the things they touch.
   Note `git rev-parse HEAD`. If RULES.md and .pariter/rules.json exist, read them first: you are refreshing.
2. Write the rules: who may see, create, change or delete each thing (access); prices, amounts, refunds, balances,
   units (money); counts, sizes, quotas (limits); which status may follow which (states); who becomes an admin
   (roles); one account's data kept from another's (tenant); what must always be true of the data (data). Aim for 8
   to 40 rules. Include a rule the code seems to forget when the app's purpose plainly implies it.
3. Trace each rule from the route or query to the lines that keep it, or to where a check is missing: ids taken from
   the request instead of the session, role fields a user can set, list queries with no owner filter, amounts taken
   from the browser.
4. Ids never change. New rules get the next unused id (R001, R002, ...). On a refresh keep each rule's id, update its
   wording or links, and mark a rule the code no longer has "status": "retired". Never reuse an id.
5. Write .pariter/rules.json:
   {"version": 1, "commit": "<full sha>", "rules": [{"id": "R001", "area": "access", "rule": "A customer sees only
   their own orders", "enforced": "no", "provable": true, "links": [{"file": "app/api/orders/[id]/route.ts",
   "start": 8, "end": 22, "symbol": "GET", "anchor": "<one exact line from that range>"}], "doubt": "optional"}]}
   Each link is the tight range (usually under 40 lines) that carries the rule out, or where the check should be.
   And RULES.md at the repo root: a line saying when and at which commit it was written, the counts ("N rules: Y
   enforced, P partly, X not enforced, U unclear"), a table (Id, Rule, Area, Enforced, Where), and a section "Not
   enforced, worst first" with what the wrong person can do and the smallest fix for each.
6. Add this block, once, to CLAUDE.md and to AGENTS.md where each exists (if CLAUDE.md only imports AGENTS.md, add
   it to AGENTS.md alone; if neither exists, create CLAUDE.md with just the block):
   <!-- pariter:rules start. Added by Pariter; delete from here to "pariter:rules end" to remove it. -->
   ## Business rules
   This app's business rules are in `RULES.md`, with their code links in `.pariter/rules.json`.
   - Before changing code, read the rules whose links touch the files you will change.
   - Before making a change that would break a rule, say which rule and ask.
   - When a change adds or changes a rule, update `RULES.md` and `.pariter/rules.json` in the same change, keeping ids.
   - Before merging into the default branch, push your branch and ask Pariter: call its check_push tool with the repo
     and the branch's full commit sha (`git rev-parse HEAD`), then fix what it reports. Its answer is advice to you;
     Pariter still checks the default branch on its own.
   <!-- pariter:rules end -->
7. Ask the owner about up to five doubtful rules as plain questions, and update both files with the answers.
8. Commit the files on a branch and open a pull request for the owner, or commit where the owner tells you. Never
   push to the default branch without the owner's word.
9. Call save_rulebook with the repo, the commit and the rules from .pariter/rules.json, so Pariter keeps the record.
   Then call setup for the next step (connect GitHub).

# Check a change against the app's rulebook

Answer one question: does the change in front of you break one of this app's written business rules?

## Ground rules
- Read the code; run nothing and call nothing. Change no file.
- This is a self-check: if you wrote the change, say so in your answer. Pariter's independent check (a reviewer that
  did not write the code) runs on every push once the account pays.

## Steps
1. The change. Uncommitted work: `git diff HEAD`. A branch: `git diff <default branch>...HEAD`. A commit: `git show <sha>`.
2. The rules it touches. Read .pariter/rules.json. A rule is touched when one of its links names a file the change
   edits and the link's lines (start to end) are within 3 lines of a changed line on the old side. Also note when the
   change adds a route, a table or a role: those may need a new rule. No rule touched and nothing added: answer
   "nothing touched" and stop.
3. Judge only those rules against only this change. For each: "holds" (still true after the change), "changed_as_stated"
   (the change means to alter it and says so), "broke" (no longer true, and nothing says that was meant, or plainly
   wrong: a lost permission check, a unit or formula error, a wrong status), or "unclear". Say "broke" only when you can
   point to the changed line that breaks it, and give the smallest fix in one or two lines.
4. Answer the owner in plain words: the rules touched, each verdict with its line, the fixes, and any new rule the
   change introduces. If a rule changed on purpose, update RULES.md and .pariter/rules.json in the same change, keeping
   ids.
