Skip to content

Commit e283223

Browse files
fix(examples): configuration management system
changes: - file: data_processor.py area: core added: [calculate_metrics, process_with_external_api, export_report, process_user_data, generate_report, another_unused_function, +11 more] - file: simple_buggy.py area: core added: [__init__, duplicate_function, process_user_input, process_data, BadClass, save_data, +5 more] - file: ollama_simple_demo.py area: core added: [call_ollama, log_section, validate_with_vallm, Colors, generate_ollama_prompt, extract_code_from_response, +5 more] stats: lines: "+2181/-0 (net +2181)" files: 9 complexity: "Large structural change (normalized)"
1 parent c973df8 commit e283223

File tree

17 files changed

+2209
-3
lines changed

17 files changed

+2209
-3
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
## [0.1.8] - 2026-03-01
2+
3+
### Summary
4+
5+
fix(examples): configuration management system
6+
7+
### Docs
8+
9+
- docs: update README
10+
11+
### Other
12+
13+
- docker: update Dockerfile
14+
- update examples/11_claude_code_autonomous/claude_autonomous_demo.py
15+
- scripts: update docker-entrypoint.sh
16+
- update examples/11_claude_code_autonomous/legacy_code/data_processor.py
17+
- update examples/11_claude_code_autonomous/requirements.txt
18+
- scripts: update run.sh
19+
- docker: update Dockerfile
20+
- scripts: update docker-entrypoint.sh
21+
- update examples/12_ollama_simple_demo/legacy_code/simple_buggy.py
22+
- update examples/12_ollama_simple_demo/ollama_simple_demo.py
23+
- ... and 2 more
24+
25+
126
## [0.1.7] - 2026-03-01
227

328
### Summary

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.7
1+
0.1.8
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM python:3.13-slim
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
git \
7+
build-essential \
8+
zstd \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Set up working directory
12+
WORKDIR /app
13+
14+
# Copy the entire vallm project
15+
COPY . /vallm
16+
WORKDIR /vallm
17+
18+
# Install additional dependencies
19+
COPY examples/11_claude_code_autonomous/requirements.txt /tmp/
20+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
21+
22+
# Install vallm in editable mode
23+
RUN pip install -e ".[llm]"
24+
25+
# Set working directory for demo
26+
WORKDIR /vallm/examples/11_claude_code_autonomous
27+
28+
# Start script
29+
COPY examples/11_claude_code_autonomous/docker-entrypoint.sh /usr/local/bin/
30+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
31+
32+
ENTRYPOINT ["docker-entrypoint.sh"]
33+
CMD ["bash"]
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
# Claude Code Autonomous Demo
2+
3+
## 🤖 Autonomous Refactoring with Full Feedback Loop
4+
5+
This demo showcases a complete autonomous code refactoring workflow using Claude Code with comprehensive validation and iterative improvement.
6+
7+
## 🔄 Workflow Pipeline
8+
9+
```
10+
code2llm → Claude Code → vallm → Runtime Tests → code2llm (loop)
11+
↓ ↓ ↓ ↓ ↓
12+
Analysis Refactoring Validation Functionality Re-analysis
13+
```
14+
15+
### 📋 Complete Process
16+
17+
1. **code2llm Analysis** - Deep structural analysis and code smell detection
18+
2. **Claude Code** - Advanced refactoring with architectural improvements
19+
3. **vallm Validation** - Multi-criteria quality assessment (syntax, security, performance, semantics)
20+
4. **Runtime Tests** - Automated functionality validation with pytest
21+
5. **code2llm Re-analysis** - Verify improvements and detect remaining issues
22+
6. **Iterative Loop** - Continue until perfect code achieved (max 5 iterations)
23+
24+
## 🎯 Key Features
25+
26+
### 🔍 Comprehensive Analysis
27+
- **Code Structure**: Functions, classes, modules, entry points
28+
- **Code Smells**: Complexity, duplication, dead code, coupling issues
29+
- **Security**: Vulnerabilities, hardcoded credentials, injection risks
30+
- **Performance**: Inefficient algorithms, memory usage patterns
31+
- **Architecture**: SOLID violations, tight coupling, separation of concerns
32+
33+
### 🧠 Claude Code Integration
34+
- **Advanced Reasoning**: Superior code understanding and refactoring
35+
- **Architectural Patterns**: Design patterns, clean architecture principles
36+
- **Security Focus**: Proactive vulnerability detection and fixing
37+
- **Performance Optimization**: Algorithmic improvements and best practices
38+
39+
### ✅ Multi-Layer Validation
40+
- **vallm**: Syntax, imports, complexity, security, semantics, performance
41+
- **Runtime Tests**: Functional validation with auto-generated test suites
42+
- **Quality Metrics**: Code quality scoring and improvement tracking
43+
44+
### 🔄 Autonomous Loop
45+
- **Feedback Integration**: Validation failures guide next iteration
46+
- **Progressive Improvement**: Each iteration builds on previous results
47+
- **Best Version Tracking**: Automatically saves the best refactored version
48+
- **Termination Criteria**: Stops when perfect code achieved or max iterations reached
49+
50+
## 🚀 Quick Start
51+
52+
### Prerequisites
53+
- Docker and Docker Compose
54+
- ANTHROPIC_API_KEY environment variable
55+
- Local Ollama (optional, for comparison)
56+
57+
### Setup
58+
```bash
59+
# Set your Anthropic API key
60+
export ANTHROPIC_API_KEY='your-anthropic-api-key'
61+
62+
# Run the demo
63+
./run.sh
64+
```
65+
66+
## 📁 Project Structure
67+
68+
```
69+
11_claude_code_autonomous/
70+
├── claude_autonomous_demo.py # Main autonomous workflow
71+
├── legacy_code/
72+
│ └── data_processor.py # Legacy code with multiple issues
73+
├── requirements.txt # Python dependencies
74+
├── Dockerfile # Container configuration
75+
├── docker-entrypoint.sh # Container startup script
76+
├── run.sh # Demo runner script
77+
└── README.md # This file
78+
```
79+
80+
## 🔧 Legacy Code Issues
81+
82+
The demo refactors a complex data processing system with:
83+
84+
### 🚨 Security Issues
85+
- **SQL Injection**: Direct string concatenation in queries
86+
- **Command Injection**: Unsafe subprocess calls
87+
- **Pickle Deserialization**: Unsafe object serialization
88+
- **Hardcoded Credentials**: API keys in source code
89+
- **eval() Usage**: Dangerous code execution
90+
91+
### 🏗️ Architecture Problems
92+
- **SRP Violations**: DataProcessor has too many responsibilities
93+
- **Tight Coupling**: Direct access to internal state
94+
- **Global Variables**: Shared state management issues
95+
- **No Error Handling**: Missing exception management
96+
97+
### 🐉 Code Smells
98+
- **Deep Nesting**: Complex conditional structures
99+
- **Duplicate Code**: Repeated validation functions
100+
- **Dead Code**: Unused functions and variables
101+
- **Long Parameter Lists**: Maintainability issues
102+
- **Magic Numbers**: Hardcoded values
103+
104+
### ⚡ Performance Issues
105+
- **Inefficient Algorithms**: O(n²) nested loops
106+
- **Memory Leaks**: Unbounded cache growth
107+
- **Poor Data Structures**: Suboptimal choices
108+
109+
## 📊 Validation Criteria
110+
111+
### vallm Validation
112+
- **Syntax**: Python syntax correctness
113+
- **Imports**: Module import validation
114+
- **Complexity**: Cyclomatic complexity analysis
115+
- **Security**: Vulnerability detection
116+
- **Semantics**: Code meaning and intent
117+
- **Performance**: Efficiency analysis
118+
119+
### Runtime Tests
120+
- **Functionality**: Behavioral correctness
121+
- **Edge Cases**: Boundary condition testing
122+
- **Error Handling**: Exception management
123+
- **Integration**: Component interaction
124+
125+
### Quality Metrics
126+
- **Code Smells**: Reduction in detected issues
127+
- **Coupling**: Improved module independence
128+
- **Cohesion**: Better relatedness of code elements
129+
- **Maintainability**: Enhanced readability and structure
130+
131+
## 🎯 Expected Improvements
132+
133+
After autonomous refactoring, the code should have:
134+
135+
### ✅ Security Fixes
136+
- Parameterized queries to prevent SQL injection
137+
- Safe subprocess usage with proper validation
138+
- Secure serialization methods
139+
- Environment-based configuration
140+
- Input sanitization and validation
141+
142+
### 🏗️ Architecture Improvements
143+
- Single Responsibility Principle compliance
144+
- Dependency injection implementation
145+
- Proper abstraction layers
146+
- Interface segregation
147+
- Loose coupling design
148+
149+
### 🧹 Code Quality
150+
- Eliminated code smells
151+
- Reduced complexity
152+
- Improved naming conventions
153+
- Better error handling
154+
- Comprehensive documentation
155+
156+
### ⚡ Performance Gains
157+
- Optimized algorithms
158+
- Efficient data structures
159+
- Proper memory management
160+
- Reduced computational complexity
161+
162+
## 📈 Output Files
163+
164+
The demo generates several output files:
165+
166+
- **best_refactored.py** - Final optimized version
167+
- **refactored_v{1-5}.py** - Iteration snapshots
168+
- **claude_autonomous.log** - Detailed workflow logs
169+
- **claude-autonomous-output.log** - Console output
170+
- **test_*.py** - Auto-generated test files
171+
172+
## 🔄 Iteration Process
173+
174+
Each iteration includes:
175+
176+
1. **Analysis**: code2llm examines current state
177+
2. **Refactoring**: Claude Code generates improvements
178+
3. **Validation**: vallm assesses code quality
179+
4. **Testing**: Runtime validation of functionality
180+
5. **Scoring**: Overall quality assessment
181+
6. **Decision**: Continue if not perfect
182+
183+
The loop continues until:
184+
- All validation criteria pass ✅
185+
- All runtime tests pass ✅
186+
- No code smells detected ✅
187+
- Maximum iterations reached (5) ⚠️
188+
189+
## 🎮 Advanced Features
190+
191+
### 🧠 Intelligent Feedback
192+
- Validation errors guide specific fixes
193+
- Test failures inform corrections
194+
- Code analysis targets remaining issues
195+
- Progressive improvement strategy
196+
197+
### 📊 Quality Tracking
198+
- Iteration-by-iteration scoring
199+
- Best version automatic selection
200+
- Improvement metrics visualization
201+
- Comparative analysis
202+
203+
### 🔧 Customizable Parameters
204+
- Maximum iterations limit
205+
- Validation weight adjustments
206+
- Test coverage requirements
207+
- Quality thresholds
208+
209+
## 🚀 Use Cases
210+
211+
This autonomous workflow is ideal for:
212+
213+
- **Legacy Modernization**: Updating old codebases
214+
- **Security Hardening**: Vulnerability remediation
215+
- **Performance Optimization**: Algorithmic improvements
216+
- **Code Quality**: Maintaining high standards
217+
- **Technical Debt**: Systematic reduction
218+
219+
## 🎓 Learning Outcomes
220+
221+
Running this demo demonstrates:
222+
223+
- **Autonomous Refactoring**: AI-driven code improvement
224+
- **Multi-Tool Integration**: Combining specialized tools
225+
- **Quality Assurance**: Comprehensive validation strategies
226+
- **Iterative Development**: Progressive enhancement approach
227+
- **Best Practices**: Modern software engineering principles
228+
229+
## 🔮 Future Enhancements
230+
231+
Potential improvements to the workflow:
232+
233+
- **Multi-Model Support**: Integration with other LLMs
234+
- **Custom Validation**: Domain-specific rules
235+
- **Performance Benchmarks**: Quantitative measurements
236+
- **Code Review Integration**: Team collaboration features
237+
- **CI/CD Pipeline**: Automated deployment integration
238+
239+
---
240+
241+
## 📞 Support
242+
243+
For questions or issues with this demo:
244+
245+
1. Check the generated log files
246+
2. Verify ANTHROPIC_API_KEY is set correctly
247+
3. Ensure Docker is running properly
248+
4. Review the troubleshooting section in logs
249+
250+
Enjoy the autonomous refactoring experience! 🚀

0 commit comments

Comments
 (0)