Codebase Migration Agent (Python 2 to 3, JavaScript to TypeScript)
This agent orchestrates the complete migration of a codebase between technologies: Python 2 to Python 3 or JavaScript to TypeScript. It analyzes the existing source code, identifies incompatibilities and obsolete patterns, generates a prioritized migration plan, then produces the migrated code file by file with corresponding unit tests.
For who
Developers and tech leads needing to migrate a legacy codebase to a modern language version, seeking to automate and make the process more reliable.
Input
Code source à migrer (fichiers Python 2 ou JavaScript), avec indication du type de migration souhaité (Python 2→3 ou JS→TS)
steps (5)
Source Code Audit and Mapping
promptAnalyzes existing code to identify all incompatibilities and dependencies to migrate.
Prioritized Migration Plan
promptGenerates an ordered migration plan with file dependencies and optimal processing order.
File-by-File Code Migration
promptApplies migration transformations on each file following the established plan.
Non-Regression Test Generation
promptCreates a test suite verifying that migrated code behavior is identical to the original.
Final Report and Deployment Guide
promptSynthesizes the migration with a complete report and deployment instructions.
Output
Code migré complet, suite de tests de non-régression, changelog détaillé des transformations, et rapport de migration avec guide de déploiement
Example
Input
Python 2 to 3 migration of a data processing module:
```python
# utils.py
import urllib2
import ConfigParser
from StringIO import StringIO
def fetch_data(url):
response = urllib2.urlopen(url)
return response.read()
def parse_config(path):
config = ConfigParser.SafeConfigParser()
config.read(path)
return dict(config.items('main'))
def process_items(items):
results = filter(lambda x: x > 0, items)
for key, value in {}.iteritems():
print key, value
return map(str, results)
```Output
**Migrated code (utils.py)**:
```python
import urllib.request
import configparser
from io import StringIO
def fetch_data(url: str) -> bytes:
response = urllib.request.urlopen(url)
return response.read()
def parse_config(path: str) -> dict[str, str]:
config = configparser.ConfigParser()
config.read(path)
return dict(config.items('main'))
def process_items(items: list[int]) -> list[str]:
results = [x for x in items if x > 0]
for key, value in {}.items():
print(key, value)
return [str(x) for x in results]
```
**Changelog**: 6 transformations applied (3 renamed imports, 1 print to print(), 1 iteritems to items, 1 filter/map to list comprehension). **Tests**: 4 functional parity tests generated. **Confidence**: 95%.Customization
| Parameter | Description | Default |
|---|---|---|
| migration_type | Type de migration Ă effectuer : Python 2 vers Python 3, ou JavaScript vers TypeScript | python2-to-python3 |
| strategie | Stratégie de migration : 'conservative' (comportement identique garanti) ou 'modern' (adoption des patterns modernes idiomatiques) | modern |
| strictness_level | Niveau de strictness pour le typage en cible : 'loose' (any autorisé), 'moderate' (any limité), 'strict' (zéro any, types exhaustifs) | moderate |