reviewer-skill 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 itinance
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,200 @@
1
- # Temporary Holding Version
1
+ # reviewer-skill
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A pull-request review process for [Claude Code](https://claude.com/claude-code): every PR
4
+ round gets **3 separate review agents**, each with one focus.
5
+
6
+ | Agent | Focus |
7
+ |---|---|
8
+ | `review-correctness` | Does the change do what the PR says; edge cases; every caller of a changed contract; error paths; spec grounding |
9
+ | `review-security` | Access control, input validation, secrets in logs, sensitive data, the project's hard rules, supply chain |
10
+ | `review-tests` | Red-first tests that pin real behaviour, the right test layer, the full CI job set on the head, spec/docs match the code |
11
+
12
+ The rules:
13
+
14
+ - All 3 reviewers run on every round, also for small diffs, docs, specs and dependency bumps.
15
+ - A re-round after a fix push goes to the **same named agents** (`SendMessage` with the new
16
+ head sha). They check their own earlier findings and report only blocking problems. This
17
+ stops endless nit loops.
18
+ - Reviewers only read. They write the full report to `.scratch/reviews/<pr>-<area>[-rN].md`
19
+ and reply with the verdict only (CLEAN / FINDINGS, a count, the blocking titles).
20
+ - Findings are fixed **in the same PR**, also the non-blocking ones. Design questions go to
21
+ the human.
22
+
23
+ ## What gets installed
24
+
25
+ | Template in this repo | Path in your project |
26
+ |---|---|
27
+ | `templates/agents/review-correctness.md` | `.claude/agents/review-correctness.md` |
28
+ | `templates/agents/review-security.md` | `.claude/agents/review-security.md` |
29
+ | `templates/agents/review-tests.md` | `.claude/agents/review-tests.md` |
30
+ | `templates/skills/review-round/SKILL.md` | `.claude/skills/review-round/SKILL.md` (start, wait, fix, re-round, merge) |
31
+ | `templates/docs/REVIEW_AND_MERGE.md` | `docs/REVIEW_AND_MERGE.md` (rules + section 4 "Project gates" to fill in) |
32
+ | `templates/CLAUDE.snippet.md` | optional: appended to `CLAUDE.md` between `<!-- reviewer-skill:start -->` and `<!-- reviewer-skill:end -->` |
33
+ | — | optional: a `.scratch/` line in `.gitignore` (the review reports) |
34
+
35
+ There are two ways to install: a Claude agent copies the files (no network code runs), or
36
+ the npm installer copies them. Both start in a feature branch.
37
+
38
+ ## Install with a Claude agent (local, no npx)
39
+
40
+ This path runs no downloaded code. The agent only reads the templates and writes files.
41
+ Give your Claude Code session this section and the tag to use, for example: *"Install
42
+ reviewer-skill v0.2.0 as described in its README section 'Install with a Claude agent'."*
43
+
44
+ Steps for the agent:
45
+
46
+ 1. **Branch first.** Run `git branch --show-current` and `git status --short`. Never install
47
+ on the default branch. Create a branch or a worktree, for example
48
+ `git switch -c chore/reviewer-skill`. Note every file that is already modified: those
49
+ changes are not part of this install.
50
+ 2. **Get the templates without running them.** Use a tag that is at least 7 days old
51
+ (release cooldown):
52
+ ```sh
53
+ git clone --depth 1 --branch v0.2.0 https://github.com/itinance/reviewer-skill.git /tmp/reviewer-skill-v0.2.0
54
+ git -C /tmp/reviewer-skill-v0.2.0 log -1 --format='%H %cI' # tag commit and date; compare with the tag on GitHub
55
+ ```
56
+ Do not run anything from the clone. Read the files only.
57
+ 3. **Copy the 5 files** in the table above with Read and Write. If a destination exists
58
+ with other content, do not overwrite it: show the human the difference and ask.
59
+ 4. **CLAUDE.md and .gitignore.** If `CLAUDE.md` does not contain
60
+ `<!-- reviewer-skill:start -->`, append the text of `templates/CLAUDE.snippet.md` between
61
+ the start and end markers. If no `.gitignore` line ignores `.scratch/`, add `.scratch/`.
62
+ Check with `git check-ignore -q .scratch/reviews/x.md`.
63
+ 5. **Fill in section 4 of `docs/REVIEW_AND_MERGE.md` from repo facts only.** Write the
64
+ source file after each value. The section says what to read for each gate. In short:
65
+ - Test and lint: the task runner (Justfile, Makefile, package.json scripts) and the CI
66
+ workflows (`.github/workflows/*.yml`, job names). Prefer the project's safe test
67
+ wrapper (for example one with a throwaway database). Copy forbidden commands from
68
+ CLAUDE.md into the gate.
69
+ - Worktree install: the real layout, with the lockfile and install scripts off, for
70
+ example `npm ci --ignore-scripts`, `pnpm install --frozen-lockfile --ignore-workspace
71
+ --ignore-scripts` for a standalone app in a workspace, `uv sync --frozen`.
72
+ - Supply chain: `.npmrc` (`ignore-scripts`), `pnpm-workspace.yaml` (`minimumReleaseAge`,
73
+ `onlyBuiltDependencies`, `ignoredBuiltDependencies`), `bunfig.toml`, the uv/pip config
74
+ (`exclude-newer`). If no setting enforces a cooldown, write "not enforced by config;
75
+ the security reviewer checks publish dates".
76
+ - Hard rules: grep the tests for existing guard tests and name the file and the test
77
+ functions. A rule without a guard test: "no guard test yet". Never invent one.
78
+ - Human-approval paths: find the real directories (for example
79
+ `find . -type d -name versions` for migrations). Do not assume a framework default.
80
+ - AI review bot: copy the project's existing rules from CLAUDE.md, and name removed bots.
81
+ - Sensitive data: list the classes only (customer names, personal emails, live database
82
+ rows, `.env` contents). Never write a real value. If there is no check script, say so.
83
+ 6. **Verify section 4 is complete.** This prints `0` when every gate is filled in:
84
+ ```sh
85
+ sed -n '/^## 4\./,/^## 5\./p' docs/REVIEW_AND_MERGE.md | grep -c 'TODO(project)'
86
+ ```
87
+ 7. **Commit only the install.** Stage the installed files, `CLAUDE.md` and `.gitignore` by
88
+ name (never `git add -A`). For any other change in the checkout, ask the human, or put it
89
+ in a separate commit.
90
+ 8. **Open a draft PR** and make it the first review round of the new process. The new agent
91
+ types load only after a restart of Claude Code or `/agents`. In the same session, start
92
+ each reviewer with `subagent_type: "general-purpose"` and the full text of its agent file
93
+ in the prompt.
94
+ 9. **Clean up:** `rm -rf /tmp/reviewer-skill-v0.2.0`.
95
+
96
+ **If the files were already written on the default branch** (for example by an older
97
+ installer): create the branch or worktree, copy the installed files there, apply the
98
+ `CLAUDE.md` and `.gitignore` changes there, and check that the files are the same
99
+ (`diff -r`). Then, on the default branch, delete the new files and run
100
+ `git restore CLAUDE.md .gitignore`. Leave unrelated changes alone.
101
+
102
+ ## Install with npm
103
+
104
+ The package has **no dependencies and no install scripts**. Install it with an exact version.
105
+ Never use `@latest`, a bare package name, or `-y` / `--yes`. `npx` downloads and runs code:
106
+ if your rules forbid fetch-and-execute, use the agent path above.
107
+
108
+ ### 1. Check the release age first
109
+
110
+ Use a version that is at least **7 days** old (release cooldown). A fresh release is the
111
+ window in which a hijacked account or a bad publish does the most damage.
112
+
113
+ ```sh
114
+ npm view reviewer-skill time --json # publish date of every version
115
+ npm view reviewer-skill@0.2.0 dist.integrity
116
+ ```
117
+
118
+ ### 2. Run the installer in a feature branch of your project
119
+
120
+ The installer refuses to write on the default branch (`origin/HEAD`, else `main` or
121
+ `master`). It reads the branch with your local `git`; that is the only program it runs.
122
+ Create a branch first: `git switch -c chore/reviewer-skill`.
123
+
124
+ `--before <date>` lets npm enforce the cooldown: if the pinned version was published after
125
+ that date, npx stops with `notarget` before it downloads or runs anything.
126
+
127
+ ```sh
128
+ # macOS
129
+ npx --ignore-scripts --before "$(date -v-7d +%Y-%m-%d)" reviewer-skill@0.2.0 install --dry-run
130
+ npx --ignore-scripts --before "$(date -v-7d +%Y-%m-%d)" reviewer-skill@0.2.0 install
131
+
132
+ # Linux
133
+ npx --ignore-scripts --before "$(date -d '7 days ago' +%Y-%m-%d)" reviewer-skill@0.2.0 install
134
+ ```
135
+
136
+ `npx` asks "Ok to proceed?" before it downloads the package. Read it and answer it; do not
137
+ suppress it.
138
+
139
+ In a terminal, the installer asks before each change to an existing file and before the
140
+ optional `CLAUDE.md` and `.gitignore` edits. Without a terminal (an agent runs it), it only
141
+ creates missing files. An agent names the optional edits explicitly:
142
+
143
+ ```sh
144
+ npx --ignore-scripts --before "$(date -v-7d +%Y-%m-%d)" reviewer-skill@0.2.0 install --append-claude-md --gitignore-scratch
145
+ ```
146
+
147
+ Both edits are idempotent: the `CLAUDE.md` section is added once (marker check), and the
148
+ `.scratch/` line only if no line ignores `.scratch` yet. There is no flag that answers every
149
+ question with yes.
150
+
151
+ With Bun (Bun does not run lifecycle scripts of packages by default):
152
+
153
+ ```sh
154
+ bunx reviewer-skill@0.2.0 install
155
+ ```
156
+
157
+ Do not install it globally. If you must: `npm install -g --ignore-scripts reviewer-skill@0.2.0`.
158
+
159
+ ### 3. After the install
160
+
161
+ Follow steps 5 to 8 of the agent path: fill in section 4 from repo facts, verify it, commit
162
+ only the installed files, open a draft PR as the first review round, and restart Claude Code
163
+ (or open `/agents`) so that it loads the new agents.
164
+
165
+ ## Use
166
+
167
+ Ask Claude Code: *"Run a review round on PR 123."* The `review-round` skill starts the 3
168
+ agents in parallel as `review-123-correctness`, `review-123-security`, `review-123-tests`,
169
+ waits for their verdicts, reads the reports, fixes the findings in the same PR, and sends the
170
+ new head sha to the same 3 agents until all are clean.
171
+
172
+ ## Commands
173
+
174
+ ```
175
+ reviewer-skill [install] [options]
176
+ --target <dir> project root (default: current directory)
177
+ --dry-run show what would happen; write nothing
178
+ --append-claude-md append the marked review section to CLAUDE.md (once)
179
+ --gitignore-scratch add ".scratch/" to .gitignore (once)
180
+ --allow-default-branch install on the default branch (normally refused)
181
+ reviewer-skill print-snippet print the CLAUDE.md section
182
+ reviewer-skill --help | --version
183
+ ```
184
+
185
+ ## Update
186
+
187
+ Run the installer again with the new exact version (after its cooldown), or repeat the agent
188
+ path with the new tag. A file that differs from the new template is never overwritten without
189
+ asking; choose `n` to get a `.reviewer-skill.new` file and compare it with your version.
190
+
191
+ ## Development
192
+
193
+ ```sh
194
+ npm test # node --test, no dependencies
195
+ npm pack --dry-run # check the package contents
196
+ ```
197
+
198
+ ## License
199
+
200
+ MIT
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { createInterface } from 'node:readline/promises';
4
+ import { install, snippetBlock } from '../lib/install.js';
5
+
6
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
7
+
8
+ const HELP = `reviewer-skill ${pkg.version}
9
+
10
+ Installs the 3-reviewer PR process for Claude Code into a project:
11
+ .claude/agents/review-{correctness,security,tests}.md
12
+ .claude/skills/review-round/SKILL.md
13
+ docs/REVIEW_AND_MERGE.md (template, fill in the TODO(project) gates)
14
+ CLAUDE.md section, .gitignore entry (optional: asked, or by flag)
15
+
16
+ Usage:
17
+ reviewer-skill [install] [options]
18
+ reviewer-skill print-snippet print the CLAUDE.md section
19
+ reviewer-skill --help | --version
20
+
21
+ Options:
22
+ --target <dir> project root (default: current directory)
23
+ --dry-run show what would happen; write nothing
24
+ --append-claude-md append the marked review section to CLAUDE.md (once)
25
+ --gitignore-scratch add ".scratch/" to .gitignore (once)
26
+ --allow-default-branch install on the default branch (normally refused)
27
+
28
+ Existing files are never changed without asking. Without a terminal (for example
29
+ when an agent runs it), missing files are created and existing files are left alone;
30
+ only the two edits named by --append-claude-md and --gitignore-scratch are made.
31
+ There is no flag that answers every question with yes.
32
+ `;
33
+
34
+ function parseArgs(argv) {
35
+ const opts = {
36
+ command: 'install',
37
+ target: process.cwd(),
38
+ dryRun: false,
39
+ appendClaudeMd: false,
40
+ gitignoreScratch: false,
41
+ allowDefaultBranch: false,
42
+ };
43
+ const args = [...argv];
44
+ while (args.length) {
45
+ const a = args.shift();
46
+ if (a === 'install' || a === 'print-snippet') opts.command = a;
47
+ else if (a === '--target') {
48
+ const v = args.shift();
49
+ if (!v) throw new Error('--target needs a directory');
50
+ opts.target = v;
51
+ } else if (a === '--dry-run') opts.dryRun = true;
52
+ else if (a === '--append-claude-md') opts.appendClaudeMd = true;
53
+ else if (a === '--gitignore-scratch') opts.gitignoreScratch = true;
54
+ else if (a === '--allow-default-branch') opts.allowDefaultBranch = true;
55
+ else if (a === '--help' || a === '-h') opts.command = 'help';
56
+ else if (a === '--version' || a === '-v') opts.command = 'version';
57
+ else throw new Error(`unknown argument: ${a}`);
58
+ }
59
+ return opts;
60
+ }
61
+
62
+ function makeAsk() {
63
+ if (!process.stdin.isTTY || !process.stdout.isTTY) return { ask: null, close() {} };
64
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
65
+ return {
66
+ async ask(question, choices, fallback) {
67
+ for (;;) {
68
+ const a = (await rl.question(`${question} `)).trim().toLowerCase();
69
+ if (a === '') return fallback;
70
+ if (choices.includes(a[0])) return a[0];
71
+ }
72
+ },
73
+ close: () => rl.close(),
74
+ };
75
+ }
76
+
77
+ async function main() {
78
+ const opts = parseArgs(process.argv.slice(2));
79
+ if (opts.command === 'help') return void process.stdout.write(HELP);
80
+ if (opts.command === 'version') return void process.stdout.write(`${pkg.version}\n`);
81
+ if (opts.command === 'print-snippet') return void process.stdout.write(await snippetBlock());
82
+
83
+ const prompt = opts.dryRun ? { ask: null, close() {} } : makeAsk();
84
+ let results;
85
+ try {
86
+ results = await install({
87
+ target: opts.target,
88
+ ask: prompt.ask,
89
+ dryRun: opts.dryRun,
90
+ appendClaudeMd: opts.appendClaudeMd,
91
+ gitignoreScratch: opts.gitignoreScratch,
92
+ allowDefaultBranch: opts.allowDefaultBranch,
93
+ });
94
+ } finally {
95
+ prompt.close();
96
+ }
97
+
98
+ if (!prompt.ask && !opts.dryRun) {
99
+ process.stdout.write('No terminal: existing files are left alone; optional edits only by flag.\n');
100
+ }
101
+ for (const r of results) {
102
+ process.stdout.write(` ${r.action.padEnd(12)} ${r.path}${r.note ? ` (${r.note})` : ''}\n`);
103
+ }
104
+ process.stdout.write(`
105
+ Next:
106
+ 1. Fill in the project gates (section 4) from repo facts:
107
+ sed -n '/^## 4\./,/^## 5\./p' docs/REVIEW_AND_MERGE.md | grep -c 'TODO(project)' # 0 when done
108
+ 2. Restart Claude Code (or open /agents) so that it loads the new agents.
109
+ 3. Commit only these files, open a draft PR, and make it the first review round.
110
+ `);
111
+ }
112
+
113
+ main().catch((err) => {
114
+ process.stderr.write(`reviewer-skill: ${err.message}\n`);
115
+ process.exit(1);
116
+ });
package/lib/install.js ADDED
@@ -0,0 +1,246 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import { execFile } from 'node:child_process';
3
+ import path from 'node:path';
4
+ import { promisify } from 'node:util';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const execFileP = promisify(execFile);
8
+
9
+ export const TEMPLATE_DIR = path.join(
10
+ path.dirname(fileURLToPath(import.meta.url)),
11
+ '..',
12
+ 'templates',
13
+ );
14
+
15
+ // Template file -> path in the target project.
16
+ export const FILES = [
17
+ { src: 'agents/review-correctness.md', dest: '.claude/agents/review-correctness.md' },
18
+ { src: 'agents/review-security.md', dest: '.claude/agents/review-security.md' },
19
+ { src: 'agents/review-tests.md', dest: '.claude/agents/review-tests.md' },
20
+ { src: 'skills/review-round/SKILL.md', dest: '.claude/skills/review-round/SKILL.md' },
21
+ { src: 'docs/REVIEW_AND_MERGE.md', dest: 'docs/REVIEW_AND_MERGE.md' },
22
+ ];
23
+
24
+ export const SNIPPET_SRC = 'CLAUDE.snippet.md';
25
+ export const SNIPPET_START = '<!-- reviewer-skill:start -->';
26
+ export const SNIPPET_END = '<!-- reviewer-skill:end -->';
27
+ export const GITIGNORE_ENTRY = '.scratch/';
28
+ export const NEW_SUFFIX = '.reviewer-skill.new';
29
+
30
+ async function lstatOrNull(p) {
31
+ try {
32
+ return await fs.lstat(p);
33
+ } catch (err) {
34
+ if (err.code === 'ENOENT') return null;
35
+ throw err;
36
+ }
37
+ }
38
+
39
+ function insideTarget(target, p) {
40
+ const rel = path.relative(target, p);
41
+ return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
42
+ }
43
+
44
+ export async function readTemplate(src) {
45
+ return fs.readFile(path.join(TEMPLATE_DIR, src), 'utf8');
46
+ }
47
+
48
+ export async function snippetBlock() {
49
+ const body = (await readTemplate(SNIPPET_SRC)).trimEnd();
50
+ return `${SNIPPET_START}\n${body}\n${SNIPPET_END}\n`;
51
+ }
52
+
53
+ // True when a .gitignore line already ignores the .scratch directory.
54
+ export function ignoresScratch(gitignoreText) {
55
+ return gitignoreText
56
+ .split(/\r?\n/)
57
+ .map((l) => l.trim())
58
+ .some((l) => ['.scratch', '.scratch/', '/.scratch', '/.scratch/', '.scratch/*', '/.scratch/*'].includes(l));
59
+ }
60
+
61
+ async function git(cwd, args) {
62
+ try {
63
+ const { stdout } = await execFileP('git', ['-C', cwd, ...args]);
64
+ return stdout.trim();
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * The current branch of the checkout at `target` and the names that count as its default
72
+ * branch: `origin/HEAD` if it is set, else `main` and `master`. Returns null when `target`
73
+ * is not in a git work tree. `current` is '' on a detached HEAD.
74
+ */
75
+ export async function branchInfo(target) {
76
+ if ((await git(target, ['rev-parse', '--is-inside-work-tree'])) !== 'true') return null;
77
+ const current = (await git(target, ['branch', '--show-current'])) ?? '';
78
+ const originHead = await git(target, ['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD']);
79
+ const defaults = originHead ? [originHead.replace(/^origin\//, '')] : ['main', 'master'];
80
+ return { current, defaults, onDefault: current !== '' && defaults.includes(current) };
81
+ }
82
+
83
+ /**
84
+ * Install the review files into `target`.
85
+ *
86
+ * `ask(question, choices, fallback)` returns one of `choices`. When `ask` is null the
87
+ * run is non-interactive: it creates missing files and never changes an existing file,
88
+ * except for the two optional edits that the caller asks for by name:
89
+ * `appendClaudeMd` (the marked section in CLAUDE.md) and `gitignoreScratch` (the
90
+ * `.scratch/` line in .gitignore). Both are idempotent.
91
+ * `dryRun` writes nothing and asks nothing.
92
+ * The install refuses to write on the default branch unless `allowDefaultBranch` is set.
93
+ *
94
+ * Returns a list of { path, action, note? } in install order.
95
+ */
96
+ export async function install({
97
+ target,
98
+ ask = null,
99
+ dryRun = false,
100
+ appendClaudeMd = false,
101
+ gitignoreScratch = false,
102
+ allowDefaultBranch = false,
103
+ }) {
104
+ const root = path.resolve(target);
105
+ const rootStat = await lstatOrNull(root);
106
+ if (!rootStat || !rootStat.isDirectory()) {
107
+ throw new Error(`target is not a directory: ${root}`);
108
+ }
109
+
110
+ const branch = await branchInfo(root);
111
+ if (branch?.onDefault && !allowDefaultBranch && !dryRun) {
112
+ throw new Error(
113
+ `the checkout is on the default branch "${branch.current}". Install in a feature branch ` +
114
+ 'or worktree (for example `git switch -c chore/reviewer-skill`), or pass --allow-default-branch.',
115
+ );
116
+ }
117
+
118
+ const results = [];
119
+ const record = (dest, action, note) => results.push({ path: dest, action, ...(note ? { note } : {}) });
120
+ if (branch?.onDefault && !allowDefaultBranch && dryRun) {
121
+ record(`branch ${branch.current}`, 'would-refuse', 'default branch; create a feature branch or worktree first');
122
+ }
123
+
124
+ for (const file of FILES) {
125
+ const dest = path.join(root, file.dest);
126
+ if (!insideTarget(root, dest)) throw new Error(`refusing path outside target: ${file.dest}`);
127
+ const content = await readTemplate(file.src);
128
+ const st = await lstatOrNull(dest);
129
+
130
+ if (!st) {
131
+ if (!dryRun) {
132
+ await fs.mkdir(path.dirname(dest), { recursive: true });
133
+ await fs.writeFile(dest, content, { flag: 'wx' });
134
+ }
135
+ record(file.dest, dryRun ? 'would-create' : 'created');
136
+ continue;
137
+ }
138
+
139
+ if (!st.isFile()) {
140
+ record(file.dest, 'skipped', 'exists and is not a regular file (symlink or directory); not touched');
141
+ continue;
142
+ }
143
+
144
+ const existing = await fs.readFile(dest, 'utf8');
145
+ if (existing === content) {
146
+ record(file.dest, 'unchanged');
147
+ continue;
148
+ }
149
+
150
+ if (dryRun) {
151
+ record(file.dest, 'would-ask', 'exists with different content');
152
+ continue;
153
+ }
154
+ if (!ask) {
155
+ record(file.dest, 'skipped', 'exists with different content; run in a terminal to choose');
156
+ continue;
157
+ }
158
+
159
+ const choice = await ask(
160
+ `${file.dest} exists and differs. [s]kip, [o]verwrite, write [n]ew file next to it?`,
161
+ ['s', 'o', 'n'],
162
+ 's',
163
+ );
164
+ if (choice === 'o') {
165
+ await fs.writeFile(dest, content);
166
+ record(file.dest, 'overwritten');
167
+ } else if (choice === 'n') {
168
+ const side = dest + NEW_SUFFIX;
169
+ try {
170
+ await fs.writeFile(side, content, { flag: 'wx' });
171
+ record(file.dest, 'new-file', `wrote ${file.dest}${NEW_SUFFIX}`);
172
+ } catch (err) {
173
+ if (err.code !== 'EEXIST') throw err;
174
+ record(file.dest, 'skipped', `${file.dest}${NEW_SUFFIX} already exists; not touched`);
175
+ }
176
+ } else {
177
+ record(file.dest, 'skipped', 'kept your version');
178
+ }
179
+ }
180
+
181
+ results.push(await installSnippet(root, { ask, dryRun, wanted: appendClaudeMd }));
182
+ results.push(await installGitignore(root, { ask, dryRun, wanted: gitignoreScratch }));
183
+ return results;
184
+ }
185
+
186
+ async function installSnippet(root, { ask, dryRun, wanted }) {
187
+ const rel = 'CLAUDE.md';
188
+ const dest = path.join(root, rel);
189
+ const st = await lstatOrNull(dest);
190
+ if (st && !st.isFile()) return { path: rel, action: 'skipped', note: 'not a regular file; not touched' };
191
+
192
+ const existing = st ? await fs.readFile(dest, 'utf8') : null;
193
+ if (existing !== null && existing.includes(SNIPPET_START)) return { path: rel, action: 'unchanged' };
194
+
195
+ const verb = existing === null ? 'Create CLAUDE.md with' : 'Append to CLAUDE.md';
196
+ if (dryRun) {
197
+ if (wanted) return { path: rel, action: existing === null ? 'would-create' : 'would-append' };
198
+ return { path: rel, action: 'would-ask', note: `optional: ${verb.toLowerCase()} the review section` };
199
+ }
200
+ if (!wanted) {
201
+ if (!ask) {
202
+ return { path: rel, action: 'skipped', note: 'optional; pass --append-claude-md, or print it with `reviewer-skill print-snippet`' };
203
+ }
204
+ const choice = await ask(`${verb} the "Review and merge" section? [y/N]`, ['y', 'n'], 'n');
205
+ if (choice !== 'y') return { path: rel, action: 'skipped', note: 'declined' };
206
+ }
207
+
208
+ const block = await snippetBlock();
209
+ if (existing === null) {
210
+ await fs.writeFile(dest, block, { flag: 'wx' });
211
+ return { path: rel, action: 'created' };
212
+ }
213
+ const sep = existing.endsWith('\n\n') ? '' : existing.endsWith('\n') ? '\n' : '\n\n';
214
+ await fs.appendFile(dest, sep + block);
215
+ return { path: rel, action: 'appended' };
216
+ }
217
+
218
+ async function installGitignore(root, { ask, dryRun, wanted }) {
219
+ const rel = '.gitignore';
220
+ const dest = path.join(root, rel);
221
+ const st = await lstatOrNull(dest);
222
+ if (st && !st.isFile()) return { path: rel, action: 'skipped', note: 'not a regular file; not touched' };
223
+
224
+ const existing = st ? await fs.readFile(dest, 'utf8') : null;
225
+ if (existing !== null && ignoresScratch(existing)) return { path: rel, action: 'unchanged' };
226
+
227
+ const note = `reports in .scratch/reviews/ must be git-ignored: add "${GITIGNORE_ENTRY}" or pass --gitignore-scratch`;
228
+ if (dryRun) {
229
+ if (wanted) return { path: rel, action: existing === null ? 'would-create' : 'would-append' };
230
+ return { path: rel, action: 'would-ask', note };
231
+ }
232
+ if (!wanted) {
233
+ if (!ask) return { path: rel, action: 'skipped', note };
234
+ const verb = existing === null ? 'Create .gitignore with' : 'Add';
235
+ const choice = await ask(`${verb} "${GITIGNORE_ENTRY}" (review reports)? [y/N]`, ['y', 'n'], 'n');
236
+ if (choice !== 'y') return { path: rel, action: 'skipped', note };
237
+ }
238
+
239
+ const line = `${GITIGNORE_ENTRY}\n`;
240
+ if (existing === null) {
241
+ await fs.writeFile(dest, line, { flag: 'wx' });
242
+ return { path: rel, action: 'created' };
243
+ }
244
+ await fs.appendFile(dest, (existing === '' || existing.endsWith('\n') ? '' : '\n') + line);
245
+ return { path: rel, action: 'appended' };
246
+ }
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "reviewer-skill",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Installs a 3-reviewer pull-request process (correctness, security, tests) for Claude Code into a project: agents, a review-round skill and a docs template.",
5
+ "keywords": ["claude-code", "claude", "code-review", "agents", "skill", "pull-request"],
6
+ "license": "MIT",
7
+ "author": "itinance",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/itinance/reviewer-skill.git"
11
+ },
12
+ "type": "module",
13
+ "bin": {
14
+ "reviewer-skill": "bin/reviewer-skill.js"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "lib/",
19
+ "templates/",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18.17"
25
+ },
26
+ "scripts": {
27
+ "test": "node --test"
28
+ }
29
+ }
@@ -0,0 +1,3 @@
1
+ ## Review and merge
2
+
3
+ Every PR round gets 3 separate review agents: `review-correctness`, `review-security`, `review-tests` (`.claude/agents/`). This also applies to small diffs, docs, specs and dependency bumps. Run a round with the `review-round` skill. A re-round after a fix push goes to the same 3 named agents (`SendMessage`), not to new ones. Fix review findings in the same PR, never in a new PR. Merge only when all 3 are clean on the current head, with `gh pr merge --merge --match-head-commit <sha>` (never squash). The full rules and the project gates are in `docs/REVIEW_AND_MERGE.md`.
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: review-correctness
3
+ description: CORRECTNESS reviewer for one PR (code or spec), one of 3 separate reviewers (correctness, security, tests) that every PR review round gets. Give it the PR number, the head sha and what the PR claims to do. Project rules come from CLAUDE.md and docs/REVIEW_AND_MERGE.md if present.
4
+ tools: Bash, Read, Grep, Glob, Write
5
+ ---
6
+
7
+ You are the CORRECTNESS reviewer for one pull request. Two other reviewers cover
8
+ security/guardrails and tests/spec quality; stay in your lane, but report a blocking problem
9
+ from another lane if you see one.
10
+
11
+ First read the project's CLAUDE.md and, if it exists, docs/REVIEW_AND_MERGE.md. Their rules
12
+ win over this file.
13
+
14
+ ## Rules (no exceptions)
15
+
16
+ - Read only. Use `gh pr view|diff|checks`, `git fetch`, `git show <sha>:<path>`,
17
+ `git diff origin/<base>...<sha>`, and the code on the base branch.
18
+ - Never `git checkout` or `git switch` in an existing checkout or worktree — another session
19
+ may work in it.
20
+ - Never run code from a fork PR: if `gh pr view <pr> --json isCrossRepository` is `true`, only
21
+ read. For a PR from the same repository, if you must run code, create a throwaway worktree
22
+ under `.claude/worktrees/rev-<pr>-correctness` (`git worktree add --detach <path> <sha>`) with
23
+ its own dependency install from the lockfile, and remove it at the end.
24
+ - Never edit a tracked file, commit, push, comment on GitHub, merge, trigger a review bot, or
25
+ call a paid API.
26
+ - Never print sensitive data (customer data, secrets, personal data). Report counts, statuses,
27
+ codes and file:line only.
28
+ - "Read only" is enforced by these rules; `Write` is only for your report file.
29
+
30
+ ## What to check
31
+
32
+ Code PR:
33
+ - The change does what the PR says, for every input: empty, malformed, huge, wrong type,
34
+ concurrent, repeated, the last page, the first run, a re-run, a partial failure.
35
+ - Every caller and consumer of a changed function, model or API shape still works, including
36
+ generated clients, types and test fixtures.
37
+ - Error paths fail loudly and are recorded; nothing is lost silently.
38
+ - Database migrations: one head, idempotent, downgrade stated, access rules still hold.
39
+
40
+ Spec PR:
41
+ - Every file:line grounding claim exists on the base branch and says what the spec says.
42
+ - Every target state can be built as written; API, migration and UI consequences are complete.
43
+ - No contradiction with other specs; recorded human decisions are applied, not re-argued.
44
+
45
+ ## Report
46
+
47
+ Write the full report to `.scratch/reviews/<pr>-correctness[-rN].md` (N = round, from 2 on).
48
+ Each finding: severity, file:line (or spec section + code file:line), a concrete failure
49
+ scenario, a fix direction, blocking yes/no. Then reply with ONLY: the verdict (CLEAN or
50
+ FINDINGS), the number of findings, and a one-line title for each blocking finding.
51
+
52
+ In a later round you get a new head sha by message: check that each earlier finding is fixed,
53
+ check only the changed text for new problems, and report only blocking ones.
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: review-security
3
+ description: SECURITY / GUARDRAILS / SUPPLY-CHAIN reviewer for one PR (code, spec or dependency bump), one of 3 separate reviewers (correctness, security, tests) that every PR review round gets. Give it the PR number, the head sha and what the PR claims to do. Project rules come from CLAUDE.md and docs/REVIEW_AND_MERGE.md if present.
4
+ tools: Bash, Read, Grep, Glob, Write
5
+ ---
6
+
7
+ You are the SECURITY / GUARDRAILS reviewer for one pull request. Two other reviewers cover
8
+ correctness and tests/spec quality; stay in your lane, but report a blocking problem from
9
+ another lane if you see one.
10
+
11
+ First read the project's CLAUDE.md and, if it exists, docs/REVIEW_AND_MERGE.md. Their hard
12
+ rules and guardrails are part of your checklist and win over this file.
13
+
14
+ ## Rules (no exceptions)
15
+
16
+ - Read only: `gh pr view|diff|checks`, `git fetch`, `git show <sha>:<path>`, the code on the
17
+ base branch, and registry metadata as JSON (pypi.org, registry.npmjs.org). Never install,
18
+ download-and-run, or execute fetched code.
19
+ - Never `git checkout` or `git switch` in an existing checkout or worktree. Never edit a
20
+ tracked file, commit, push, comment on GitHub, merge, or trigger a review bot.
21
+ - Never print sensitive data, secrets, or the entries of any denylist or secret list.
22
+ - "Read only" is enforced by these rules; `Write` is only for your report file.
23
+
24
+ ## What to check
25
+
26
+ 1. Sensitive data: none in the diff, fixtures, specs, commit messages
27
+ (`git log --format=%B origin/<base>..<sha>`) or the PR body. If the project has a
28
+ denylist check (see its docs), run it on those texts and report only "hits: N" and the file.
29
+ 2. The project's hard guardrails (CLAUDE.md): untouched and not weakened; their guard tests
30
+ unchanged.
31
+ 3. Access control: every new or changed endpoint or action checks who may call it (role,
32
+ owner, tenant); ids from the request are looked up with the same scoping as the rest of the
33
+ route; an unknown and a foreign id give the same answer; database access rules hold.
34
+ 4. Secrets and credentials never reach logs, URLs, error messages, audit details or
35
+ responses; user input is validated; parsers are safe and bounded (size, depth, regex cost).
36
+ 5. Anything that reaches an LLM prompt, a report or a log goes through the project's
37
+ sanitizer, if it has one.
38
+ 6. Supply chain: exact pins where the project requires them, a release cooldown for every
39
+ changed lock entry (direct AND transitive — list each with its publish date), no new or
40
+ look-alike package names, no install scripts, normal registry URLs and integrity hashes;
41
+ no `curl | sh`, no floating tags in commands or CI.
42
+ 7. Error logging: clean messages for expected errors, no secrets or sensitive data in them.
43
+
44
+ ## Report
45
+
46
+ Write the full report to `.scratch/reviews/<pr>-security[-rN].md`. Each finding: severity,
47
+ file:line, a concrete scenario, a fix direction, blocking yes/no. Then reply with ONLY: the
48
+ verdict (CLEAN or FINDINGS), the number of findings, and a one-line title for each blocking
49
+ finding.
50
+
51
+ In a later round you get a new head sha by message: check that each earlier finding is fixed,
52
+ check only the changed text, run the sensitive-data check again on the new diff, commits and
53
+ body, and report only blocking problems.
@@ -0,0 +1,51 @@
1
+ ---
2
+ name: review-tests
3
+ description: TESTS / CI / SPEC-QUALITY reviewer for one PR (code, spec or dependency bump), one of 3 separate reviewers (correctness, security, tests) that every PR review round gets. Give it the PR number, the head sha and what the PR claims to do. Project rules come from CLAUDE.md and docs/REVIEW_AND_MERGE.md if present.
4
+ tools: Bash, Read, Grep, Glob, Write
5
+ ---
6
+
7
+ You are the TESTS / SPEC reviewer for one pull request. Two other reviewers cover correctness
8
+ and security; stay in your lane, but report a blocking problem from another lane if you see one.
9
+
10
+ First read the project's CLAUDE.md and, if it exists, docs/REVIEW_AND_MERGE.md. Their test
11
+ and spec conventions win over this file.
12
+
13
+ ## Rules (no exceptions)
14
+
15
+ - Read only: `gh pr view|diff|checks`, `gh run list|view`, `git fetch`, `git show <sha>:<path>`.
16
+ - Never `git checkout` or `git switch` in an existing checkout or worktree.
17
+ - Never run code from a fork PR: if `gh pr view <pr> --json isCrossRepository` is `true`, only
18
+ read. For a PR from the same repository, if you must run a test, use a throwaway worktree
19
+ under `.claude/worktrees/rev-<pr>-tests` with its own dependency install, and remove it at
20
+ the end.
21
+ - Never edit a tracked file, commit, push, comment on GitHub, merge, or trigger a review bot.
22
+ - Never print sensitive data.
23
+ - "Read only" is enforced by these rules; `Write` is only for your report file.
24
+
25
+ ## What to check
26
+
27
+ Code PR:
28
+ - Red first: the new tests fail on the old code and pin the real behaviour, not mocks the test
29
+ set up itself. Edge cases: empty, invalid, boundary, the last page, concurrency, roles.
30
+ - The right test layer (unit, integration against a real database where access rules matter,
31
+ end-to-end) as the project defines it. Fixtures are synthetic.
32
+ - CI on the CURRENT head: every workflow run concluded success or skipped, and the job set is
33
+ complete. Compare the job count with the latest run on the base branch; GitHub has created
34
+ partial job sets before, and right after a push only skipped checks may exist — wait for the
35
+ run. Note whether the head is behind the base branch.
36
+
37
+ Spec PR and the spec part of a code PR:
38
+ - The spec describes the current intended state and matches the code; a decisions table holds
39
+ every human decision with its source and date; no open question blocks the build.
40
+ - Each item has a test plan that would catch its bug; acceptance criteria are testable (no
41
+ "about", "nice", "clear").
42
+ - The project's doc conventions are kept.
43
+
44
+ ## Report
45
+
46
+ Write the full report to `.scratch/reviews/<pr>-tests[-rN].md`, with run ids and job counts.
47
+ Then reply with ONLY: the verdict (CLEAN or FINDINGS), the number of findings, and a one-line
48
+ title for each blocking finding.
49
+
50
+ In a later round you get a new head sha by message: check that each earlier finding is fixed,
51
+ check only the changed text, check CI again on the new head, and report only blocking problems.
@@ -0,0 +1,122 @@
1
+ # Review and merge
2
+
3
+ These rules apply to every pull request, also to small diffs, docs, specs and dependency
4
+ bumps. They add to `CLAUDE.md` and do not repeat it.
5
+
6
+ Installed by `reviewer-skill`. Section 4 holds the project gates. Each open gate carries a
7
+ TODO marker. Fill in every gate from facts in this repository, and name the file that each
8
+ fact comes from. A gate that is still open does not exist yet: reviewers report it as a
9
+ note, they do not invent one.
10
+
11
+ ## 1. Three separate reviewers per round
12
+
13
+ - Every review round starts 3 separate review agents on the PR head:
14
+ - `review-correctness` (`.claude/agents/review-correctness.md`)
15
+ - `review-security` (`.claude/agents/review-security.md`)
16
+ - `review-tests` (`.claude/agents/review-tests.md`)
17
+ - The `review-round` skill (`.claude/skills/review-round/SKILL.md`) runs a round.
18
+ - Each agent gets a name with the PR number and its area, for example `review-123-security`.
19
+ All 3 start in one message, in the background, so that they run in parallel.
20
+ - The reviewers only read. They never check out a branch in a checkout that another session
21
+ uses. They never edit, never comment on GitHub, never merge.
22
+ - "Read only" is a rule in the agent prompt, not a tool limit. The agents need `Write` for
23
+ the report file, and `Bash` can write anywhere.
24
+ - The reviewers may run PR code only in a throwaway worktree under `.claude/worktrees/`, and
25
+ only when the PR head is in this repository. For a PR from a fork
26
+ (`gh pr view <pr> --json isCrossRepository` is `true`), they only read.
27
+ - Each reviewer writes its full report to `.scratch/reviews/<pr>-<area>[-rN].md`
28
+ (git-ignored) and replies with only: the verdict (CLEAN or FINDINGS), the number of
29
+ findings, and a one-line title for each blocking finding.
30
+ - Each finding has: file:line, a concrete failure scenario, a fix direction, blocking yes/no.
31
+ - After a fix push, the new head sha goes to the SAME three agents (`SendMessage`). Each one
32
+ checks its own earlier findings, checks only the changed text, and reports only blocking
33
+ problems. Repeat until all three are clean on the current head.
34
+ - The orchestrator (the main session) only relays while reviewers run. It does not edit code
35
+ until all three have replied.
36
+
37
+ ## 2. Findings are fixed in the same PR
38
+
39
+ - Fix every review finding in the PR that it was found in, also the non-blocking ones. Never
40
+ open a new PR for a review finding, also not for the same class of problem in another file.
41
+ - Push the fixes for one round as one push.
42
+ - A finding that needs a design decision goes to the human. The agent does not decide it.
43
+ - A real bug found outside the scope of the PR gets its own small PR from the base branch.
44
+
45
+ ## 3. Merge
46
+
47
+ - Merge only when all 3 reviewers are CLEAN on the current head, and every gate in
48
+ section 4 is green.
49
+ - Never start a merge in the same command as a safety check. Run the check on its own and
50
+ read its result first.
51
+ - Merge with `gh pr merge <pr> --merge --match-head-commit <sha>`. Never squash. Never
52
+ rebase a PR branch.
53
+ - Never merge the base branch into a work branch. When the head is behind, the merge step
54
+ runs `gh pr update-branch <pr>`, and the reviewers check CI again on the new head.
55
+ - After the merge: CI on the base branch is green.
56
+
57
+ ## 4. Project gates
58
+
59
+ <!--
60
+ Replace each open marker with a fact from this repository and its source, for example
61
+ "`make test` (source: Makefile, .github/workflows/ci.yml job `test`)". A line that does not
62
+ apply: write "none". Never write a guess, and never write a real sensitive value.
63
+ -->
64
+
65
+ ### 4.1 Commands
66
+
67
+ Read the task runner (Justfile, Makefile, package.json scripts), the CI workflows
68
+ (`.github/workflows/*.yml`, job names) and CLAUDE.md first.
69
+
70
+ - Test command: TODO(project). Use the project's safe wrapper (for example one that uses
71
+ a throwaway database), not a raw `pytest` or `npm test`, if the project has one.
72
+ - Forbidden commands: TODO(project), for example "plain `pytest` hits the live database"
73
+ (source: CLAUDE.md), or "none".
74
+ - Lint and type check: TODO(project).
75
+ - Dependency install in a throwaway review worktree, from the lockfile, with install
76
+ scripts off, for the real layout: TODO(project). Examples: `npm ci --ignore-scripts`;
77
+ `pnpm install --frozen-lockfile --ignore-scripts` (add `--ignore-workspace` for a
78
+ standalone app inside a workspace); `uv sync --frozen`.
79
+ - CI workflow and job set to compare job counts against: TODO(project).
80
+
81
+ ### 4.2 Hard rules
82
+
83
+ - Rules that a PR must never weaken, each with its guard test (file and test function):
84
+ TODO(project). Find the guard tests with a grep over the tests. A rule without a guard
85
+ test: write "no guard test yet". Do not invent a test.
86
+
87
+ ### 4.3 Sensitive data
88
+
89
+ - Classes of sensitive data in this project: TODO(project), for example customer names,
90
+ personal emails, live database rows, `.env` contents. Classes only: never a real value.
91
+ - Sensitive-data check on the diff, the commit messages and the PR body: TODO(project).
92
+ If the project has no such script, write "none; reviewers report file:line and counts
93
+ only". A check must print counts only, never the matched text.
94
+
95
+ ### 4.4 Supply chain
96
+
97
+ Read `.npmrc`, `pnpm-workspace.yaml` (`minimumReleaseAge`, `onlyBuiltDependencies`,
98
+ `ignoredBuiltDependencies`), `bunfig.toml` and the uv/pip config (`exclude-newer`).
99
+
100
+ - Exact version pins: TODO(project).
101
+ - Release cooldown per ecosystem (at least 7 days): TODO(project). Write the setting that
102
+ enforces it. If no config enforces it, write "not enforced by config; the security
103
+ reviewer checks publish dates". Never claim a cooldown that no config enforces.
104
+ - Install scripts: TODO(project), for example "off (`ignore-scripts=true` in .npmrc);
105
+ allowed only for the packages in `onlyBuiltDependencies`".
106
+
107
+ ### 4.5 Extra merge gates
108
+
109
+ - AI review bot: TODO(project). Copy the project's own rules for it (CLAUDE.md), for
110
+ example "manual trigger only, backend PRs only", and name bots that were removed; or
111
+ "none". If a bot is used: keep it paused until the 3 reviewers are clean, then trigger it
112
+ once. A pause posted right after `gh pr create` does not stop the first review: open the
113
+ PR as a draft, pause the bot, wait for its confirmation, then mark the PR ready.
114
+ - Checks before a merge (for example "no live deploy running"): TODO(project) or "none".
115
+ - Paths or PR types that need a human approval: TODO(project) or "none". Use the real
116
+ paths (find them, for example `find . -type d -name versions` for migrations); do not
117
+ assume a framework's default layout.
118
+
119
+ ## 5. Decisions
120
+
121
+ - Every human decision on a PR goes into the decisions table of its spec, with the source and
122
+ the date, in the same turn.
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: review-round
3
+ description: Use when a pull request needs a review, when a fix was pushed to a PR that is under review, when a reviewer reported findings, or before merging a PR. Covers code, spec, docs and dependency-bump PRs of any size.
4
+ ---
5
+
6
+ # Review round
7
+
8
+ Every PR round gets 3 separate review agents: `review-correctness`, `review-security`,
9
+ `review-tests` (`.claude/agents/`). The project rules are in `docs/REVIEW_AND_MERGE.md`;
10
+ read it first. Its section 4 holds the project gates.
11
+
12
+ You are the orchestrator. You start the reviewers, relay, fix, and re-round. You do not
13
+ review the PR yourself, and you do not edit code while reviewers run.
14
+
15
+ ## Before round 1
16
+
17
+ 1. Get the PR number, the head sha and the base branch:
18
+ `gh pr view <pr> --json number,headRefOid,baseRefName,isCrossRepository,title,body`.
19
+ 2. Check that the reports stay out of git: `git check-ignore -q .scratch/reviews/x.md`.
20
+ If this fails, stop and ask the human to add `.scratch/` to `.gitignore`.
21
+ 3. Write one line that says what the PR claims to do (from its title and body).
22
+
23
+ ## Round 1: start all 3 in one message
24
+
25
+ Send ONE message with 3 `Agent` calls, so that they run in parallel. Run each in the
26
+ background (`run_in_background: true` where the tool has it). The `name` makes the agent
27
+ addressable for later rounds.
28
+
29
+ ```
30
+ Agent(
31
+ name: "review-<pr>-correctness",
32
+ subagent_type: "review-correctness",
33
+ description: "Review PR <pr> correctness",
34
+ prompt: "PR <pr>, head <sha>, base <base>. Claims: <one line>. Round 1.
35
+ Report to .scratch/reviews/<pr>-correctness.md."
36
+ )
37
+ ```
38
+
39
+ Do the same for `review-<pr>-security` / `review-security` and `review-<pr>-tests` /
40
+ `review-tests`. If the agent types are not loaded (the files were installed during this
41
+ session), use `subagent_type: "general-purpose"` and put the full text of the agent file
42
+ in the prompt.
43
+
44
+ ## Wait, then read
45
+
46
+ - Wait until all 3 have replied. Each background agent sends a completion notification by
47
+ itself: do not poll, do not sleep. Do not edit while you wait.
48
+ - A reply is only: CLEAN or FINDINGS, a count, and the titles of blocking findings. Read
49
+ the full reports in `.scratch/reviews/` before you fix anything.
50
+
51
+ ## Fix
52
+
53
+ - Fix every finding in THIS PR, also the non-blocking ones. Never open a new PR for a
54
+ review finding.
55
+ - A finding that needs a design decision goes to the human. Do not decide it. Fix and push
56
+ the other findings as usual. The PR does not merge before the human has answered and the
57
+ answer is applied. Record the answer in the spec's decisions table (source, date), and put
58
+ it in the next round message.
59
+ - A real bug outside the PR's scope gets its own small PR from the base branch.
60
+ - Push all fixes of the round as one push. Get the new head sha.
61
+
62
+ ## Round N (N ≥ 2): the SAME agents, by message
63
+
64
+ Send the new sha to the same 3 named agents with `SendMessage`. Do not start new agents.
65
+ Each one checks its own earlier findings. If `SendMessage` is a deferred tool, load it
66
+ first (`ToolSearch` with `select:SendMessage`).
67
+
68
+ ```
69
+ SendMessage(
70
+ to: "review-<pr>-correctness",
71
+ message: "Round <N> of PR <pr> (base <base>). New head <sha>.
72
+ Changed since round <N-1>: <files>. Decisions since then: <none | text>.
73
+ Check your earlier findings, check only the changed text, report only
74
+ blocking problems. Report to .scratch/reviews/<pr>-correctness-r<N>.md."
75
+ )
76
+ ```
77
+
78
+ Re-rounds report only blocking problems; this stops nit loops. A re-round with no blocking
79
+ problem is CLEAN.
80
+
81
+ If a named agent can no longer be reached (for example after a session restart), start a
82
+ new agent with the same name and type, and tell it to read its earlier reports in
83
+ `.scratch/reviews/<pr>-<area>*.md` first.
84
+
85
+ Repeat fix → re-round until all 3 are CLEAN on the current head.
86
+
87
+ ## Merge
88
+
89
+ Only when all 3 are CLEAN on the current head, in this order (`docs/REVIEW_AND_MERGE.md`
90
+ sections 3 and 4):
91
+
92
+ 1. If the head is behind the base: `gh pr update-branch <pr>`, then send the new sha to the
93
+ 3 agents as a new round. Start again at "Wait, then read".
94
+ 2. Run each gate of section 4 as its own command and read its result. A gate that still
95
+ says `TODO(project)` does not exist; say so in your report to the human.
96
+ 3. In a separate command: `gh pr merge <pr> --merge --match-head-commit <sha>`. Never
97
+ squash.
98
+ 4. Check that CI on the base branch is green after the merge.
99
+
100
+ ## When the human asks to skip a step
101
+
102
+ The rules above are the human's own process, so the human may change them for one PR. Say
103
+ in one sentence which rule the request breaks (for example "all 3 reviewers also on small
104
+ PRs"). Do it only after the human confirms, and write the exception in the PR body.
105
+
106
+ ## Quick reference
107
+
108
+ | Situation | Action |
109
+ |---|---|
110
+ | New PR, or first review | 3 `Agent` calls in one message, names `review-<pr>-<area>` |
111
+ | Fix pushed | `SendMessage` the new sha to the same 3 names |
112
+ | Small diff, docs or spec PR | Still all 3 reviewers |
113
+ | Reviewer reports a non-blocking finding | Fix it in this PR |
114
+ | Finding needs a design choice | Ask the human |
115
+ | Head behind base | `gh pr update-branch <pr>`, then the reviewers check CI on the new head |
116
+ | PR from a fork | Reviewers only read; nobody runs its code |
117
+
118
+ ## Common mistakes
119
+
120
+ - Starting 3 NEW agents for round 2. They do not know their earlier findings, and they
121
+ report new nits forever. Re-rounds go to the same names.
122
+ - Reviewing only the "risky" lane on a small PR. Every round runs all 3.
123
+ - Opening a follow-up PR for a finding. Fix it in this PR.
124
+ - Asking a reviewer for its findings in the chat. The reply is the verdict; the findings are
125
+ in the report file.
126
+ - Merging on a green CI that shows only skipped checks right after a push. Wait for the run.