Command: ruthless-code-reviewer
Relevant source files
The following files were used as context for generating this wiki page:
The ruthless-code-reviewer is a specialized command and persona designed for the swe-term environment. Its primary purpose is to provide high-leverage, critical evaluations of code changes, focusing on correctness, safety, and operational simplicity. It operates as part of the project's agentic framework, often serving as a final quality gate for automated code generations or manual submissions.
The command adheres to a strict "Decision Hierarchy" where correctness, safety, and observability take precedence over performance and elegance. It utilizes structured code analysis tools, such as ast-grep and semgrep, to perform deep structural audits rather than relying on simple regex-based searches.
Sources: AGENTS.md:1-25, .agents/commands/ruthless-code-reviewer.md
Architectural Principles and Decision Authority
The reviewer operates under a specific set of principles that prioritize system stability and maintainability. When reviewing code, the agent resolves conflicts using a prioritized hierarchy.
| Priority | Principle | Description |
|---|---|---|
| 1 | Correctness | Do what was asked; prioritize user intent. |
| 2 | Safety | Minimize blast radius; avoid irreversible damage. |
| 3 | Observability | Ensure failures are visible and diagnosis is cheap. |
| 4 | Simplicity | Systems must be operable at 3am by humans. |
| 5 | Maintainability | Code must be readable and explainable in six months. |
Sources: AGENTS.md:28-48
Systems Preflight Checklist
Before a review outcome is finalized, the system undergoes a mandatory preflight check to evaluate the impact of the proposed changes.
The diagram shows the internal logic flow an agent must follow before prescribing changes or approving a review.
Sources: AGENTS.md:52-70
Code Analysis Integration
The command leverages external extensions and internal prompt configurations to perform its duties. Specifically, it integrates with ast-grep for structural analysis and swe_distiller for content extraction and safety verification.
Structural Analysis with ast-grep
The reviewer is configured to use ast-grep rules to identify complex code patterns. This avoids the limitations of regex by understanding the AST (Abstract Syntax Tree).
- Atomic Rules: Matches nodes by
kindorpattern. - Relational Rules: Matches nodes
insideorhasspecific parent/child relationships. - Composite Rules: Combines multiple conditions using
all,any, ornot.
Sources: src/prompts.yaml:65-100
Safety and Quality Gates
When code is extracted or reviewed, it passes through safety checks to ensure the output is consistent with the source and does not introduce significant "noise" or dangerous deletions.
The diagram represents the safety verification logic implemented in the extraction module.
Sources: extensions/swe_distiller/src/extraction/checks.rs:43-69, extensions/swe_distiller/src/extraction/llm.rs:48-60
Implementation Detail: Safety Logic
The project uses Rust-based logic to verify if a candidate code block (or extracted text) is safe to accept. The passes_safety_checks function compares the original and candidate based on token overlap and structural consistency.
// extensions/swe_distiller/src/extraction/checks.rs:43-69
pub fn passes_safety_checks(original: &str, candidate: &str) -> bool {
let ow = word_count(original) as f32;
let cw = word_count(candidate) as f32;
if ow > 0.0 && (cw < ow * 0.75 || cw > ow * 1.35) {
return false;
}
let ol = link_count(original) as f32;
let cl = link_count(candidate) as f32;
if ol >= 6.0 && cl < ol * 0.55 {
return false;
}
// ... heading overlap checks ...
true
}
Sources: extensions/swe_distiller/src/extraction/checks.rs:43-69
Response Modes
The ruthless-code-reviewer switches between distinct modes depending on the current phase of the development lifecycle:
- Mode: Diagnose: Focuses on read-only probes and minimal, high-signal questions to narrow hypotheses.
- Mode: Review: Focuses on correctness, clarity, safety, and operability. Feedback is specific and Socratic.
- Mode: Execute: Produces safe, reproducible actions with a preference for dry-runs.
Sources: AGENTS.md:89-115
Conclusion
The ruthless-code-reviewer serves as the primary technical gatekeeper within the swe-term repository. By combining a strict decision hierarchy with structural AST analysis and quantitative safety checks (word counts, link densities, and noise scores), it ensures that code changes maintain the project's standards for safety and operational simplicity. Its integration with tools like ast-grep and the swe_distiller pipeline allows it to perform automated, high-fidelity reviews that go beyond surface-level syntax checking.