SpECTRE Code Review
Arguments: $ARGUMENTS
Current branch: !git branch --show-current
Perform a thorough code review of SpECTRE changes. Follow every step below
precisely. The full SpECTRE code rules reference (provide to review agents):
!tail -n +5 .claude/rules/Cxx.md
Step 1: Parse Arguments & Acquire Diff
Parse $ARGUMENTS:
- Number present (e.g.
1234): PR mode. Fetch with:
gh pr diff <N> --repo sxs-collaboration/spectre and
`gh pr view <N> --repo sxs-collaboration/spectre --json
title,body,headRefName,baseRefName`
- No number: Local mode. Use
git diff develop...HEADfor committed
changes, plus git diff and git diff --cached for uncommitted changes. If
no diff, fall back to git diff HEAD~1.
- "clang-tidy" present: Enable the clang-tidy step.
- "coverage" present: Enable the targeted code coverage step.
Save the diff. Extract the list of changed files categorized by type (C++
.cpp/.hpp/.tpp, Python .py, CMake CMakeLists.txt, other).
Create a task list tracking all review steps.
Step 2: Formatting Checks (run in parallel)
C++ (clang-format)
For each changed C++ file:
- Parse diff hunk headers (
@@ +START,COUNT @@) to get changed line ranges - Expand each range by +/-4 lines (clamped to file bounds)
- Run:
clang-format -style=file --lines=START:END [--lines=...] FILEPATH - Diff against original. Collect any formatting differences.
Python (black + isort)
For each changed .py file (excluding external/):
black --check --diff FILEPATH
isort --check-only --diff FILEPATH
Step 3: CI Pre-Checks on Changed Files (run in parallel)
Check each changed file for issues that SpECTRE CI (tools/FileTestDefs.sh,
tools/CheckFiles.sh) will flag. Only check lines/patterns introduced in the
diff, not pre-existing issues.
All files: lines >80 chars (excluding URLs, NOLINT, #include, \snippet,
\image, \link, import); missing MIT license header; no final newline; tabs;
trailing whitespace; carriage returns
C++ files (.cpp/.hpp/.tpp):
- Missing
#pragma oncein headers #include <iostream>-> useParallel/Printf/Printf.hpp#include <lrtslock.h>-> use<converse.h>std::enable_if-> userequiresnamespace _details-> use_detailstruct TD;/class TD;(debug artifacts).ckLocal()->Parallel::local().ckLocalBranch()->Parallel::local_branch()return Py_None;->Py_RETURN_NONE- Text after
/*!on same line Lsabbreviation -> useList- Doxygen (
///or/*!) in.cppfiles (only use//comments in cpp) - Top-level
conston value parameters in function declarations (.hpp) ->
remove const from the declaration (keep in definition)
- TODO/FIXME comments (not allowed)
Test files:
TEST_CASEinstead ofSPECTRE_TEST_CASEApprox(instead ofapprox
CMake: New C++ files in a directory must be listed in that directory's
CMakeLists.txt; removed files must be removed; entries should be alphabetical.
LLM Comments: Identify comments that seem like notes from a coding agent
during its thinking process.
Include Order (C++ files in diff)
Verify:
- (Tests)
"Framework/TestingFramework.hpp"first, then blank line - (
.cppwith.hpp) Corresponding.hpp, then blank line - STL/external
<headers>alphabetical - Blank line
- SpECTRE
"headers"alphabetical
Commit Messages (local mode only)
Check no commit starts with (case-insensitive): fixup, wip, fixme, deleteme,
rebaseme, testing, rebase.
Step 4: Code Review (2 Parallel Agents)
Launch 2 parallel agents. Provide each with the full diff and the
SpECTRE code rules reference shown above.
Agent A: Style, Patterns & Idioms
Instructions for the agent:
- Check the diff against every rule in Banned Patterns and Style Rules
- Check for Prefer-Library Patterns (manual tensor loops that should use
EagerMath)
- When you spot a suspicious pattern NOT in the checklist (e.g., a manual matrix
operation, a loop that looks like it reimplements an existing utility), use
grep -r in src/DataStructures/Tensor/EagerMath/, src/DataStructures/,
src/NumericalAlgorithms/, or src/Utilities/ to find an existing utility
- Only flag issues in lines that the diff introduces (not pre-existing code)
- For each finding:
file:line, severity (critical/important/suggestion),
explanation
Agent B: Bugs, Logic, Tests & Documentation
Instructions for the agent:
- Read each changed file in full (not just the diff) to understand surrounding
context
- Look for: logic errors, off-by-one, uninitialized variables, NaN handling,
race conditions, incorrect template instantiations, virtual inheritance issues
(most-derived must init virtual bases)
- Check that new/changed public API in
.hppfiles has Doxygen documentation - Check that new source files have corresponding tests (
src/Foo/Bar.hpp->
tests/Unit/Foo/Test_Bar.cpp)
- Check that new
.cpp/.hppfiles are listed in theirCMakeLists.txt - Only flag issues introduced by the diff
- For each finding:
file:line, severity, explanation - Check for potentially problematic floating point math like:
- Catastrophic cancellation: subtraction of nearly-equal values
(a - b where a ~ b).
- Division by near-zero: a denominator that approaches zero for certain
inputs (e.g., near coordinate boundaries, poles, or special points).
- Naive summation of many terms: summing a long list of floating-point
numbers accumulates round-off.
- Unstable polynomial evaluation: monomial form
(a*x^3 + b*x^2 + c*x + d), instead use Horner's method,
evaluate_polynomial() from src/Utilities/Math.hpp
- Numerically unstable quadratic formula: the standard formula
(-b +/- sqrt(b^2 - 4ac)) / 2a loses precision.
- Accumulation of terms with widely varying magnitudes: adding a tiny
correction to a large value drops the correction entirely.
- Make sure the code always uses
atan2instead ofatan,log1p(x)instead
of log(1+x), expm1(x) instead of exp(x)-1, hypot(x,y) instead of
sqrt(x*x+y*y).
Step 5: clang-tidy (if requested, run in parallel)
If "clang-tidy" was in arguments:
- Check for
build/compile_commands.json. If missing, report that clang-tidy
requires a configured build directory and skip.
- For each changed
.cppfile:clang-tidy -p build/ FILEPATH 2>&1 - Filter output to only warnings on lines in the diff.
Step 6: Code Coverage (if requested, run in parallel)
If "coverage" was in arguments:
Read references/coverage-steps.md and follow those instructions exactly.
Step 7: Self-Review Prune
Combine all findings from steps 2-6. Review each finding and REMOVE only clear
non-issues:
- False positives (pattern match that isn't the actual flagged issue)
- Pre-existing issues not introduced by this diff, except missing includes
- Issues suppressed by
// NOLINT(...)comments - Exact duplicates between agents or between agents and formatting/CI checks
Assign each remaining finding a confidence score (0-100). Remove findings
below 50. Keep all findings scoring 50 or above -- err on the side of including
borderline issues rather than missing real ones.
Step 8: Lightweight Model Critique
Spawn an agent using the cheapest available model (Claude Code: haiku;
Codex: gpt-5.4-mini). Provide it with:
- The SpECTRE code rules reference (from Step 1)
- The list of pruned findings (with scores)
- A summary of what the diff does
Ask the critique agent to:
- Score each finding 0-100 for "is this a real, actionable issue?"
- Flag any remaining false positives with reasoning
- Note if important issues seem to be missing
- Return scores and feedback
After receiving the critique agent's feedback:
- Remove findings scored < 40
- Downgrade severity (e.g., important -> suggestion) for findings scored
40-60
- Consider adding issues the critique agent suggested (verify them first)
Step 9: Final Report
Read references/report-template.md and present the report in that format.