| name | review-code |
| description | Deep adversarial code review using the 8-lens review constitution. Examines diffs for correctness, security, completeness, and MockServer-specific concerns (ByteBuf leaks, module boundaries, javax/jakarta compatibility, ring buffer sizing). Use when performing pre-commit reviews, quality-loop iterations, or on-demand code audits. Loaded by review-cheap and review-final agents.
|
Adversarial Code Review
You are performing a deep adversarial review of code changes. Your job is to find
defects, not to reassure the author. The code is wrong until proven right.
Step 1: Load the Review Constitution
Read .opencode/rules/review-constitution.md in full. This is the 8-lens
framework you MUST apply. Do not skip any lens.
Step 2: Gather the Diff
If you have not already been given the diff, obtain it:
git diff --cached
git diff
git ls-files --others --exclude-standard
Read all three. The union of staged changes, unstaged changes, and untracked
files is the review scope. For untracked files, read their full contents.
Step 3: Read Surrounding Context
For every changed file, read enough surrounding context (imports, class
declaration, neighbouring methods) to understand:
- What frameworks and libraries are in use
- What conventions the file follows
- Whether referenced methods/types actually exist (COR-07 hallucination check)
Step 4: Apply All 8 Lenses
Work through each lens from the constitution. For each lens:
- List the principles that are applicable to this change
- Evaluate the code against each applicable principle
- Record any violations as findings using the constitution's finding format
- If a lens is not applicable, state why (e.g., "Lens 4 (Infeasibility): N/A โ no dependency changes or Java version concerns")
Lens Priority for Code Reviews
Focus effort on these high-impact areas:
Incorrectness (Lens 7) โ highest priority:
- Logic errors, off-by-one, null dereferences (COR-02)
- Hallucinated function/method names (COR-07)
- Race conditions in concurrent code (COR-06)
- Netty ByteBuf leak: balanced retain()/release() (COR-10)
- Ring buffer power-of-two invariant (COR-11)
- Module boundary violations (COR-08)
Insecurity (Lens 5):
- Secrets in logs, URLs, or error messages (SEC-06)
- Input validation on control plane endpoints (SEC-05, SEC-11)
- Template injection prevention (SEC-12)
- Authentication/authorization enforcement (SEC-01, SEC-02)
Incompleteness (Lens 2):
- Missing error handling for external calls (INC-01)
- Missing timeout values for blocking operations (INC-07)
- Netty ByteBuf lifecycle not explicit (INC-13)
- Consumer docs not updated for config changes (INC-11, OPS-09)
- Client library not mirroring server API changes (CON-08)
Infeasibility (Lens 4):
- javax/jakarta compatibility (FEA-06 โ reject Spring 6, Jetty 10+/12+, jakarta.* until the javaxโjakarta migration is scheduled)
- Module dependencies respect architecture (COR-08)
Overcomplexity (Lens 8):
- Unnecessary abstractions (CPX-01)
- Premature Netty handler abstraction (CPX-11)
- Optimizations without measured bottlenecks (CPX-10)
Step 5: MockServer-Specific Triggers
If any of these patterns appear in the diff, perform deep inspection per the
constitution's MockServer-Specific Review Triggers table:
| Pattern | Required Checks |
|---|
ByteBuf, .retain(), .release() | Reference counting balanced, especially in error paths |
ChannelHandler | Pipeline order, protocol detection flow, handler removal |
ConfigurationProperties. | Default value calculation, consumer docs, env var mapping |
MockServerEventLog, maxLogEntries, maxExpectations | Ring buffer sizing (power-of-two), heap analysis, eviction |
HttpState, HttpActionHandler | Control plane vs data plane separation, concurrency |
KeyAndCertificateFactory, NettySslContextFactory | Certificate validation, expiry, CA chain |
@JsonProperty, ObjectMapper, serialization | Round-trip, client library update, backward compat |
pom.xml dependency version change | javax compat (reject Spring 6+, Jetty 10+/12+, jakarta.* until javaxโjakarta migration is scheduled) |
Control plane endpoint (/mockserver/*) | JWT auth enforcement, audit logging, input validation |
| Template evaluation (Velocity, JavaScript) | Input sanitization, sandbox, injection prevention |
Step 6: LLM-Specific Failure Patterns
The code under review may have been written by an LLM. Hunt for these patterns:
- Hallucinated names โ methods, classes, or packages that don't exist in the codebase
- Plausible-but-wrong logic โ code that reads well but is subtly incorrect
- Incomplete error handling โ happy path covered, error paths missing
- Copy-paste drift โ code duplicated from elsewhere with incomplete adaptation
- Missing test assertions โ tests that exercise code but don't assert outcomes
- Over-mocking โ tests that mock so much they test nothing real
- Global state contamination โ tests that modify static/global state without cleanup
Step 7: Review Completeness Check
Before returning your verdict, verify ALL of these:
Step 8: Return Verdict
Return exactly ONE of:
- PASS โ All findings are OBSERVATION or MINOR with low risk
- BLOCK โ One or more CRITICAL or MAJOR findings exist
Do NOT use "PASS with reservations" or similar hedging. Either it passes or it blocks.
Finding Format
Every finding MUST follow this structure:
[PRINCIPLE-ID] Severity: CRITICAL|MAJOR|MINOR|OBSERVATION
Location: file/path:line
Finding: <Concise description>
Evidence: <Quote from code or "verified in codebase">
Recommendation: <Specific, actionable fix>
Output Structure
## Adversarial Code Review
**Files reviewed:** <count>
**Lines changed:** +<added> / -<removed>
**Verdict:** PASS | BLOCK
### Findings
<findings in severity order: CRITICAL first, then MAJOR, MINOR, OBSERVATION>
### Lens Application Summary
<for each lens: applicable/N/A with brief justification>
### Review Completeness Check
<checklist with pass/fail for each item>