Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/claude-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,100 @@ jobs:
# One place for the model. The small sites get Sonnet; 4thcltr.com, heuristics, papers,
# gorfed.net, bindercurve.com, assess and ops keep Opus under "auto". Matching is by
# repository name, case-insensitive (ACID2REAPER's remote is spelled in capitals).
# A diff whose every changed path is R0 (shipping.md ladder: docs, lockfiles, generated
# files, a patch bump in package.json) gets Sonnet in an Opus repository too. Fails closed:
# a missing or empty file list, a rename, a quoted path or any path outside the R0 classes
# keeps Opus. Rule files (REVIEW.md, CLAUDE.md, the files REVIEW.md lists under "Where the rules live", templates, .claude/, control/) never count as docs.
- name: Pick the model
if: steps.dup.outputs.skip != 'true'
id: model
env:
REPO: ${{ github.repository }}
REQUESTED: ${{ inputs.model }}
REVIEW_INPUT: review-input
BASE: ${{ steps.pr.outputs.base }}
HEAD: ${{ steps.pr.outputs.head }}
run: |
set -euo pipefail
# 0 only when every changed path is R0. Matching is on the lowercased path, as ship-bot's
# touchesControlPlane does (a case-insensitive disk lands Docs/x on docs/x).
r0_only() {
local list="${REVIEW_INPUT:-review-input}/files.txt" added deleted path lower found=0
[[ -s "$list" ]] || return 1
while IFS=$'\t' read -r added deleted path; do
[[ -n "$path" ]] || return 1
found=1
lower="$(printf '%s' "$path" | tr '[:upper:]' '[:lower:]')"
case "$lower" in
*'=>'*|\"*) return 1 ;;
# Rule, skill, agent and memory files, and everything ship-bot's touchesControlPlane
# and scripts/check-rules-drift.mjs treat as control plane or rules: never docs.
review.md|*/review.md|claude.md|*/claude.md|agents.md|*/agents.md|skill.md|*/skill.md|memory.md|*/memory.md) return 1 ;;
.claude/*|.github/*|control/*|scripts/*|ship-bot/*|janitor/*|capacity/*|verification-kit/*|*/verification-kit/*|templates/*|docs/claude-home/*) return 1 ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: the comment above says everything ship-bot's touchesControlPlane treats as control plane never counts as docs, but this list leaves out the per-repo prefixes in ship-bot/lib/drafts.mjs REPO_EXTRA. For gorfednet/ops those are hosts/, infra/ and inventory-patches/ (control/ is already covered). REPO_EXTRA says outright that "a host README under hosts/ counts too", because root installs it on the house hosts. So in ops, which is an Opus repository, a PR that only changes hosts/<host>/README.md, infra/x.md or inventory-patches/notes.md matches *.md and drops to Sonnet. These are the root-run files whose review this PR says it keeps on Opus. To see it, run pick(['hosts/nas/README.md']) in the new test: it returns Sonnet. Fix: add hosts/*|infra/*|inventory-patches/* here (scope by $REPO if you want the .github repo's infra/nginx/README.md to stay R0), and add those paths to the "keeps Opus for rule, review and control files" test.

skills/*|*/skills/*|agents/*|*/agents/*|rules/*|*/rules/*) return 1 ;;
# What REVIEW.md lists under "Where the rules live", and the rule text beside it.
readme.md|docs/verification-rules.md|docs/retired-checks.md|docs/content-guidelines.md|docs/programme-template.md|docs/backlog.json) return 1 ;;
*.md|docs/*.txt|docs/*/*.txt) ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: *.md counts every markdown file outside the short deny-list as docs, including files that are rules. In this repository, docs/verification-rules.md is listed in REVIEW.md under "Where the rules live", and templates/REVIEW.site-footer.md is the text every site repository copies into its REVIEW.md. A PR that changes only those files gets Sonnet, although the step comment says rule files never count as docs. To reproduce: pick(['docs/verification-rules.md']) returns claude-sonnet-5-5. Either deny those paths, or narrow the comment so it no longer promises more than the case statement does.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: agent prompts and skills count as docs here, so a change to them gets Sonnet in an Opus repository. That breaks the step's own promise that rule files never count as docs. The exclusions above this line leave out SKILL.md (and skills/**/*.md) and janitor/PROMPT.md, so both fall through to *.md. ship-bot/lib/drafts.mjs:79 already treats SKILL.md as control plane, next to REVIEW.md, CLAUDE.md and AGENTS.md, and scripts/check-rules-drift.mjs:65 treats **/SKILL.md and **/skills/**/*.md as rule files. janitor/PROMPT.md is the prompt the daily janitor reads from origin/main at run time, and that janitor deletes branches and archives sessions. To see it, give the step a files.txt of 1 0 janitor/PROMPT.md (or janitor/SKILL.md) in gorfednet/ops: it picks claude-sonnet-5-5. Fix: add SKILL.md|*/SKILL.md|*/skills/*|janitor/PROMPT.md (or a general *PROMPT.md) to the return 1 arm, and add those paths to the 'keeps Opus for rule, review and control files' test.

package-lock.json|*/package-lock.json|pnpm-lock.yaml|*/pnpm-lock.yaml|yarn.lock|*/yarn.lock|bun.lock|*/bun.lock|bun.lockb|*/bun.lockb|cargo.lock|*/cargo.lock|poetry.lock|*/poetry.lock|gemfile.lock|*/gemfile.lock) ;;
*.generated.*|*/generated/*) ;;
package.json|*/package.json) patch_bump_only "$path" || return 1 ;;
*) return 1 ;;
esac
done < "$list"
[[ "$found" == 1 ]]
}
# 0 only when this package.json changed nothing but dependency versions that stay within
# the same range prefix, major and minor, inside the same section (dependencies,
# devDependencies, peerDependencies, optionalDependencies, overrides, resolutions). Read
# from git, so a line's section is known. Fails closed on any error.
patch_bump_only() {
[[ -n "${BASE:-}" && -n "${HEAD:-}" ]] || return 1
local mb
mb="$(git merge-base "$BASE" "$HEAD")" || return 1
node - "$mb" "$HEAD" "$1" <<'JS' || return 1
import { execFileSync } from 'node:child_process'
import { isDeepStrictEqual } from 'node:util'
const [, , base, head, path] = process.argv
const read = (rev) => JSON.parse(execFileSync('git', ['show', `${rev}:${path}`], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }))
const before = read(base)
const after = read(head)
const SECTIONS = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies', 'overrides', 'resolutions']
const VERSION = /^([\^~]?)(\d+)\.(\d+)\.\d+$/
const sameBump = (x, y) => {
if (x === y) return true
if (typeof x !== 'string' || typeof y !== 'string') return false
const a = VERSION.exec(x)
const b = VERSION.exec(y)
return Boolean(a && b && a[1] === b[1] && a[2] === b[2] && a[3] === b[3])
}
const ok = (() => {
const keys = new Set([...Object.keys(before), ...Object.keys(after)])
for (const key of keys) {
if (!SECTIONS.includes(key)) {
if (!isDeepStrictEqual(before[key], after[key])) return false
continue
}
const x = before[key] ?? {}
const y = after[key] ?? {}
if (!isDeepStrictEqual(Object.keys(x).sort(), Object.keys(y).sort())) return false
for (const name of Object.keys(x)) if (!sameBump(x[name], y[name])) return false
}
return true
})()
process.exit(ok ? 0 : 1)
JS
}
model="${REQUESTED:-auto}"
if [[ "$model" == auto ]]; then
model=claude-opus-5-5
repo="$(printf '%s' "${REPO#*/}" | tr '[:upper:]' '[:lower:]')"
case "$repo" in
promptboi.com|denseware.com|ssatcy.com|gorfmusic.com|subrythm.com|blackpixelrecords.com|anal0g.org|rowanmcarthur.com|acid2reaper) model=claude-sonnet-5-5 ;;
esac
if [[ "$model" == claude-opus-5-5 ]] && r0_only; then
model=claude-sonnet-5-5
echo "every changed path is R0: Sonnet reads it"
fi
fi
echo "model=${model}" >> "$GITHUB_OUTPUT"
echo "reviewing ${REPO} with ${model}"
Expand Down
78 changes: 76 additions & 2 deletions test/claudeReview.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,33 @@ describe('claude-review model choice', () => {
const script = /run: \|\n([\s\S]*)$/.exec(pick)[1].replace(/^ {10}/gm, '')

/** The model the step selects for a repository and requested model. */
function choose(repo, requested) {
function choose(repo, requested, input) {
const dir = mkdtempSync(join(tmpdir(), 'pick-model-'))
const out = join(dir, 'out')
writeFileSync(out, '')
execFileSync('bash', ['-c', script], { env: { PATH: process.env.PATH, REPO: repo, REQUESTED: requested, GITHUB_OUTPUT: out } })
let cwd = dir
const env = { PATH: process.env.PATH, REPO: repo, REQUESTED: requested, GITHUB_OUTPUT: out }
if (input) {
mkdirSync(join(dir, 'in'))
if (input.files !== undefined) writeFileSync(join(dir, 'in', 'files.txt'), input.files.map((p) => `1\t0\t${p}`).join('\n') + (input.files.length ? '\n' : ''))
if (input.diff !== undefined) writeFileSync(join(dir, 'in', 'full.diff'), input.diff)
env.REVIEW_INPUT = join(dir, 'in')
}
if (input?.pkg) {
const repoDir = join(dir, 'repo')
mkdirSync(repoDir)
const git = (...args) => execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@t', '-c', 'commit.gpgsign=false', ...args], { cwd: repoDir, encoding: 'utf8' }).trim()
git('init', '-q', '-b', 'main')
writeFileSync(join(repoDir, 'package.json'), JSON.stringify(input.pkg.before, null, 2) + '\n')
git('add', '-A')
git('commit', '-q', '-m', 'base')
env.BASE = git('rev-parse', 'HEAD')
writeFileSync(join(repoDir, 'package.json'), JSON.stringify(input.pkg.after, null, 2) + '\n')
git('commit', '-q', '-am', 'head')
env.HEAD = git('rev-parse', 'HEAD')
cwd = repoDir
}
execFileSync('bash', ['-c', script], { env, cwd })
const model = /^model=(.*)$/m.exec(readFileSync(out, 'utf8'))[1]
rmSync(dir, { recursive: true, force: true })
return model
Expand Down Expand Up @@ -702,4 +724,56 @@ describe('claude-review model choice', () => {
assert.equal(choose('gorfednet/promptboi.com', ''), 'claude-sonnet-5-5')
assert.equal(choose('gorfednet/assess', ''), 'claude-opus-5-5')
})

describe('R0-only diffs', () => {
const opus = 'claude-opus-5-5'
const sonnet = 'claude-sonnet-5-5'
const pick = (files, pkg) => choose('gorfednet/ops', 'auto', { files, pkg })
const pkgOf = (deps, extra = {}) => ({ name: 'x', version: '1.0.0', ...extra, ...deps })
const dep = (v, section = 'dependencies') => ({ [section]: { 'left-pad': v, other: '^2.0.0' } })

it('picks Sonnet for docs, lockfiles and generated files in an Opus repository', () => {
assert.equal(pick(['docs/a.md', 'docs/notes/README.md', 'package-lock.json', 'src/x.generated.ts']), sonnet)
})
it('picks Sonnet for a patch bump in package.json and its lockfile', () => {
assert.equal(pick(['package.json', 'package-lock.json'], { before: pkgOf(dep('^1.2.3')), after: pkgOf(dep('^1.2.9')) }), sonnet)
})
it('keeps Opus for a minor or major bump', () => {
assert.equal(pick(['package.json'], { before: pkgOf(dep('^1.2.3')), after: pkgOf(dep('^1.3.0')) }), opus)
assert.equal(pick(['package.json'], { before: pkgOf(dep('^1.2.3')), after: pkgOf(dep('^2.0.0')) }), opus)
})
it('keeps Opus when only the range prefix changes (not a patch bump)', () => {
assert.equal(pick(['package.json'], { before: pkgOf(dep('~1.2.3')), after: pkgOf(dep('^1.2.3')) }), opus)
assert.equal(pick(['package.json'], { before: pkgOf(dep('^1.2.3')), after: pkgOf(dep('^1.2.4')) }), sonnet)
})
it('keeps Opus when a dependency moves between sections', () => {
const before = pkgOf({ dependencies: { esbuild: '^0.25.1' }, devDependencies: {} })
const after = pkgOf({ dependencies: {}, devDependencies: { esbuild: '^0.25.2' } })
assert.equal(pick(['package.json'], { before, after }), opus)
for (const [a, b] of [['dependencies', 'peerDependencies'], ['devDependencies', 'optionalDependencies'], ['dependencies', 'overrides'], ['dependencies', 'resolutions']]) {
assert.equal(pick(['package.json'], { before: pkgOf({ [a]: { x: '1.0.0' }, [b]: {} }), after: pkgOf({ [a]: {}, [b]: { x: '1.0.1' } }) }), opus, `${a} to ${b}`)
}
})
it('keeps Opus for a package.json edit that is not a version bump', () => {
assert.equal(pick(['package.json'], { before: pkgOf(dep('^1.2.3'), { scripts: { a: 'x' } }), after: pkgOf(dep('^1.2.4'), { scripts: { a: 'y' } }) }), opus)
assert.equal(pick(['package.json'], { before: pkgOf(dep('^1.2.3')), after: pkgOf(dep('^1.2.4'), { version: '1.0.1' }) }), opus)
})
it('keeps Opus for a mixed list (code beside docs)', () => {
assert.equal(pick(['docs/a.md', 'src/app.ts']), opus)
assert.equal(pick(['package-lock.json', '.github/workflows/ci.yml']), opus)
})
it('keeps Opus for rule, review and control files even though they are markdown', () => {
for (const p of ['REVIEW.md', 'CLAUDE.md', 'control/claude-home/rules/x.md', '.claude/agents/a.md', 'README.md', 'ship-bot/README.md', 'docs/verification-rules.md', 'docs/retired-checks.md', 'docs/content-guidelines.md', 'templates/REVIEW.site-footer.md', 'templates/CLAUDE.snippet.md', 'scripts/local-llm/out.md', 'janitor/PROMPT.md', 'janitor/SKILL.md', 'skills/x/SKILL.md', 'docs/skills/a.md', 'a/agents/b.md', 'x/rules/y.md', 'Docs/Verification-Rules.md', 'MEMORY.md', 'ship-bot/lib/notes.md', 'docs/programme-template.md']) assert.equal(pick([p]), opus, p)
})
it('fails closed: an empty, missing or unreadable list keeps Opus', () => {
assert.equal(pick([]), opus)
assert.equal(choose('gorfednet/ops', 'auto', {}), opus)
assert.equal(choose('gorfednet/ops', 'auto'), opus)
assert.equal(pick(['docs/{a => b}.md']), opus)
assert.equal(pick(['"docs/odd\\303\\251.md"']), opus)
})
it('never overrides an explicit model', () => {
assert.equal(choose('gorfednet/ops', 'claude-opus-5-5', { files: ['docs/a.md'] }), opus)
})
})
})
Loading