chore: a rule for fast code, public pages first, with one detector shared by the author and reviewer gates
Back to our planWe have no written rule for keeping the site fast, so speed depends on whoever writes the change remembering it. This adds a short rule to the places workers and reviewers already read, and one file-based detector that tells both of them when a change can affect speed, the same way the browser-test gate already works.
Owner's direction (summarized; given in a voice session on 2026-11-08): the public site must stay fast, admin second; guardrails must fire mechanically, not rest on principles alone; the rule goes where workers and reviewers find it, and the author and reviewer gates share one file-based detector like the browser-test gate. This is a policy change the owner asked for.
Problem
docs/guidelines/development.mdcovers native first, DRY and visual QA, but nothing on speed. The self-review skill has a generic "Efficiency" list, anddocs/roles/qa-reviewer.mdhas a stale "Performance" list with a fixed score target that nothing measures.- Nothing tells an author or a reviewer that a diff touches something that can slow a public page (rendering mode, data fetching, client JavaScript, images, dependencies). The browser-test gate shows the pattern that works here: a file check, no model, the same rules for both sides, and a reviewer verdict that measures it.
Proposed fix
- The rule (principles only). A new section in
docs/guidelines/development.md, "Fast by default, public pages first". Write it as principles, with no numbers and no examples from current work:- Public pages are rendered once and served many times: keep them static or revalidated, and refresh them on save through the existing revalidate hooks. Request-time APIs (cookies, headers, search params, draft mode) on a public page need a reason.
- Ask the database only for what the page shows:
select, a smalldepth, alimit, indexes on what is filtered or sorted, no query inside a loop, independent reads run together. - Ship less JavaScript: server components by default, client components as small leaves, heavy and rarely used UI loaded on demand, no large library for a small job.
- Images only through the UI kit's
Media, sized for where they show; only the image that's visible first loads early. - Measure, don't guess: the budgets come from a measured baseline, and a change that moves a number says why in the PR.
- Admin follows the same rules, after the public pages.
Link it from the self-review "Efficiency" list, from
write-code(worker) and frompr-reviewanddocs/roles/qa-reviewer.md(reviewer). Replace the qa-reviewer's fixed score target with a pointer to the budgets. Keepvercel-react-best-practicesas the detailed reference; the new section says what is ours and points to it for the rest.
- The shared detector.
scripts/perf-change.mjs, built likescripts/ui-change.mjsand on the sameclassifyFilefromscripts/behavior-change.mjs(comment-only and formatting-only edits, tests and docs never count). For each changed file it returns which checks are due:page: what a public page renders or how (src/app/(frontend)/**, any module'sui/,data/anduse-cases/,src/platform/ui|richtext|theme/**,src/proxy.ts,next.config.*, the image settings). ReuseisUiPathfor the UI part; don't copy its patterns.bundle: what ships to the browser (client components,package.jsonand lockfile dependency changes,next.config.*).query: how the database is asked (src/modules/*/data/**,src/modules/*/cms/**,src/platform/payload/**,src/payload.config.ts,src/migrations/**). A small CLI prints the same result for a local diff, so an author sees it before pushing.
- The author gate. A CI step in
.github/scripts/perf-gate.mjsreads the PR's files, calls the detector and writes a summary line to the job log in the same greppable form as the browser-test gate (perf-gate: page=run bundle=skip query=run reason="…"), plusGITHUB_OUTPUTvalues the budget jobs read to decide whether to run. A push tomainalways runs them. If the gate can't decide, it runs everything. Share the PR-reading, output and summary helpers withe2e-gate.mjsby moving them to one place, not by copying (guard rail 1). Inself-review, the author runs the detector's CLI and, for each check that is due, applies the rule and runs that check locally. - The reviewer gate. A new section in
pr-review(after "2d. Check the browser tests"): read the perf-gate summary, confirm the rule against the flagged files, and give each firing a verdict in the review: right, false alarm, or missed (a speed change the detector didn't flag, so its paths get widened). A change to the detector, the gate or a budget file is listed under Policy changes. - No way past a red budget by a sentence: the fix is to make the page lighter, or to change the budget in the same PR with the reason, which the reviewer checks against the baseline.
Acceptance criteria
- Not done:
development.mdhas the "Fast by default" section, principles only, and the file stays under 250 lines - Not done:
write-code,self-review,pr-reviewanddocs/roles/qa-reviewer.mdpoint to it; the stale fixed score target is gone - Not done:
scripts/perf-change.mjsexists, built onclassifyFileandisUiPath, with tests written first covering each category, comment-only and formatting-only edits, renames out of a counted path, and tests/docs not counting - Not done:
.github/scripts/perf-gate.mjsprints the summary line and sets outputs; on a push tomainand on any error it runs everything; tests cover each branch - Not done: The PR-reading and summary helpers are shared with
e2e-gate.mjs, not duplicated (jscpd passes) - Not done:
pr-reviewhas the performance section with the three verdict words; the detector, gate and budget files are listed as policy-change files - Not done:
npm run agent-context -- --writeis run so the generated rule copies match, andAgent contextpasses
Files likely touched
docs/guidelines/development.md, .agents/skills/write-code/SKILL.md, .agents/skills/self-review/SKILL.md, .agents/skills/pr-review/SKILL.md, docs/roles/qa-reviewer.md, scripts/perf-change.mjs (+ test), .github/scripts/perf-gate.mjs (+ test), .github/scripts/e2e-gate.mjs (helpers moved out), .github/workflows/ci.yml (the gate step only), .claude/rules/generated/ (regenerated).
Must not touch
The budget jobs themselves (they come in their own issues); scripts/ui-change.mjs rules (reuse them, don't change what counts as UI); the main ruleset.
Open questions
- Should the gate step live in its own job, or as the first step of each budget job? Pick whichever keeps the job always reporting a result (a skipped job counts as passing), and record the choice.
- A "performance" area label doesn't exist in
.github/label-policy.json; propose it only if the sweep needs to find this work, as a separate change.