feat: enhance changelog and implement SmartLearner for pattern extraction

This commit is contained in:
JamesTheGiblet 2025-12-31 12:09:32 +00:00
parent fc603464ee
commit 4943809044
2 changed files with 899 additions and 53 deletions

View file

@ -1,38 +1,59 @@
# Changelog
# BuddAI Development Changelog
## [3.2.0] - 2025-12-29
## Version 3.2 - Self-Learning & Optimization System
### Added
### 📊 Phase 1: Data Collection
- WebSocket streaming for real-time token-by-token responses
- Multi-user support with session isolation
- Connection pooling for Ollama requests (10 connection pool)
- File upload validation (50MB limit, type checking)
- Zip slip protection for malicious archives
- Filename sanitization
- Type hints throughout codebase
- Enhanced iOS PWA support
Implemented comprehensive data logging to track user interactions and code quality.
### Security
- **Correction Logging**: Added `save_correction()` to store original vs. corrected code with user reasoning.
- **Compilation Logs**: Added `log_compilation_result()` to track hardware-specific compilation success rates.
- **Feedback System**: Enhanced `record_feedback()` to support comments and trigger failure analysis on negative feedback.
- **Database Updates**: Added tables for `corrections`, `compilation_log`, `feedback` (enhanced), and `code_rules`.
- File size limits enforced (50MB)
- Magic number validation for ZIP files
- Path traversal prevention in zip extraction
- Maximum upload file count (10 files)
- Sanitized filenames to prevent path injection
### 🔬 Phase 2: Pattern Extraction
### Performance
Added intelligence to learn from the collected data.
- Connection pooling reduces latency by ~30%
- WebSocket streaming improves perceived response time
- Per-user instance management
- **Smart Learner**: Created `SmartLearner` class to diff code and extract patterns (e.g., `analogWrite` -> `ledcWrite`).
- **Hardware Profiles**: Created `HardwareProfile` class to manage hardware-specific syntax (ESP32 vs Arduino).
- **Rule Storage**: Learned patterns are stored in `code_rules` with confidence scores.
- **Prompt Injection**: `build_enhanced_prompt()` now dynamically injects high-confidence rules into the system prompt.
### Fixed
### ✅ Phase 3: Validation
- Session isolation bug (users can no longer see each other's data)
- Connection leak in Ollama requests
- Memory growth in long-running server instances
Implemented pre-flight checks to ensure code quality before display.
## [3.1.0] - 2025-12-29
- **Code Validator**: Created `CodeValidator` class to check for:
- ESP32 PWM usage (ledcWrite enforcement).
- Blocking delays in motor code.
- Missing safety timeouts.
- **Auto-Fix**: The system can now automatically patch critical errors (like incorrect PWM calls) before showing code to the user.
- **Hardware Detection**: Automatically detects target hardware (ESP32, Arduino, Pico) from user prompts.
[Previous changelog content...]
### 🔄 Phase 4: Feedback Loop
Established continuous improvement cycles.
- **Adaptive Learner**: Created `AdaptiveLearner` to analyze session history for implicit corrections ("actually, use X") and preferences.
- **Session Analysis**: Added `/analyze` command to scan the current session for learned lessons.
- **Explicit Teaching**: Added `/teach <rule>` command for manual rule insertion.
### 📈 Metrics & Fine-Tuning
Added tools to measure and cement progress.
- **Learning Metrics**: Created `LearningMetrics` to calculate accuracy trends and correction rates over 30 days.
- **Fine-Tuning Prep**: Created `ModelFineTuner` to export corrections into JSONL format for training local LLMs (Qwen).
### 🛠 New CLI Commands
- `/learn`: Extract patterns from stored corrections.
- `/analyze`: Analyze current session for implicit feedback.
- `/correct <reason>`: Mark previous response as wrong and save correction.
- `/good`: Mark previous response as correct.
- `/teach <rule>`: Explicitly teach a coding rule.
- `/validate`: Run validation checks on the last response.
- `/rules`: Display currently learned rules.
- `/metrics`: Show accuracy and improvement stats.
- `/train`: Export training data for fine-tuning.

877
main.py

File diff suppressed because it is too large Load diff