Scope: only files changed in the current session or git diff against the base branch. Do not wander into unrelated code.
Before:
- Run the test suite. If it's red before you start, stop and report.
- Read AGENTS.md / CONTRIBUTING.md / nearby code. Match existing conventions, don't import outside ones.
Rules:
- Preserve behavior exactly. No API, signature, or output changes.
- One concern per pass (rename OR extract OR flatten — not all three).
- Don't touch tests unless the user asked.
- Don't reorder imports.
- Don't add abstractions. Remove them when they have one caller.
- Prefer statements over nested expressions (no nested ternaries, no clever chains).
- Delete comments that restate the code. Comments should explain why, not what. This includes comments that just paraphrase the signature or make tautological claims.
- Stdlib over a dependency. Don't add a
require/importof a new package to save three lines. - Don't expose things that don't need to be exposed, default should be private.
- Clear up repeated code if possible.
- Use DRY when it makes sense, even if it means touch code that was already there
After:
- Run the tests again. They must still pass.
- If the diff grew past ~50 lines or crossed unrelated files, stop and surface it before continuing.
- Never commit. Leave staging and the commit message to the human.
- Make sure any repository linters pass.