Skip to content

AI-powered tool for generating Konveyor analyzer rules from migration guides

License

Notifications You must be signed in to change notification settings

konveyor-ecosystem/analyzer-rule-generator

Repository files navigation

Analyzer Rule Generator

Tests codecov Code style: black Imports: isort Python 3.9+ License

AI-powered tool for generating Konveyor analyzer rules from migration guides and documentation.

Overview

The Analyzer Rule Generator uses Large Language Models (LLMs) to automatically extract migration patterns from documentation and generate static analysis rules for the Konveyor analyzer. This helps migration teams quickly create comprehensive rulesets without manual authoring.

Features

  • Multiple Input Formats: URLs, Markdown files, plain text, ESLint codemods
  • Multi-Language Support: Java, TypeScript/React, Go, Python, CSS, and more
  • LLM-Powered Extraction: Automatically identifies migration patterns, complexity, and conditions
  • ESLint Rule Extraction: Direct extraction from ESLint codemod repositories (e.g., PatternFly pf-codemods) without LLM
  • Migration Complexity Classification: Automatic classification (trivial, low, medium, high, expert) for generated and existing rules
  • Konveyor Analyzer Format: Generates rules compatible with analyzer-lsp
  • Flexible LLM Support: OpenAI, Anthropic Claude, Google Gemini
  • Smart Provider Detection: Automatically uses Java or Builtin provider based on detected language
  • Pattern Detection: Extracts fully qualified class names, regex patterns, and file globs
  • Rule Validation: Syntactic and optional semantic validation to ensure rule quality
  • Test Data Generation: AI-powered generation of test applications for rule validation
  • CI Test Updater: Automated updates to go-konveyor-tests expectations

Quick Start

# Install dependencies
pip install -r requirements.txt

# Set up your LLM API key
export OPENAI_API_KEY="your-key-here"

# Generate rules from a migration guide
python scripts/generate_rules.py \
  --guide https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide \
  --source spring-boot-3 \
  --target spring-boot-4 \
  --output examples/output/spring-boot-4.0/migration-rules.yaml

Claude Code Skill

Interactive AI Assistant for Rule Generation

This project includes a Claude Code skill that provides an interactive AI assistant for generating migration rules. Instead of running command-line scripts manually, you can have a natural conversation with Claude to generate rules.

Using the Skill

konveyor-rules

The skill will guide you through:

  1. Providing the migration guide (URL or file)
  2. Specifying source and target frameworks
  3. Choosing LLM provider and options
  4. Reviewing generated rules and next steps

Benefits

  • Natural language interface - Describe what you need in plain English
  • Interactive guidance - Claude asks clarifying questions and provides suggestions
  • Automatic validation - Checks inputs and provides helpful error messages
  • Context-aware - Understands the project structure and suggests best practices

See .claude/skills/konveyor-rules/README.md for complete documentation.

How It Works

flowchart TD
    A[πŸ“„ Migration Guide] --> B[πŸ€– Generate Rules]
    B --> C[πŸ“‹ Konveyor Rules]
    C -.Optional.-> C1[βœ… Validate Rules]
    C1 --> C
    C --> D[πŸ€– Generate Test Data]
    D --> E[πŸ§ͺ Kantra Test]

    E -->|Pass| F[πŸ“¦ Submit to konveyor/rulesets]
    E -->|Fail| D

    F --> G[πŸ”¬ Run Analysis]
    G --> H[πŸ”„ Update CI Tests]
    H --> I[πŸ“¦ Submit to go-konveyor-tests]

    F -.Link PRs.-> I

    style A fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
    style B fill:#fff3e0,stroke:#f57c00,stroke-width:2px
    style C fill:#fff9c4,stroke:#f9a825,stroke-width:2px
    style C1 fill:#e1f5fe,stroke:#0277bd,stroke-width:2px,stroke-dasharray: 5 5
    style D fill:#fff3e0,stroke:#f57c00,stroke-width:2px
    style E fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
    style F fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
    style G fill:#ffebee,stroke:#c62828,stroke-width:2px
    style H fill:#fff3e0,stroke:#f57c00,stroke-width:2px
    style I fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
Loading

Complete Workflow:

  1. Generate Rules: LLM extracts migration patterns from documentation
    • Detects language (Java vs TypeScript/React/Go/Python)
    • For Java: Fully qualified class names and location types
    • For others: Regex patterns and file globs
  2. Validate Rules (Optional): Check rule quality before testing
    • Syntactic validation: Required fields, effort scores, pattern checks
    • Semantic validation: AI-powered description/pattern alignment
  3. Generate Test Data: AI creates test applications with violations
  4. Test Locally: Validate rules with Kantra
  5. Submit Rules: PR to konveyor/rulesets
  6. Run Analysis: Test rules on reference applications
  7. Update CI Tests: Automated update of go-konveyor-tests expectations
  8. Submit Tests: PR to go-konveyor-tests (linked with rules PR)

Examples

Java Migration (Spring Boot 3 to 4)

python scripts/generate_rules.py \
  --guide https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide \
  --source spring-boot-3 \
  --target spring-boot-4 \
  --output examples/output/spring-boot-4.0/migration-rules.yaml

TypeScript/React Migration (PatternFly v5 to v6)

Option 1: From ESLint Codemods (Recommended - No LLM required)

python scripts/generate_rules.py \
  --eslint-repo https://github.com/patternfly/pf-codemods.git \
  --source patternfly-v5 \
  --target patternfly-v6 \
  --output examples/output/patternfly-v6/

Extracts rules directly from PatternFly's official ESLint codemods. Advantages:

  • No LLM API costs
  • High-quality rules based on official codemods
  • Includes code examples and documentation links
  • Extracts 91 rules from 106 ESLint rules (86% coverage)
  • Supports: prop renames/removals, import changes, component renames, TypeScript types, markup warnings

Option 2: From Migration Guide (LLM-based)

python scripts/generate_rules.py \
  --guide https://www.patternfly.org/get-started/upgrade/ \
  --source patternfly-v5 \
  --target patternfly-v6 \
  --follow-links \
  --max-depth 1 \
  --output examples/output/patternfly-v6/migration-rules.yaml

Generates 41 comprehensive rules with hybrid detection (nodejs + builtin providers) for eliminating false positives.

Example Output

Java Provider Rules

- ruleID: spring-boot-3-to-spring-boot-4-00001
  description: Replace deprecated Spring Boot 3 annotations
  effort: 3
  category: mandatory
  labels:
    - konveyor.io/source=spring-boot-3
    - konveyor.io/target=spring-boot-4
  when:
    java.referenced:
      pattern: org.springframework.web.bind.annotation.RestController
      location: ANNOTATION
  message: "Review Spring Boot 4.0 migration requirements for REST controllers"
  links:
    - url: "https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide"
      title: "Spring Boot 4.0 Migration Guide"
  migration_complexity: low

Builtin Provider Rules (TypeScript/React/Go/Python)

- ruleID: patternfly-v5-to-patternfly-v6-00001
  description: isDisabled should be replaced with isAriaDisabled
  effort: 3
  category: potential
  labels:
    - konveyor.io/source=patternfly-v5
    - konveyor.io/target=patternfly-v6
  when:
    builtin.filecontent:
      pattern: isDisabled\s*[=:]
      filePattern: '*.{tsx,jsx,ts,js}'
  message: "The isDisabled prop has been renamed to isAriaDisabled for better accessibility"

Migration Complexity Classification

The tool automatically classifies migration complexity for generated rules and provides a script to classify existing rulesets.

Complexity Levels

  • trivial (95%+ AI success): Namespace changes, mechanical fixes (e.g., javax β†’ jakarta)
  • low (80%+ AI success): Simple API equivalents, straightforward replacements
  • medium (60%+ AI success): Requires context understanding, moderate refactoring
  • high (30-50% AI success): Architectural changes, complex migrations
  • expert (<30% AI success): Custom implementations, likely needs human review

Classifying Existing Rulesets

Add complexity classifications to existing Konveyor analyzer rulesets:

# Preview classifications (dry run)
python scripts/classify_existing_rules.py \
  --ruleset examples/output/spring-boot/migration-rules.yaml \
  --dry-run

# Apply classifications
python scripts/classify_existing_rules.py \
  --ruleset examples/output/spring-boot/migration-rules.yaml

# Batch process multiple rulesets
bash scripts/batch_classify_rulesets.sh /path/to/rulesets

The classifier analyzes:

  • Pattern descriptions and messages
  • Rule effort scores
  • When condition complexity
  • Migration keywords and indicators

See docs/guides/migration-complexity.md for complete documentation.

Rule Viewer

🌐 View Rules Online - Interactive web viewer for any Konveyor ruleset

Load and explore rules from:

  • GitHub URLs (paste any rule file URL)
  • Local YAML files (drag & drop)
  • Share with ?url= parameter

See Rule Viewers Guide for more options.

Documentation

Getting Started:

Guides:

Technical Reference:

Integration with Konveyor

Generated rules and tests integrate with:

Requirements

  • Python 3.9+
  • LLM API access (OpenAI, Anthropic, or Google)

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Code Quality Standards

This project enforces code quality through automated tooling:

  • Black for code formatting
  • isort for import sorting
  • flake8 for linting
  • pytest for testing (80%+ coverage required)

Quick Setup for Contributors

# Install dev dependencies
pip install black isort flake8 pre-commit

# Install pre-commit hooks (runs checks automatically)
pre-commit install

# Run checks manually
black src/ scripts/ tests/
isort src/ scripts/ tests/
flake8 src/ scripts/ tests/
pytest

All pull requests are automatically checked by GitHub Actions for code quality and test coverage.

License

Apache License 2.0

Related Projects

About

AI-powered tool for generating Konveyor analyzer rules from migration guides

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •