P
🤖AutomatisationAdvanced5 steps

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.

migration de coderefactoringPythonTypeScriptautomatisation

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

Type: text
Format: code

Code source à migrer (fichiers Python 2 ou JavaScript), avec indication du type de migration souhaité (Python 2→3 ou JS→TS)

steps (5)

1

Source Code Audit and Mapping

prompt

Analyzes existing code to identify all incompatibilities and dependencies to migrate.

2

Prioritized Migration Plan

prompt

Generates an ordered migration plan with file dependencies and optimal processing order.

3

File-by-File Code Migration

prompt

Applies migration transformations on each file following the established plan.

4

Non-Regression Test Generation

prompt

Creates a test suite verifying that migrated code behavior is identical to the original.

5

Final Report and Deployment Guide

prompt

Synthesizes the migration with a complete report and deployment instructions.

Output

Type: text
Format: structuré

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

ParameterDescriptionDefault
migration_typeType de migration Ă  effectuer : Python 2 vers Python 3, ou JavaScript vers TypeScriptpython2-to-python3
strategieStratégie de migration : 'conservative' (comportement identique garanti) ou 'modern' (adoption des patterns modernes idiomatiques)modern
strictness_levelNiveau de strictness pour le typage en cible : 'loose' (any autorisé), 'moderate' (any limité), 'strict' (zéro any, types exhaustifs)moderate

Technical Notes

<p>This agent works optimally on moderately sized modules (< 500 lines per file). For large codebases, proceed in batches by submitting files module by module following the dependency order.</p><p>For Python 2 to 3 migrations, the agent handles major incompatibilities: print, unicode/bytes, renamed imports, iterators, integer division, and syntax changes. Advanced metaprogramming cases (metaclasses, custom descriptors) require human review.</p><p>For JS to TS migrations, the agent infers types from context and usage. Provide existing type files (@types/) and API interfaces for more precise typing. Enable strict mode for critical projects.</p>