Ralph Wiggum v2 - Autonomous TDD Development Loop
Quick Start
/ralph-wiggum-v2:ralph-loop --project "diablo-starcraft" --completion-promise "DIABLO_STARCRAFT_COMPLETE"
Overview
Autonomous TDD development loop that uses parallel agent swarms to review code, discover issues, and fix them with test-first methodology until convergence criteria are met.
Workflow
Phase 1: Discovery & Initialization
- Locate or create state file:
{project}/.ralph/state.json
- Locate or create categories file:
{project}/.ralph/categories.json
- Bootstrap categories from codebase structure if empty
Phase 2: Parallel Agent Review Swarm
Spawn 3-5 parallel agents with:
- Random category (weighted toward lowest scores)
- Random subcategory within that category
- Random review style (never same as last 3 used)
- Unique focus area (no overlap between agents)
Phase 3: TDD Implementation Cycle
For each finding:
- Write failing test first
- Implement minimal fix
- Verify test passes
- Update state
Phase 4: Category Evolution
After each iteration:
- Merge new discoveries
- Recalculate scores
- Meta-review (every 5 iterations)
Phase 5: Convergence Detection
Complete when:
- 10 consecutive clean iterations
- All category scores >= 95/100
- All tests passing
- Game runs without crashes
State Schema
{
"project": "diablo-starcraft",
"iteration": 0,
"consecutiveCleanIterations": 0,
"requiredCleanIterations": 10,
"completionPromise": "DIABLO_STARCRAFT_COMPLETE",
"categories": {},
"discoveryLog": [],
"lastReviewStyles": [],
"agentHistory": [],
"startedAt": "<timestamp>",
"lastUpdated": "<timestamp>"
}
Categories Schema
{
"categories": {
"<category_name>": {
"score": 50,
"maxScore": 100,
"subcategories": {
"<subcategory_name>": {
"score": 50,
"issues": [],
"lastReviewed": null,
"reviewCount": 0
}
},
"discoveredAt": 0,
"lastUpdated": "<timestamp>"
}
}
}
Review Styles
Code Quality
| Style |
Focus |
| NITPICKER |
Formatting, naming, tiny inconsistencies |
| REFACTORER |
Duplication, abstraction opportunities |
| DRY_ENFORCER |
Copy-paste code, repeated patterns |
| TYPE_ZEALOT |
Type safety, any usage, casting |
| SOLID_ADHERENT |
SOLID principle violations |
| API_PURIST |
Interface design, contracts, signatures |
Reliability
| Style |
Focus |
| DEBUGGER |
Logic errors, off-by-one, wrong operators |
| EDGE_CASE_HUNTER |
Boundary conditions, null/undefined |
| ERROR_HANDLER |
Missing try/catch, unhandled promises |
| STATE_MACHINE_ANALYST |
Invalid state transitions |
| CONCURRENCY_EXPERT |
Race conditions, async bugs |
| MEMORY_LEAK_HUNTER |
Listeners not removed, growing arrays |
Performance
| Style |
Focus |
| PERFORMANCE_HAWK |
O(n²), unnecessary renders, hot paths |
| ALLOCATION_AUDITOR |
Object churn, GC pressure |
| RENDER_OPTIMIZER |
DOM thrashing, layout thrashing |
Security
| Style |
Focus |
| SECURITY_AUDITOR |
XSS, injection, unsafe operations |
| INPUT_VALIDATOR |
Unsanitized user input |
Architecture
| Style |
Focus |
| ARCHITECT |
Coupling, cohesion, separation of concerns |
| DEPENDENCY_AUDITOR |
Circular deps, tight coupling |
| LAYER_GUARDIAN |
Layer violations, wrong abstractions |
Testing
| Style |
Focus |
| TEST_SKEPTIC |
Coverage gaps, weak assertions |
| MUTATION_TESTER |
Tests that always pass |
| INTEGRATION_ANALYST |
Unit vs integration gaps |
Game-Specific
| Style |
Focus |
| DIABLO_VETERAN |
ARPG conventions, loot, skills, combat feel |
| STARCRAFT_FAN |
Faction identity, unit feel, SC universe |
| GAME_FEEL_EXPERT |
Juice, polish, responsiveness |
| BALANCE_DESIGNER |
Numbers, progression, fairness |
| PLAYER_PSYCHOLOGY |
Motivation, reward loops |
| SPEEDRUNNER |
Exploits, sequence breaks |
| COMPLETIONIST |
Missing edge cases in content |
| FIRST_TIME_USER |
Onboarding, confusion points |
Meta
| Style |
Focus |
| FRESH_EYES |
What would confuse a new developer? |
| DOCUMENTATION_STICKLER |
Missing/wrong comments |
| FUTURE_MAINTAINER |
Technical debt accumulation |
Agent Output Format
{
"agentId": "<uuid>",
"category": "<category>",
"subcategory": "<subcategory>",
"reviewStyle": "<style>",
"filesReviewed": ["<paths>"],
"findings": [
{
"severity": "critical|major|minor|nitpick",
"type": "<issue_type>",
"location": "<file:line>",
"description": "<what's wrong>",
"suggestedFix": "<how to fix>",
"requiresTest": true,
"testWritten": false,
"fixed": false,
"newSubcategory": null
}
],
"scoreAdjustment": 0,
"newCategoriesDiscovered": [],
"cleanReview": false
}
Hard Requirements
Iteration Loop
LOOP:
1. Load state from .ralph/state.json
2. Load categories from .ralph/categories.json
3. Increment iteration counter
4. Select 3-5 lowest-scoring categories for review
5. Spawn parallel review agents (use Task tool)
6. Collect findings from all agents
7. Sort findings by severity (critical → major → minor)
8. TDD fix each finding:
a. Write failing test
b. Implement minimal fix
c. Verify test passes
d. Run full test suite
9. Update scores and state
10. Check convergence criteria:
- All agents returned cleanReview: true?
- No critical/major findings?
- All tests passing?
- No new categories discovered?
11. IF clean: consecutiveCleanIterations++
IF dirty: consecutiveCleanIterations = 0
12. IF consecutiveCleanIterations >= 10 AND all scores >= 95:
→ CONVERGED: Run final verification
ELSE: → Continue loop
Final Verification
When convergence criteria met:
- Full test suite run
- TypeScript strict mode check
- Build production bundle
- Verify game loads and plays
- Generate completion report
- Output:
{COMPLETION_PROMISE} achieved
Game-Specific Categories (Diablo-StarCraft)
Auto-discovered from codebase:
- engine/ → Engine (Game, Camera)
- mechanics/ → Mechanics (Player, Ability, Item)
- ai/ → AI (Enemy, Pathfinding)
- graphics/ → Graphics (Renderer, VFX)
- audio/ → Audio (AudioManager)
- physics/ → Physics (Collision)
- world/ → World (Tilemap)
- persistence/ → Persistence (SaveManager)
- input/ → Input (InputManager)
- utils/ → Utils (isometric)
Game system categories:
- Combat → Damage, resistance, crits, DOTs
- Skills → Abilities, cooldowns, scaling
- Loot → Drops, rarity, equipment
- Progression → XP, levels, stats
- Waves → Spawning, difficulty, bosses
- UI/HUD → Health bars, buffs, minimap
- Save/Load → Persistence, state restoration
1---2name: ralph-wiggum-v23description: Autonomous TDD development loop with parallel agent swarm, category evolution, and convergence detection. Use when running autonomous game development, quality improvement loops, or comprehensive codebase reviews.4---5
6# Ralph Wiggum v2 - Autonomous TDD Development Loop
7
8## Quick Start
9
10```
11/ralph-wiggum-v2:ralph-loop --project "diablo-starcraft" --completion-promise "DIABLO_STARCRAFT_COMPLETE"
12```
13
14## Overview
15
16Autonomous TDD development loop that uses parallel agent swarms to review code, discover issues, and fix them with test-first methodology until convergence criteria are met.
17
18## Workflow
19
20### Phase 1: Discovery & Initialization
21
221. **Locate or create state file**: `{project}/.ralph/state.json`
232. **Locate or create categories file**: `{project}/.ralph/categories.json`
243. **Bootstrap categories** from codebase structure if empty
25
26### Phase 2: Parallel Agent Review Swarm
27
28Spawn 3-5 parallel agents with:
29- Random category (weighted toward lowest scores)
30- Random subcategory within that category
31- Random review style (never same as last 3 used)
32- Unique focus area (no overlap between agents)
33
34### Phase 3: TDD Implementation Cycle
35
36For each finding:
371. Write failing test first
382. Implement minimal fix
393. Verify test passes
404. Update state
41
42### Phase 4: Category Evolution
43
44After each iteration:
451. Merge new discoveries
462. Recalculate scores
473. Meta-review (every 5 iterations)
48
49### Phase 5: Convergence Detection
50
51Complete when:
52- 10 consecutive clean iterations
53- All category scores >= 95/100
54- All tests passing
55- Game runs without crashes
56
57---
58
59## State Schema
60
61```json
62{
63 "project": "diablo-starcraft",
64 "iteration": 0,
65 "consecutiveCleanIterations": 0,
66 "requiredCleanIterations": 10,
67 "completionPromise": "DIABLO_STARCRAFT_COMPLETE",
68 "categories": {},
69 "discoveryLog": [],
70 "lastReviewStyles": [],
71 "agentHistory": [],
72 "startedAt": "<timestamp>",
73 "lastUpdated": "<timestamp>"
74}
75```
76
77## Categories Schema
78
79```json
80{
81 "categories": {
82 "<category_name>": {
83 "score": 50,
84 "maxScore": 100,
85 "subcategories": {
86 "<subcategory_name>": {
87 "score": 50,
88 "issues": [],
89 "lastReviewed": null,
90 "reviewCount": 0
91 }
92 },
93 "discoveredAt": 0,
94 "lastUpdated": "<timestamp>"
95 }
96 }
97}
98```
99
100---
101
102## Review Styles
103
104### Code Quality
105| Style | Focus |
106|-------|-------|
107| NITPICKER | Formatting, naming, tiny inconsistencies |
108| REFACTORER | Duplication, abstraction opportunities |
109| DRY_ENFORCER | Copy-paste code, repeated patterns |
110| TYPE_ZEALOT | Type safety, any usage, casting |
111| SOLID_ADHERENT | SOLID principle violations |
112| API_PURIST | Interface design, contracts, signatures |
113
114### Reliability
115| Style | Focus |
116|-------|-------|
117| DEBUGGER | Logic errors, off-by-one, wrong operators |
118| EDGE_CASE_HUNTER | Boundary conditions, null/undefined |
119| ERROR_HANDLER | Missing try/catch, unhandled promises |
120| STATE_MACHINE_ANALYST | Invalid state transitions |
121| CONCURRENCY_EXPERT | Race conditions, async bugs |
122| MEMORY_LEAK_HUNTER | Listeners not removed, growing arrays |
123
124### Performance
125| Style | Focus |
126|-------|-------|
127| PERFORMANCE_HAWK | O(n²), unnecessary renders, hot paths |
128| ALLOCATION_AUDITOR | Object churn, GC pressure |
129| RENDER_OPTIMIZER | DOM thrashing, layout thrashing |
130
131### Security
132| Style | Focus |
133|-------|-------|
134| SECURITY_AUDITOR | XSS, injection, unsafe operations |
135| INPUT_VALIDATOR | Unsanitized user input |
136
137### Architecture
138| Style | Focus |
139|-------|-------|
140| ARCHITECT | Coupling, cohesion, separation of concerns |
141| DEPENDENCY_AUDITOR | Circular deps, tight coupling |
142| LAYER_GUARDIAN | Layer violations, wrong abstractions |
143
144### Testing
145| Style | Focus |
146|-------|-------|
147| TEST_SKEPTIC | Coverage gaps, weak assertions |
148| MUTATION_TESTER | Tests that always pass |
149| INTEGRATION_ANALYST | Unit vs integration gaps |
150
151### Game-Specific
152| Style | Focus |
153|-------|-------|
154| DIABLO_VETERAN | ARPG conventions, loot, skills, combat feel |
155| STARCRAFT_FAN | Faction identity, unit feel, SC universe |
156| GAME_FEEL_EXPERT | Juice, polish, responsiveness |
157| BALANCE_DESIGNER | Numbers, progression, fairness |
158| PLAYER_PSYCHOLOGY | Motivation, reward loops |
159| SPEEDRUNNER | Exploits, sequence breaks |
160| COMPLETIONIST | Missing edge cases in content |
161| FIRST_TIME_USER | Onboarding, confusion points |
162
163### Meta
164| Style | Focus |
165|-------|-------|
166| FRESH_EYES | What would confuse a new developer? |
167| DOCUMENTATION_STICKLER | Missing/wrong comments |
168| FUTURE_MAINTAINER | Technical debt accumulation |
169
170---
171
172## Agent Output Format
173
174```json
175{
176 "agentId": "<uuid>",
177 "category": "<category>",
178 "subcategory": "<subcategory>",
179 "reviewStyle": "<style>",
180 "filesReviewed": ["<paths>"],
181 "findings": [
182 {
183 "severity": "critical|major|minor|nitpick",
184 "type": "<issue_type>",
185 "location": "<file:line>",
186 "description": "<what's wrong>",
187 "suggestedFix": "<how to fix>",
188 "requiresTest": true,
189 "testWritten": false,
190 "fixed": false,
191 "newSubcategory": null
192 }
193 ],
194 "scoreAdjustment": 0,
195 "newCategoriesDiscovered": [],
196 "cleanReview": false
197}
198```
199
200---
201
202## Hard Requirements
203
204- [ ] **PLAYABLE_LOCAL** - Runs in browser, playable start-to-finish
205- [ ] **TDD_ENFORCED** - No fix without failing test first
206- [ ] **ZERO_CRASHES** - No unhandled exceptions in any path
207- [ ] **ALL_TESTS_PASS** - 100% test suite green
208- [ ] **SCORES_95_PLUS** - Every category at 95+/100
209- [ ] **CLEAN_CONVERGENCE** - 10 consecutive clean iterations
210
211---
212
213## Iteration Loop
214
215```
216LOOP:
217 1. Load state from .ralph/state.json
218 2. Load categories from .ralph/categories.json
219 3. Increment iteration counter
220 4. Select 3-5 lowest-scoring categories for review
221 5. Spawn parallel review agents (use Task tool)
222 6. Collect findings from all agents
223 7. Sort findings by severity (critical → major → minor)
224 8. TDD fix each finding:
225 a. Write failing test
226 b. Implement minimal fix
227 c. Verify test passes
228 d. Run full test suite
229 9. Update scores and state
230 10. Check convergence criteria:
231 - All agents returned cleanReview: true?
232 - No critical/major findings?
233 - All tests passing?
234 - No new categories discovered?
235 11. IF clean: consecutiveCleanIterations++
236 IF dirty: consecutiveCleanIterations = 0
237 12. IF consecutiveCleanIterations >= 10 AND all scores >= 95:
238 → CONVERGED: Run final verification
239 ELSE: → Continue loop
240```
241
242---
243
244## Final Verification
245
246When convergence criteria met:
2471. Full test suite run
2482. TypeScript strict mode check
2493. Build production bundle
2504. Verify game loads and plays
2515. Generate completion report
2526. Output: `{COMPLETION_PROMISE}` achieved
253
254---
255
256## Game-Specific Categories (Diablo-StarCraft)
257
258### Auto-discovered from codebase:
259- **engine/** → Engine (Game, Camera)
260- **mechanics/** → Mechanics (Player, Ability, Item)
261- **ai/** → AI (Enemy, Pathfinding)
262- **graphics/** → Graphics (Renderer, VFX)
263- **audio/** → Audio (AudioManager)
264- **physics/** → Physics (Collision)
265- **world/** → World (Tilemap)
266- **persistence/** → Persistence (SaveManager)
267- **input/** → Input (InputManager)
268- **utils/** → Utils (isometric)
269
270### Game system categories:
271- **Combat** → Damage, resistance, crits, DOTs
272- **Skills** → Abilities, cooldowns, scaling
273- **Loot** → Drops, rarity, equipment
274- **Progression** → XP, levels, stats
275- **Waves** → Spawning, difficulty, bosses
276- **UI/HUD** → Health bars, buffs, minimap
277- **Save/Load** → Persistence, state restoration