Diff quality analyzer

From paulpas/agent-skill-router · View interactive version

Diff quality analyzer is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Implements intelligent diff quality analyzer with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense

How to use this skill

Skill file

Diff Quality Analyzer

Orchestrates intelligent skill selection and execution for diff quality analyzer workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.

TL;DR Checklist

┌───────────────────────────────────────────────────────────────────────────────┐

│ Orchestration Flow │

└───────────────────────────────────────────────────────────────────────────────┘

User Request

↓

┌─────────────────┐

│ Parse Request │

│ & Extract │

│ Features │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Evaluate Available Skills │

│ │

│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │

│ │ Skill A │ │ Skill B │ │ Skill C │ │

│ │ - Match Score│ │ - Match Score│ │ - Match Score│ │

│ │ - Confidence │ │ - Confidence │ │ - Confidence │ │

│ │ - History │ │ - History │ │ - History │ │

│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │

│ │ │ │ │

│ └─────────────────┴─────────────────┘ │

│ ↓ │

│ Select Best Skill │

└─────────────────────────────────────────────────────────────────────┘

↓

┌─────────────────┐

│ Execute Skill │

└────────┬────────┘

↓

┌─────────────────┐

│ Handle Result │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Error Handling & Fallback │

│ │

│ Success? ────────► Return Result │

│ │

│ Fail? ────────┐ │

│ ↓ │

│ ┌──────────────────────────────────────────────────────────┐ │

│ │ Fallback Chain │ │

│ │ │ │

│ │ 1. Retry with adjusted parameters │ │

│ │ 2. Try Alternative Skill (if available) │ │

│ │ 3. Defer to Human Operator (if critical) │ │

│ │ 4. Log & Return Error │ │

│ └──────────────────────────────────────────────────────────┘ │

└─────────────────────────────────────────────────────────────────────┘

When to Use

Use this skill when:

When NOT to Use

Avoid this skill for:

Core Workflow

  1. Parse and Analyze Request - Extract intent, entities, and constraints from user input.

Checkpoint: All required parameters must be present and in valid format before proceeding.

  1. Score Available Skills - Calculate match scores using multi-factor algorithm:

Checkpoint: Skip to fallback if no skill scores above threshold.

  1. Select Optimal Skill - Choose skill with highest score that meets minimum confidence.

Checkpoint: Verify skill has not been disabled or deprecated.

  1. Execute with Fallback - Run skill execution wrapped in retry and fallback logic.

Checkpoint: Log all execution attempts for audit trail.

  1. Return or Fallback - Either return successful result or apply fallback chain:

Checkpoint: Record outcome with timing and confidence metadata.

Implementation Patterns

Pattern 1: Skill Selection Logic

def route_diff_analysis(diff_content: str, analysis_scope: List[str]) -> Dict:
    """Route diff content to appropriate quality analysis modules.
    
    Implements Law 2 (Parse at boundary) by validating diff format first.
    Uses multi-factor scoring to pick the best analyzer for each changed file.
    """
    if not diff_content or not diff_content.strip():
        raise ValueError("Diff content cannot be empty")
        
    parsed_diff = parse_unified_diff(diff_content)
    if not parsed_diff.files:
        return {"status": "empty", "analyzers": []}
        
    routing_plan = []
    for file_path, changes in parsed_diff.files.items():
        required_analyzers = []
        
        # Language-specific routing
        if file_path.endswith(('.py', '.js', '.ts', '.go')):
            required_analyzers.append("complexity-analyzer")
            
        # Security-sensitive routing
        if "security" in analysis_scope or "auth" in file_path.lower():
            required_analyzers.append("security-scanner")
            
        # Size-based routing
        if changes.added_lines > 50 or changes.removed_lines > 50:
            required_analyzers.append("test-coverage-checker")
            
        routing_plan.append({
            "file": file_path,
            "analyzers": required_analyzers,
            "confidence": 0.95 if required_analyzers else 0.0,
            "change_metrics": {
                "added": changes.added_lines,
                "removed": changes.removed_lines
            }
        })
        
    return {"routing_plan": routing_plan, "total_files": len(parsed_diff.files)}

Pattern 2: Execution with Fallback

def execute_analysis_pipeline(routing_plan: Dict, fallback_analyzers: Dict) -> Dict:
    """Execute diff quality analysis with per-analyzer fallback chains.
    
    Implements Law 4 (Fail Fast) by halting on critical security findings.
    Implements Law 3 (Atomic Predictability) by returning immutable result dicts.
    """
    results = []
    for route in routing_plan.get("routing_plan", []):
        file_results = []
        for analyzer_name in route["analyzers"]:
            try:
                analyzer = get_analyzer_module(analyzer_name)
                score = analyzer.run(route["file"])
                file_results.append({
                    "analyzer": analyzer_name,
                    "score": score,
                    "status": "passed",
                    "latency_ms": analyzer.get_latency()
                })
            except AnalyzerTimeoutError:
                # Fallback: try lightweight static check
                fallback = fallback_analyzers.get(analyzer_name, "basic-linter")
                score = get_analyzer_module(fallback).run(route["file"])
                file_results.append({
                    "analyzer": fallback,
                    "score": score,
                    "status": "fallback",
                    "latency_ms": get_analyzer_module(fallback).get_latency()
                })
            except CriticalSecurityError:
                # Law 4: Fail immediately on critical issues
                return {
                    "status": "blocked",
                    "file": route["file"],
                    "reason": "critical_vulnerability",
                    "severity": "high"
                }
                
        results.append({"file": route["file"], "analysis": file_results})
        
    return {
        "pipeline_status": "completed",
        "file_results": results,
        "aggregate_score": calculate_weighted_average(results),
        "execution_timestamp": time.time()
    }

MUST DO

MUST NOT DO

TL;DR Checklist

TL;DR for Code Generation

Output Template

When applying this skill, produce:

  1. Selected Skills - List of skill names with confidence scores
  2. Selection Rationale - Why each skill was chosen (match score, history, availability)
  3. Execution Plan - Order of execution with dependencies
  4. Fallback Strategy - Which fallback skills will be tried and in what order
  5. Risk Assessment - Any potential failure points and their impact
  6. Timing Estimates - Expected latency including fallback scenarios


Constraints

MUST DO

MUST NOT DO

Live References

Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.

Related Skills

| Skill | Purpose |

|

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.