Module fixer
connectorautomation/fixer
Ballerina AI Code Fixer
An intelligent AI-powered tool that automatically detects and fixes compilation errors in Ballerina projects using advanced language models.
š Overview
The Ballerina AI Code Fixer is a sophisticated tool designed to streamline the development process by automatically identifying and resolving compilation errors in Ballerina codebases. Leveraging the power of Anthropic's Claude AI, it provides intelligent, context-aware fixes that maintain code quality and follow Ballerina best practices.
⨠Key Features
- AI-Powered Error Resolution: Uses Anthropic's Claude Sonnet 4 for intelligent code analysis and fixing
 - Interactive Workflow: Step-by-step confirmation for each proposed fix
 - Automatic Backup: Creates backup files before applying changes
 - Iterative Fixing: Continues fixing until all compilation errors are resolved
 - Progress Tracking: Detailed feedback and iteration summaries
 - Error Analysis: Comprehensive parsing of Ballerina compilation errors
 - Multi-file Support: Handles complex projects with multiple error sources
 
š Prerequisites
- Ballerina 2201.12.7 or later
 - Valid Anthropic API key
 - Internet connection for AI model access
 
āļø Configuration
Environment Setup
- 
API Key Configuration: Set up your Anthropic API key in
Config.toml:[fixer.fixer] apiKey="your-anthropic-api-key-here" maxIterations=10 - 
Environment Variable (Alternative):
export ANTHROPIC_API_KEY="your-anthropic-api-key-here" 
Configuration Parameters
| Parameter | Default Value | Description | 
|---|---|---|
apiKey | Required | Your Anthropic API key for Claude access | 
maxIterations | 10 | Maximum number of fix iterations before stopping | 
š Installation & Usage
Quick Start
- 
Clone and Navigate:
cd fixer - 
Configure API Key: Update
Config.tomlwith your Anthropic API key - 
Run the Fixer:
bal run -- <path-to-your-ballerina-project> 
Usage Examples
Basic Usage:
bal run -- ./my-ballerina-project
With Relative Path:
bal run -- ../another-project
With Absolute Path:
bal run -- /home/user/ballerina-projects/my-app
š How It Works
Workflow Overview
- Error Detection: Analyzes 
bal buildoutput to identify compilation errors - Error Parsing: Extracts detailed error information (file, line, column, message)
 - Context Analysis: Reads source files and prepares context for AI analysis
 - AI Processing: Sends code and errors to Claude for intelligent fixing
 - User Review: Presents proposed fixes for user approval
 - Fix Application: Applies approved changes with automatic backup
 - Iteration: Repeats process until all errors are resolved
 
Error Types Handled
- Syntax errors
 - Type mismatches
 - Import resolution issues
 - Function signature problems
 - Variable declaration errors
 - And many more Ballerina compilation issues
 
š Interactive Features
User Confirmation Process
For each proposed fix, the tool provides:
- Clear error description
 - Proposed code changes
 - Interactive confirmation prompt
 - Option to review before applying
 
Example Output
=== Iteration 1 - Fix for src/main.bal === Errors to fix: Line 15: undefined symbol 'http:Client' Line 23: incompatible types: expected 'string', found 'int' Proposed fix: ```ballerina // Fixed code with proper imports and type corrections
Apply this fix? (y/n):
## š Project Structure
fixer/ āāā main.bal # Main entry point and CLI interface āāā Config.toml # Configuration file āāā Ballerina.toml # Package definition āāā Dependencies.toml # Dependencies configuration āāā README.md # This documentation āāā FIXER_COST_ESTIMATION.md # API cost analysis āāā modules/ āāā fixer/ ā āāā fixer.bal # Core fixing logic ā āāā types.bal # Type definitions āāā command_executor/ āāā command_executor.bal # Build command execution
## š Performance & Cost ### Typical Performance - **Processing Time**: 2-5 seconds per file - **Success Rate**: High success rate for common compilation errors - **Iteration Efficiency**: Usually resolves most errors within 2-3 iterations ### Cost Estimation Based on moderate usage (10 fix requests per developer per day): - **Daily Cost**: ~$1.38 - **Monthly Cost**: ~$41.40 See `FIXER_COST_ESTIMATION.md` for detailed cost analysis. ## š§ Advanced Configuration ### Custom Iteration Limits Adjust the maximum number of fixing iterations: ```toml [fixer.fixer] maxIterations=15 # Increase for complex projects
Timeout Settings
The AI model has built-in timeout protection (300 seconds) to prevent hanging on complex fixes.
š ļø Troubleshooting
Common Issues
- 
API Key Issues:
- Ensure your Anthropic API key is valid
 - Check that the key has sufficient credits
 - Verify the key is properly configured in 
Config.toml 
 - 
Build Failures:
- Ensure the target project is a valid Ballerina project
 - Check that all dependencies are properly configured
 - Verify Ballerina version compatibility
 
 - 
No Progress on Fixes:
- Some errors may require manual intervention
 - Complex architectural issues may need human review
 - Check if the same errors persist across iterations
 
 
Debug Tips
- Review the generated backup files (
.backupextension) if fixes need to be reverted - Check console output for detailed error parsing information
 - Monitor API usage if experiencing rate limiting
 
šÆ Best Practices
- Review Before Applying: Always review proposed fixes before confirmation
 - Backup Management: Keep track of backup files for important changes
 - Incremental Fixing: Fix errors in small batches for better results
 - Manual Review: Review complex fixes manually after AI application
 - Version Control: Commit changes after successful fix sessions
 
š¤ Contributing
This project is part of the Ballerina sanitizer toolkit. Contributions are welcome for:
- Enhanced error parsing
 - Additional AI model support
 - Improved user interface
 - Performance optimizations
 
š License
This project is part of the Ballerina development tools ecosystem. sudo bal push
š Related Tools
- Sanitizor: Spec sanitization tool
 - Doc Generator: Documentation generation tool
 - Example Generator: Example code generation tool
 
Note: This tool uses AI models for code generation. Always review and test generated fixes in a safe environment before deploying to production.