miyabi-agent-review 0.1.2

Miyabi Review Agent - Code review, quality scoring, and security scanning
docs.rs failed to build miyabi-agent-review-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

miyabi-agent-review

Code review, quality scoring (100-point scale), and security scanning agent for the Miyabi framework.

Crates.io Documentation License

πŸ“‹ Overview

miyabi-agent-review (ι€šη§°: めだまん) is an automated code review agent that performs comprehensive quality analysis on Rust codebases. It integrates cargo clippy, cargo check, cargo-audit, and test coverage tools to generate detailed quality reports with actionable recommendations.

Key Capabilities:

  • πŸ” Linting Analysis: Runs cargo clippy and scores based on warnings
  • πŸ› οΈ Type Checking: Runs cargo check and detects compilation errors
  • πŸ”’ Security Scanning: Uses cargo-audit to detect known vulnerabilities
  • πŸ“Š Coverage Analysis: Calculates test coverage (integrates with cargo-tarpaulin)
  • πŸ“ˆ 100-Point Scoring: Generates overall quality score with detailed breakdown
  • ⚠️ Escalation: Automatically escalates to Tech Lead if score < 60

πŸš€ Features

  • Automated Quality Scoring: 100-point scale based on:
    • Clippy warnings (100 - warnings Γ— 5)
    • Type errors (100 - errors Γ— 10)
    • Security vulnerabilities (dynamic scoring based on severity)
    • Test coverage (target: 80%+)
  • Detailed Issue Reporting: File, line, severity, and message for each issue
  • Recommendations: Actionable suggestions to improve code quality
  • Escalation Logic: Automatically escalates low-quality code (< 60 score) to human reviewers
  • JSON Output: Structured quality reports for CI/CD integration

πŸ“¦ Installation

Add to your Cargo.toml:

[dependencies]
miyabi-agent-review = "0.1.0"

Or install the CLI:

cargo install miyabi-cli

πŸ”§ Usage

As a Library

use miyabi_agent_review::ReviewAgent;
use miyabi_agent_core::BaseAgent;
use miyabi_types::{AgentConfig, Task, TaskType};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Configure agent
    let config = AgentConfig {
        device_identifier: "macbook-pro".to_string(),
        github_token: std::env::var("GITHUB_TOKEN")?,
        repo_owner: Some("your-org".to_string()),
        repo_name: Some("your-repo".to_string()),
        ..Default::default()
    };

    // Create agent
    let reviewer = ReviewAgent::new(config);

    // Create task
    let task = Task {
        id: "task-001".to_string(),
        title: "Review PR #123".to_string(),
        description: "Review code quality for feature implementation".to_string(),
        task_type: TaskType::Feature,
        ..Default::default()
    };

    // Execute review
    let result = reviewer.execute(&task).await?;

    // Check quality score
    if let Some(metrics) = result.metrics {
        if let Some(score) = metrics.quality_score {
            println!("Quality Score: {}/100", score);

            if score >= 80 {
                println!("βœ… Code approved for merge!");
            } else {
                println!("❌ Code needs improvement");
            }
        }
    }

    Ok(())
}

As a CLI Tool

# Review current directory
miyabi agent run review --task-id task-001

# Review specific path
cd /path/to/your/project
miyabi agent run review --task-id task-002

# With custom config
miyabi agent run review --task-id task-003 --config config.toml

πŸ“Š Quality Report Structure

{
  "score": 87,
  "passed": true,
  "issues": [
    {
      "issue_type": "Eslint",
      "severity": "Medium",
      "message": "unused variable `foo`",
      "file": "src/main.rs",
      "line": 42,
      "score_impact": 5
    }
  ],
  "recommendations": [
    "Fix clippy warnings to improve code quality",
    "Increase test coverage to at least 80%"
  ],
  "breakdown": {
    "clippy_score": 90,
    "rustc_score": 100,
    "security_score": 100,
    "test_coverage_score": 75
  }
}

πŸ”’ Security Scanning

The agent integrates cargo-audit to detect known security vulnerabilities:

# Install cargo-audit (required for security scanning)
cargo install cargo-audit

# Review will automatically run security checks
miyabi agent run review --task-id security-check

Security Scoring:

  • 100: No vulnerabilities detected
  • 80: Low severity vulnerabilities only
  • 60: Medium severity vulnerabilities
  • 40: High severity vulnerabilities
  • 0: Critical vulnerabilities found

πŸ§ͺ Testing

# Run all tests
cargo test --package miyabi-agent-review

# Run with output
cargo test --package miyabi-agent-review -- --nocapture

# Test specific functionality
cargo test --package miyabi-agent-review test_review_agent_creation

πŸ“ˆ Scoring Algorithm

Overall Score Calculation

Overall Score = Average(Clippy Score, Rustc Score, Security Score, Coverage Score)

Component Scores

  1. Clippy Score: 100 - (warnings Γ— 5) (minimum: 0)
  2. Rustc Score: 100 - (errors Γ— 10) (minimum: 0)
  3. Security Score: Dynamic based on vulnerability severity
  4. Coverage Score: Based on test coverage percentage (target: 80%+)

Approval Threshold

  • βœ… Approved: Score β‰₯ 80
  • ⚠️ Needs Work: Score 60-79
  • ❌ Escalated: Score < 60 (auto-escalates to Tech Lead)

πŸ—οΈ Architecture

ReviewAgent
  β”œβ”€β”€ run_clippy()           β†’ ClippyResult
  β”œβ”€β”€ run_rustc_check()      β†’ RustcResult
  β”œβ”€β”€ run_security_audit()   β†’ SecurityResult
  β”œβ”€β”€ calculate_coverage()   β†’ CoverageResult
  └── generate_quality_report() β†’ QualityReport

πŸ”— Dependencies

  • Core: miyabi-agent-core, miyabi-types, miyabi-core
  • Runtime: tokio, async-trait
  • Serialization: serde, serde_json
  • Utilities: chrono, regex, thiserror, tracing

πŸ“š Related Crates

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

πŸ“„ License

Licensed under the MIT License. See LICENSE for details.

πŸ”– Version History

  • v0.1.0 (2025-10-25): Initial release
    • Clippy integration
    • Rustc type checking
    • Security scanning (cargo-audit)
    • 100-point quality scoring
    • Escalation logic

Part of the Miyabi Framework - Autonomous AI Development Platform