Git History
Every commit tells a story. The AI reads recent commits to understand what changed and why.
When ralph resets context, how does progress survive? This is the key question—and the answer is surprisingly elegant.
Each iteration starts fresh. The AI has no memory of previous iterations. So how does it know:
State lives in the codebase, not in conversation. The AI reconstructs context by reading files.
| State Externalization | |
|---|---|
| Conversation Memory (lost on reset): | |
| ❌ “We decided to use this pattern…” | |
| ❌ “The user said they prefer…” | |
| ❌ “Earlier we tried X and it failed…” | |
| File-Based State (persists always): | |
✓ src/auth.test.js | → Pattern visible in code |
✓ .plans/progress.txt | → Explicit status log |
✓ git log | → History of changes |
✓ .plans/prd.json | → Feature requirements |
ralph uses several channels to persist state:
Git History
Every commit tells a story. The AI reads recent commits to understand what changed and why.
Code Itself
Patterns, conventions, and completed work are visible in the codebase. The AI reads and follows existing code.
Progress Files
Explicit state files (progress.txt, prd.json) track what’s done and what remains.
Test Results
Running tests shows current status. Passing tests = completed work. Failing tests = work remaining.
Git is ralph’s most powerful state channel.
# Recent changesgit log --oneline -10
# What files changedgit diff HEAD~3
# Full history of a filegit log -p src/auth.test.js
# Uncommitted workgit statusEach iteration, the AI can read git history to understand:
Good commit messages are state documents:
# Bad - no useful stategit commit -m "Updates"
# Good - captures stategit commit -m "Add tests for UserAuth module
- Added 5 test cases covering login, logout, refresh- Edge cases: expired tokens, invalid credentials- Remaining: SessionManager, TokenService modules"ralph creates .plans/progress.txt to track learning across iterations.
# Progress Log
## Completed- UserAuth module tests (5 tests)- SessionManager tests (3 tests)
## In Progress- TokenService tests
## Remaining- OAuth integration tests- SAML provider tests
## Learnings- Using Jest with async/await pattern- Each module follows AAA pattern (Arrange, Act, Assert)- Mock external services, don't call real APIsIn your prompt:
Track your progress in progress.txt:1. Note completed items2. Add learnings about patterns and decisions3. Update after each significant milestoneThe most reliable state is the code itself. The AI:
If the AI is adding tests and finds:
describe('UserAuth', () => { it('should login with valid credentials', async () => { // ... test code });
it('should reject invalid passwords', async () => { // ... test code });});It knows:
describe, it)Next iteration, it looks for modules without .test.js files and continues.
Running tests provides immediate state:
$ npm test
PASS src/auth.test.jsPASS src/user.test.jsFAIL src/payment.test.js ● PaymentService › should process refunds Expected: true Received: false
Tests: 14 passed, 1 failedThe AI now knows:
ralph creates this structure in your project:
project/├── .ralph/│ └── config.toml # Configuration└── .plans/ ├── prd.json # Feature requirements (PRD) ├── PROMPT.md # System prompt for the AI └── progress.txt # Learning logThe Product Requirements Document defines features for the AI to work on:
{ "features": [ { "id": "auth-tests", "name": "Auth Module Tests", "status": "in_progress" }, { "id": "user-tests", "name": "User Module Tests", "status": "pending" } ]}The system prompt that runs every iteration:
# Task: Add Test Coverage
Add tests for all modules in src/.
## ProgressCheck progress.txt for completed work.
## CompletionWhen coverage is 80%+, output:<promise>COMPLETE</promise>If something goes wrong, state helps recover:
# See what ralph didgit log --oneline -20
# Undo last iteration's workgit reset --hard HEAD~1
# Continue from a known good stategit checkout known-good-commitralph run## State Management
1. Update progress.txt after completing each module2. Commit after each significant piece of work3. Use descriptive commit messages4. Check git status before starting work# ralph init creates the .plans/ directory with:# - prd.json (features)# - PROMPT.md (your task)# - progress.txt (learning log)ralph initTests are objective. A passing test suite is more reliable than any progress file.
If there’s a conflict between a progress file and actual code, trust the code. Files can get out of sync; code is ground truth.