--- name: audit-pr description: Use when asked to audit, review or check a pull request, a branch or uncommitted changes, whether they are safe or "perfectly safe" to merge, to find every problem in them however minor (even a single typo), whether a pull request is completely finished, or to fix what a review found before merging. --- # Audit a pull request ## What this skill is for You decide whether a pull request is **PERFECTLY SAFE to merge into its target branch while keeping its purpose** — or you list **every** fix it needs, down to a single typo. In Fix mode you also make those fixes on its branch. Then you report in a fixed format. There are only two verdicts: - **PERFECTLY SAFE to merge into ``.** — nothing at all is left to fix. - **NOT SAFE TO MERGE YET — `` fixes needed.** — followed by every fix, however small. Three rules make the audit fair: - **Nothing is too small.** A typo, a double space, a wrong capital letter, a leftover `console.log` — each is a fix, and each one keeps the pull request from being perfectly safe. - **Nothing is invented.** Every finding quotes the exact text that is wrong and the rule it breaks. "I would write it differently" is not a finding. - **A clean pull request is called clean.** If you find nothing, the verdict is PERFECTLY SAFE. Never add findings to look thorough. Being asked to audit **is** being asked to fix and push (Fix mode). You do not need to ask again before pushing fixes to the pull request's branch. ## How to follow this file 1. Do the steps in order, from Step 1 to Step 10. Do not skip a step. Do not change the order. 2. Each step has three parts: - **Do** — what to do. Commands are shown in code blocks. Replace every `` with the real value and remove the brackets. - **Check** — what must be true before you go on. - **If not** — what to do when the check fails. 3. When this file says **STOP**, stop working, send the message it gives, and wait for the answer. 4. Never invent a fact. Every finding must quote the exact text from the diff, a command output, or the pull request's own words. For something that is **missing** (a promised job that is not in the diff), quote the words that promise it. 5. When you cannot check something — no access, a command fails, a file is missing — do not guess. Note it for Step 7, which decides whether it blocks. 6. The project's own rules win — "the project" is the repository the pull request belongs to, not whatever folder you happen to be in. If a file you read in Step 1 says something different from this file, do what the project says, and say so in the report: `The project's rule "" replaced this skill's rule "".` 7. Never merge the pull request, approve it, close it, or force-push. Only the owner merges. ## Words used in this file | Word | Meaning | |---|---| | **owner** | The person who merges pull requests. Step 1 shows how to find them. | | **base branch** | The branch the pull request goes into — the target branch, usually `main`. | | **head branch** | The pull request's own branch. | | **fork** | A pull request from someone else's copy of the repository. You usually cannot push to it. | | **scratch copy** | A separate folder with its own checkout (a git worktree), outside the person's own folder. All your work happens there. | | **scratch folder** | A folder outside the repository for temporary files. Use the one your tool gives you (a scratchpad or temp folder). If it gives none: `/tmp/going-dark` on macOS and Linux, `%TEMP%\going-dark` on Windows. | | **acceptance criteria** | What the pull request must do, taken from its issue's "What to build" and "Verify" sections and its plan's phase. The pull request's description is a **claim** to check, not the specification. | | **changed line** | A line in the diff that starts with `+` (added or changed). Lines starting with `-` are removed; you check them only to see what was lost. | | **finding** | Something in the change that is wrong, missing or inconsistent, and breaks a named rule (Step 7). Every finding is either a **fix** or a **question** for the owner. | | **preference** | "I would write it differently" with no rule broken. A preference is **not** a finding and is never reported. | | **behaviour fix** | A fix that changes what runs: source code, SQL, migrations, config, scripts, CI — except the tidy fixes below. | | **text fix** | A fix that changes only words people read: docs, comments, copy, test names, the description, plans, decision records, index tables — and the words inside a string in code, when nothing else on the line changes. | | **tidy fix** | Removing something that should not be there, or whitespace: an unused import or variable, a leftover debug or log line (even one that logs personal data), commented-out code, trailing spaces. It needs no test. | | **test fix** | A fix that changes only test files: removing an unrelated test, making a test deterministic. | | **unsafe** | Severity 1, 2 or 3 in Step 7: breaks the deploy or loses data, a security or privacy problem, or broken for users. | | **unrelated** | Not needed for any acceptance criterion or anything the description promises. | | **small** | All of these are true: under about 50 changed lines; no new dependency; no new table, column or migration; no new scheduled job, service, environment variable or setting; no new text users read that the owner has not approved; no product decision. | | **deployment skew** | During a release, the new frontend may talk to the old backend (or the reverse) for a few minutes. Both must keep working. | ## Step 1 — Read the pull request and its context **Do:** 1. Get the latest state: ``` git fetch origin ``` 2. Read the pull request: ``` gh pr view --json number,title,body,state,isDraft,isCrossRepository,baseRefName,headRefName,mergeable,files,commits ``` Write down: its title, description, state, base branch, head branch, whether it is from a fork (`isCrossRepository`), its files and **every commit message**. 3. Read the project's rule files, every one that exists: ``` git ls-files AGENTS.md CLAUDE.md GEMINI.md CONTRIBUTING.md .github/copilot-instructions.md .github/pull_request_template.md "docs/guides/*" ``` Note: the owner (look for "owner", "maintainer", "only … merges"; also `.github/CODEOWNERS`), the check commands, how migrations run, rules about releases and old clients, **style rules** (capitalisation, spelling, naming, wording), whether pull requests are **squash-merged**, and any pull request check. 4. Find the pull request check, if any: in `package.json` under `"scripts"`, a name containing `pr` or `check`; in `.github/workflows/`, a workflow that reads the pull request body. Write down its command, or "none". 5. Read the issue it names (`Closes #` or `Part of #`) and the plan that issue names: ``` gh issue view --comments git grep -l "#" origin/ -- docs git show origin/: ``` Write the **acceptance criteria** as a numbered list. Copy every piece of exact text the issue specifies (messages, labels, numbers) — Step 5 compares them character by character. 6. **Choose the mode.** Use the first rule that matches: | If | Mode | |---|---| | The state is `CLOSED` (not merged) | **STOP.** Tell the person it is closed and ask what they want. | | The state is `MERGED` | **Follow-up mode**: audit it, and put fixes in a new pull request (Step 8). | | The person said "verdict only", "report only", "don't change anything", or similar | **Report-only mode**: write every fix in the report, change nothing. | | `isCrossRepository` is `true` (a fork) | **Report-only mode**. | | You cannot push to the repository (no write access, or you are not allowed to push) | **Report-only mode**. | | Otherwise | **Fix mode**: fix on the head branch. | Steps 2 to 7 and Step 9 are the same in every mode: they only read and check. The modes differ only in Step 8. **Check:** you have the acceptance criteria (or know there is no issue), the check commands, the style rules, and the mode. **If not:** with no linked issue, use the description's own promises as the criteria, and note for Step 7: `No linked issue: checked against the description only.` ## Step 2 — Check the state, and the other open pull requests **Do:** 1. CI status: ``` gh pr checks ``` 2. How far behind the base branch it is: ``` git rev-list --count origin/..origin/ ``` The number is how many commits the base branch has that the pull request does not. 3. The other open pull requests: ``` gh pr list --state open --json number,title,headRefName,files ``` For each, compare with this pull request: - **the same file changed** → note it; whichever merges second may conflict; - **the same new number** — a migration file (`0019_…`), a decision record (`0014-…`), a plan (`0031-…`) — → a finding: two pull requests claim one number. **Check:** you know CI's status, how far behind it is, and any collisions. ## Step 3 — Make a scratch copy and trial-merge the base branch **Do:** 1. Make the scratch copy on a new local branch that follows the head branch: ``` git worktree add --track -b audit- "/audit-" origin/ ``` From now on, run every command for this pull request with `git -C "/audit-" …`, or from inside that folder. Never change the person's own folder. 2. If Step 2 said **0 commits behind**, skip to the Check: there is nothing to merge. 3. Otherwise trial-merge the latest base branch: ``` git -C "/audit-" merge --no-commit --no-ff origin/ ``` 4. List conflicts: ``` git -C "/audit-" diff --name-only --diff-filter=U ``` **Check:** no conflicts (step 4 printed nothing, or you skipped it). Leave a clean trial merge in place: Step 6 checks the merged result, because a clean merge can still hide breakage (another pull request renamed a function this one calls). **If not:** each conflicted file is a finding. In Fix mode you resolve it in Step 8. Until then, abort the trial merge: `git -C "/audit-" merge --abort`, and run Step 6 on the branch as it is. ## Step 4 — Check what the change means: letters A to L **Do:** read the whole diff: ``` gh pr diff ``` Then go through **every** letter A to L below. For each, write one result: **Sound**, **Finding** (with each finding), **Not applicable** (with why), or **Not verified** (with why). For each finding, write the file, the exact text, what is wrong, and why it matters. **A. Purpose.** Take each acceptance criterion from Step 1. Is it done in the code? Does a test cover it? Is everything the description promises in the diff? Is every new piece of code actually used — a new component that nothing renders, a new route that nothing calls? A promise with no code (for example "a nightly job" with no job) is a finding. **B. Security and privacy.** For every new or changed route or action: - Who may call it — anyone, signed-in users, admins, only the owner of the record? Is that checked on the **server**? - Is every input checked on the server (type, length, allowed values)? A limit only in the browser (`maxLength`) is not a limit. - Is any secret, token, password or personal data (names, emails, phone numbers, messages) in code, **logs**, responses, the description or screenshots? - Abuse: can someone not signed in write data or send email? Is there a rate limit? Does a table grow forever with no clean-up? Is personal data kept with no limit on how long? **C. Data.** For every migration: - Does it only add (no drop or rename of anything the running code uses)? - Is it safe on a full live table (a big `UPDATE` locks rows; a backfill can time out)? - Does it work the way the project runs migrations? If all pending migrations run in **one transaction**: a new enum value cannot be used in that same transaction, and `CREATE INDEX CONCURRENTLY` cannot run at all. - Is every table and column the code uses created somewhere? - If the project generates migrations (for example `drizzle-kit generate`, `prisma migrate dev`, `alembic revision --autogenerate`), running the generate command again must produce nothing new. **D. Deployment skew and connections.** - A new field the frontend reads from the backend: is it optional in the type and read with a fallback (`?? 0`, `?? []`, `?? ''`)? - A removed or renamed field: does the old frontend still work? - A new required field in a request: does the old frontend still send a valid request? - Does every caller use exactly the name the other side expects — the same URL path, the same field names, the same method? Compare the frontend request with the backend route and its validation, letter by letter. **E. Concurrency and failure.** - If the same action runs twice at the same moment (a double click), does the duplicate get a proper error, not a `500` or a second email? - If a call fails (a network error, a `400`, a `500`), does the code notice? Showing success after a failed request is a finding. **F. Tests.** For each new or changed test: - Would it fail without this change? - Does it test the exact value the issue gives (a limit of 500 is tested with 501, not 5001)? - Is it deterministic — no unordered pick (`limit(1)` with no `orderBy`), no dependence on the clock or timing, no `sleep`? - Is its body real, not empty or a placeholder? - Is it about this pull request's purpose? - Does the number of tests match what the description says? **G. User interface** — checked from the code and from the screenshots in the description. (Looking at the running page on a phone is the staging step that comes after merging; it is not required here.) - The project's design tokens, not raw colours, sizes or shadows. - Every input has a label. - Focus is visible. - Live regions (`aria-live`) do not announce every keystroke. Announce only at thresholds (for example near a limit) or on submit. - A message that appears after an action (a success or error text) is announced: `role="status"` or `aria-live="polite"`. **H. Records.** Docs, the plan's boxes and status, index rows and decision records all match the code — every name, number and limit. Also search for the **old** value or behaviour the change replaces (an old limit, an old message, an old format): `git -C "/audit-" grep -n ""`. Every place that still says the old thing is a finding. **I. Description.** - It is accurate after your fixes. It claims nothing the diff does not do. - Its issue number is right: `Closes #` names the issue in Step 1. - Screenshots are real (they show this feature), current, contain no personal data, and none is repeated. - It follows the pull request template, and passes the pull request check if the project has one. **J. Scope.** Nothing unrelated is in the diff — an unrelated test, a refactor, a dependency bump. Each unrelated part is a finding: remove it, and it can become its own issue. **K. Numbers.** No collision with another open pull request (Step 2). **L. Attribution.** No commit message (Step 1) and no description contains an AI attribution: a `Co-Authored-By` line naming an AI, or a "Generated with" line. **Not applicable** means the diff touches nothing the letter is about (no migration → C). **Sound** means it does, and you found nothing wrong. A letter can have several findings — write each one. If you checked part of a letter and could not check the rest, write **Sound** for the part you checked and **Not verified** for the rest, each saying which part. **Check:** all twelve letters have at least one result. ### Known problems and their usual fixes | Problem | Usual fix | |---|---| | A new enum value is used in the same migration transaction that adds it | Keep only `ADD VALUE` in this migration. Move the statement that uses the value to a later migration that ships in a later release, or to application code. | | A big `UPDATE` or backfill inside a migration | Take it out of the migration; run it in batches as a separate step after the release. This is usually **not small**: a question for the owner. | | A new response field read without a fallback | Make it optional in the type, and read it with `?? 0`, `?? []` or `?? ''`. | | `aria-live` announcing every keystroke | Keep `aria-live`, but render the text only near the limit (for example the last 10%), or announce on submit. | | `limit(1)` (or any first row) with no `orderBy` in a test | Create the exact row the test needs and use it, or add `orderBy`. | | A duplicate insert that returns 500 | A unique constraint, and turn its error into `409 Conflict`. | | A public write route with no limit | The project's rate limiter if it has one; otherwise an owner question: sign-in, rate limit, and how long rows are kept. | | An input with no label | A `