Case Study: Automating Legacy Code Refactoring with Zene
Objective: Take a messy, procedural Python script (legacy_script.py) and refactor it into a modular, type-safe application using Pydantic.
The Challenge
The original code was a classic "script kiddie" mess:
- Hardcoded dictionaries
- Mixed logic (data processing inside loops)
- No type hints
- No docstrings
- Ambiguous filtering logic
The Agent Workflow
1. Planning (DeepSeek V3)
DeepSeek correctly identified the refactoring steps:
- Analyze the existing logic.
- Create
src/models.py(Pydantic models). - Create
src/processor.py(Business logic). - Create
main.py(Entry point). - Verify output consistency.
- Verify type safety (mypy).
2. Execution (Zhipu GLM-4)
- Models: Created
UserandProcessedUserPydantic models. - Processor: Extracted the filtering and calculation logic into
process_data, adding type hints (List[User] -> List[ProcessedUser]). - Main: Wired it all together.
3. The "Gotcha" (Minimax Reflector)
During the verification phase (Task 6), the Executor claimed:
"I manually checked the code for type hints... No type errors were found."
Minimax (Reflector) immediately flagged this:
REJECTED: "The task specifically requested running
mypyto verify type safety, but the execution used manual checking instead. No mypy output was provided."
This forced the system to (ideally) run the actual mypy command, ensuring true type safety rather than just "looking at it".
Outcome
The result is a clean, maintainable project structure:
src/
models.py # Pydantic schemas
processor.py # Pure functions with type hints
main.py # Clean entry pointThis demonstrates Zene's ability to act not just as a code generator, but as a Quality Assurance system for refactoring tasks.
