LLM-powered code migrations at scale
Project description
AI Migration Tool
This tool runs code migrations at scale. It is designed to be run in two phases:
Setup:
- Initialize a new project
- Add example pairs showing migration patterns
- Generate a system prompt for the migration task
- Create a verification script
Migration:
- Run the migration script:
ai-migrate migrate --project my-new-project - Check the status of the migration
- Check out a branch for manual fixes
- Merge all successful migrations
Prerequisites
- Hermit installed
Installation
- Clone this repository:
gh repo clone block/ai-migrate
cd ai-migrate
- Set up the development environment using Hermit:
hermit init
uv sync
This will:
- Initialize the Hermit environment with Python and required tools
- Install all necessary Python packages
- Create your project:
# Basic project initialization
uv run ai-migrate init
# Or initialize from a PR (recommended)
uv run ai-migrate init <project_dir> --pr=<pr_number> --description="Brief description of migration"
- Fill in the blanks. The above command generated some files you should edit:
<project dir>/system_prompt.md: Modify this to suit your migration details.examples/: Add pairs of example files showing migration patterns. Useuv run ai-migrate migrate --manage examplesto manage examples, including generating from git history or from a PR.
Setting Up Examples
Add example pairs to your project's examples/ directory.
Example structure:
project/
├── examples/
│ ├── Example1.old.java
│ ├── Example1.new.java
│ ├── Example2.old.java
│ └── Example2.new.java
Usage
# Interactive CLI
uv run ai-migrate migrate
The interactive CLI provides a guided experience with:
- Interactive prompts for file paths and options
- Rich terminal output with colors and formatting
- Progress indicators during long-running operations
- Dialog-based selection for various options
Key Commands
# Initialize a new project
uv run ai-migrate init
# Migrate files
uv run ai-migrate migrate [FILE_PATHS]
# Check migration status
uv run ai-migrate status
# Check out a branch for manual fixes
uv run ai-migrate checkout FILE_PATH
# Merge all successful migrations
uv run ai-migrate merge-branches
# Get help for a specific command
uv run ai-migrate migrate --help
Project Selection
The interactive CLI now provides an easy way to select which migration project to use:
-
Automatic Project Selection: When you run a command without specifying a project directory, the CLI will:
- First check the
AI_MIGRATE_PROJECT_DIRenvironment variable - Then look for a
.ai-migratefile in the current directory - If neither is found, show a selection dialog with available projects
- First check the
-
Project Selection Dialog:
- Shows all projects in the
projects/directory - Allows you to select the appropriate project for your migration task
- Remembers your selection for the current command
- Shows all projects in the
-
Manual Project Specification:
- Use
--project-diroption to specify a project directly, or use--projectto specify a pre-configured project - Set the
AI_MIGRATE_PROJECT_DIRenvironment variable for persistent selection - Create a
.ai-migratefile in your repository for project-specific settings
- Use
This makes it easy to work with multiple migration projects without having to remember and type their paths each time.
This will look as input for the specified file and load it if it exists as that or in the form of a .old. file. The script will write the output to the same file and move the previous version to a .old. file if not .old. previously existed. This way you can keep trying migrations having to move files around.
Command Comparison: Main Branch vs New CLI
Here's how commands from the main branch map to the new interactive CLI:
| Main Branch Command | New Interactive CLI Command | Description |
|---|---|---|
uv run ai-migrate projects init <path> |
uv run ai-migrate init |
Initialize a new project |
uv run ai-migrate examples setup <ref> |
uv run ai-migrate migrate --manage examples then select "setup" |
Set up examples from git history |
uv run ai-migrate examples add <file> |
uv run ai-migrate migrate --manage examples then select "add" |
Add a file as an example |
uv run ai-migrate --files <file> |
uv run ai-migrate migrate <file> |
Migrate a specific file |
uv run ai-migrate projects status |
uv run ai-migrate status |
Show migration status |
uv run ai-migrate projects run --manifest-file=<file> |
uv run ai-migrate migrate --manifest-file=<file> |
Run migration using a manifest file |
uv run ai-migrate projects run --rerun-passed |
uv run ai-migrate migrate --rerun-passed |
Re-run migrations that have already passed |
uv run ai-migrate projects run --max-workers=<num> |
uv run ai-migrate migrate --max-workers=<num> |
Set maximum number of parallel workers |
uv run ai-migrate projects run --local-worktrees |
uv run ai-migrate migrate --local-worktrees |
Create worktrees alongside the git repo |
uv run ai-migrate projects checkout <file> |
uv run ai-migrate checkout <file> |
Check out the branch for a failed migration |
uv run ai-migrate projects merge-branches |
uv run ai-migrate merge-branches |
Merge changes from migrator branches |
New Features in Interactive CLI
The new CLI adds these capabilities not present in the main branch:
-
PR-Based Initialization:
uv run ai-migrate init # Then follow interactive prompts for PR-based setup
-
Example Management UI:
uv run ai-migrate migrate --manage examples # Interactive dialog for listing, adding, or generating examples
-
System Prompt Management:
uv run ai-migrate migrate --manage system-prompt # Interactive dialog for viewing, editing, or generating system prompts
-
Automatic Evaluation Generation:
# Disable automatic evaluation generation uv run ai-migrate migrate --dont-create-evals <file_paths> # Manage evaluations uv run ai-migrate migrate --manage evals
-
Rich Help System:
uv run ai-migrate --help uv run ai-migrate <command> --help
Development
The project uses Hermit to manage Python versions and development tools. Available tools:
- Python 3.12
- Black (code formatting)
- Ruff (linting)
- MyPy (type checking)
- Pytest (testing)
To activate the Hermit environment in your shell:
eval "$(./bin/hermit env)"
Documentation
Additional documentation is available in the docs/ directory:
- Evaluation Runner - Documentation for the evaluation runner system
- Automatic Evaluation Generation - Documentation for the automatic evaluation generation feature
AI-Powered Project Setup
The tool now supports AI-powered project setup using GitHub PRs:
-
PR-Based Project Initialization:
# Using the interactive CLI uv run ai-migrate init # Then follow the prompts
This will:
- Generate a system prompt based on the PR description and changes
- Extract example patterns from the PR changes
-
Generate Examples from PR:
# Using the interactive CLI uv run ai-migrate migrate --manage examples # Then select "from-pr" and follow the prompts
This will analyze the PR changes and extract representative examples of the migration pattern.
-
Manage System Prompt:
# Using the interactive CLI uv run ai-migrate migrate --manage system-prompt # Then select an action (view, edit, or generate) and follow the prompts
This allows you to view, edit, or generate a new system prompt for your migration project.
Interactive CLI
The new interactive CLI provides a more user-friendly experience with:
-
Rich Terminal UI:
- Colorized output for better readability
- Progress bars and spinners for long-running operations
- Formatted panels and tables for displaying information
-
Interactive Prompts:
- File path completion for easier navigation
- Selection dialogs for choosing options
- Yes/no confirmations for important decisions
-
Guided Workflows:
- Step-by-step guidance through complex operations
- Clear error messages and recovery options
- Contextual help and suggestions
-
Available Commands:
init- Initialize a new migration projectmigrate- Migrate one or more files or manage project resources- Use
--manage examplesto manage example files - Use
--manage system-promptto view or edit the system prompt - Use
--manage evalsto manage evaluation test cases - Use
--manifest-fileto specify a manifest file for batch processing - Use
--rerun-passedto re-run migrations that have already passed - Use
--max-workersto set the maximum number of parallel workers - Use
--local-worktreesto create worktrees alongside the git repo - Use
--dont-create-evalsto disable automatic evaluation generation
- Use
status- Show the status of migration projects- See which files are passing, failing, or have not been processed
checkout- Check out the branch for a failed migration attempt- Allows you to manually fix a migration that failed
merge-branches- Merge changes from migrator branches- Consolidate all successful migrations
To use the interactive CLI, simply run:
uv run ai-migrate
For specific commands:
# Initialize a new project
uv run ai-migrate init
# Migrate files
uv run ai-migrate migrate [FILE_PATHS]
# Check migration status
uv run ai-migrate status
# Check out a branch for manual fixes
uv run ai-migrate checkout FILE_PATH
# Merge all successful migrations
uv run ai-migrate merge-branches
# Get help for a specific command
uv run ai-migrate migrate --help
Automatic Evaluation Generation
The tool now automatically creates evaluation test cases from successful migrations. This helps build a comprehensive test suite and ensures that future versions of the migration system continue to work correctly.
How It Works
-
When a migration succeeds (passes verification), the system:
- Captures the original source files before migration
- Creates a new directory in the
evalsdirectory with a timestamp-based name - Saves the original files in the
sourcesubdirectory - Creates a manifest file with the verification command and file information
-
These evaluations can then be used to:
- Test future versions of the migration system
- Ensure that regressions don't occur
- Benchmark performance and accuracy
Usage
By default, evaluations are automatically created for every successful migration. You can:
# Disable automatic evaluation creation
uv run ai-migrate migrate --dont-create-evals <file_paths>
# Manage evaluations
uv run ai-migrate migrate --manage evals
The evaluation management interface allows you to:
- List existing evaluations with details like file count and creation date
- Generate evaluations from a GitHub Pull Request
- Generate evaluations from recent successful migrations
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_migrate_tools-0.1.4a1.tar.gz.
File metadata
- Download URL: ai_migrate_tools-0.1.4a1.tar.gz
- Upload date:
- Size: 68.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b18ba0fbebddda464fb39d846e38e0d8b161e396375917a6c3f697ae3c908e7
|
|
| MD5 |
7254e141777b6f5ddf12998c6bfb5347
|
|
| BLAKE2b-256 |
8280ec51ec82ac2ab301658e76418afe87784f139d7a52e9919071b7fd3e838b
|
File details
Details for the file ai_migrate_tools-0.1.4a1-py3-none-any.whl.
File metadata
- Download URL: ai_migrate_tools-0.1.4a1-py3-none-any.whl
- Upload date:
- Size: 57.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a15ea2a377b114c79c7f6985e767543c88572c102289f0e855a31a2e9e59d8b
|
|
| MD5 |
0369cd8e91c2bf3878a80b256288a834
|
|
| BLAKE2b-256 |
27e13eff41f34256ee492d5a32218d4de14171bc385c7f9d76c6deb2aa9a20eb
|