forked from Rockachopa/Timmy-time-dashboard
feat: Self-Coding Foundation (Phase 1)
Implements the foundational infrastructure for Timmy's self-modification capability:
## New Services
1. **GitSafety** (src/self_coding/git_safety.py)
- Atomic git operations with rollback capability
- Snapshot/restore for safe experimentation
- Feature branch management (timmy/self-edit/{timestamp})
- Merge to main only after tests pass
2. **CodebaseIndexer** (src/self_coding/codebase_indexer.py)
- AST-based parsing of Python source files
- Extracts classes, functions, imports, docstrings
- Builds dependency graph for blast radius analysis
- SQLite storage with hash-based incremental indexing
- get_summary() for LLM context (<4000 tokens)
- get_relevant_files() for task-based file discovery
3. **ModificationJournal** (src/self_coding/modification_journal.py)
- Persistent log of all self-modification attempts
- Tracks outcomes: success, failure, rollback
- find_similar() for learning from past attempts
- Success rate metrics and recent failure tracking
- Supports vector embeddings (Phase 2)
4. **ReflectionService** (src/self_coding/reflection.py)
- LLM-powered analysis of modification attempts
- Generates lessons learned from successes and failures
- Fallback templates when LLM unavailable
- Supports context from similar past attempts
## Test Coverage
- 104 new tests across 7 test files
- 95% code coverage on self_coding module
- Green path tests: full workflow integration
- Red path tests: errors, rollbacks, edge cases
- Safety constraint tests: test coverage requirements, protected files
## Usage
from self_coding import GitSafety, CodebaseIndexer, ModificationJournal
git = GitSafety(repo_path=/path/to/repo)
indexer = CodebaseIndexer(repo_path=/path/to/repo)
journal = ModificationJournal()
Phase 2 will build the Self-Edit MCP Tool that orchestrates these services.
This commit is contained in:
50
src/self_coding/__init__.py
Normal file
50
src/self_coding/__init__.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Self-Coding Layer — Timmy's ability to modify its own source code safely.
|
||||
|
||||
This module provides the foundational infrastructure for self-modification:
|
||||
|
||||
- GitSafety: Atomic git operations with rollback capability
|
||||
- CodebaseIndexer: Live mental model of the codebase
|
||||
- ModificationJournal: Persistent log of modification attempts
|
||||
- ReflectionService: Generate lessons learned from attempts
|
||||
|
||||
Usage:
|
||||
from self_coding import GitSafety, CodebaseIndexer, ModificationJournal
|
||||
from self_coding import ModificationAttempt, Outcome, Snapshot
|
||||
|
||||
# Initialize services
|
||||
git = GitSafety(repo_path="/path/to/repo")
|
||||
indexer = CodebaseIndexer(repo_path="/path/to/repo")
|
||||
journal = ModificationJournal()
|
||||
|
||||
# Use in self-modification workflow
|
||||
snapshot = await git.snapshot()
|
||||
# ... make changes ...
|
||||
if tests_pass:
|
||||
await git.commit("Changes", ["file.py"])
|
||||
else:
|
||||
await git.rollback(snapshot)
|
||||
"""
|
||||
|
||||
from self_coding.git_safety import GitSafety, Snapshot
|
||||
from self_coding.codebase_indexer import CodebaseIndexer, ModuleInfo, FunctionInfo, ClassInfo
|
||||
from self_coding.modification_journal import (
|
||||
ModificationJournal,
|
||||
ModificationAttempt,
|
||||
Outcome,
|
||||
)
|
||||
from self_coding.reflection import ReflectionService
|
||||
|
||||
__all__ = [
|
||||
# Core services
|
||||
"GitSafety",
|
||||
"CodebaseIndexer",
|
||||
"ModificationJournal",
|
||||
"ReflectionService",
|
||||
# Data classes
|
||||
"Snapshot",
|
||||
"ModuleInfo",
|
||||
"FunctionInfo",
|
||||
"ClassInfo",
|
||||
"ModificationAttempt",
|
||||
"Outcome",
|
||||
]
|
||||
Reference in New Issue
Block a user