Morph: AST-Level LLM Refactoring Where the Model Plans, Not Codes

View on GitHub

Pipeline Architecture

Most AI refactoring tools generate raw code and trust the model to preserve semantics. Morph flips that: the model proposes typed refactor operations, and the engine enforces constraints before touching files.

That design gives you a cleaner review surface and safer automation across larger codebases.

Core Idea

Use LLMs for intent generation, not code generation. Then validate and execute with AST-aware operations such as symbol rename, extraction, movement, and annotation updates.

After applying, run tests and keep rollback ready. This keeps the workspace deterministic even when plans are ambitious.

Run the Project

git clone https://github.com/dakshjain-1616/morph
cd morph
pip install -e .

morph refactor --goal 'rename calculate_total to compute_total' ./src
morph refactor --goal 'extract validation logic into validate_input' ./src --dry-run
morph plan --goal 'add type annotations to utils' ./src --output plan.json
morph refactor --plan plan.json ./src
morph verify ./src

The documented operation set currently includes ExtractModule; if you need custom operations, extend the schema first and then update planner prompts.

Architecture Walkthrough

The morph ast refactoring repository is organized around a clear pipeline, so you can trace the full flow from input handling to final output without guesswork. This makes onboarding easier for new contributors and helps teams debug faster when behavior changes after updates.

Practical Use Cases

If you are evaluating morph ast refactoring for production, start with a small real-world dataset, run the included commands end to end, and compare output quality, latency, and operational complexity. This gives a practical signal that is stronger than a toy demo.

Implementation Notes

The project is useful as both a standalone tool and a reference implementation. You can copy patterns from this codebase into your own stack, especially around evaluation discipline, reproducibility, and operator visibility.

Try NEO in Your IDE

Install the NEO extension to bring AI-powered development directly into your workflow: