Alexander Payne
|
49ca4dad43
|
feat: Self-Edit MCP Tool (Phase 2.1)
Implements the Self-Edit MCP Tool that orchestrates the self-coding foundation:
## Core Features
1. **SelfEditTool** (src/tools/self_edit.py)
- Complete self-modification orchestrator
- Pre-flight safety checks (clean repo, on main branch)
- Context gathering (codebase indexer + modification journal)
- Feature branch creation (timmy/self-edit/{timestamp})
- LLM-based edit planning with fallback
- Safety constraint validation
- Aider integration (preferred) with fallback to direct editing
- Automatic test execution via pytest
- Commit on success, rollback on failure
- Modification journaling with reflections
2. **Safety Constraints**
- Max 3 files per commit
- Max 100 lines changed
- Protected files list (self-edit tool, foundation services)
- Only modify files with test coverage
- Max 3 retries on failure
- Requires user confirmation (MCP tool registration)
3. **Execution Backends**
- Aider integration: --auto-test --test-cmd pytest --yes --no-git
- Direct editing fallback: LLM-based file modification with AST validation
- Automatic backend selection based on availability
## Test Coverage
- 19 new tests covering:
- Basic functionality (initialization, preflight checks)
- Edit planning (with/without LLM)
- Safety validation (file limits, protected files)
- Execution flow (success and failure paths)
- Error handling (exceptions, LLM failures)
- MCP registration
## Usage
from tools.self_edit import register_self_edit_tool
from mcp.registry import tool_registry
# Register with MCP
register_self_edit_tool(tool_registry, llm_adapter)
Phase 2.2 will add Dashboard API endpoints and UI.
|
2026-02-26 12:28:05 -05:00 |
|