ralph-wiggum-v2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRalph Wiggum v2 - Autonomous TDD Development Loop
Ralph Wiggum v2 - 自动化TDD开发循环
Quick Start
快速开始
/ralph-wiggum-v2:ralph-loop --project "diablo-starcraft" --completion-promise "DIABLO_STARCRAFT_COMPLETE"/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.
这是一个自动化TDD开发循环,利用并行Agent集群评审代码、发现问题,并采用测试优先的方法论修复问题,直到满足收敛标准。
Workflow
工作流程
Phase 1: Discovery & Initialization
阶段1:发现与初始化
- 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
- 定位或创建状态文件:
{project}/.ralph/state.json - 定位或创建分类文件:
{project}/.ralph/categories.json - 若分类文件为空,则从代码库结构引导生成分类
Phase 2: Parallel Agent Review Swarm
阶段2:并行Agent评审集群
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)
生成3-5个并行Agent,每个Agent具备:
- 随机分配分类(权重倾向于得分最低的分类)
- 该分类下的随机子分类
- 随机评审风格(与最近3次使用的风格不同)
- 唯一的聚焦领域(Agent之间无重叠)
Phase 3: TDD Implementation Cycle
阶段3:TDD实施周期
For each finding:
- Write failing test first
- Implement minimal fix
- Verify test passes
- Update state
针对每个发现的问题:
- 先编写失败的测试用例
- 实现最小化修复
- 验证测试通过
- 更新状态
Phase 4: Category Evolution
阶段4:分类演进
After each iteration:
- Merge new discoveries
- Recalculate scores
- Meta-review (every 5 iterations)
每次迭代后:
- 合并新发现的内容
- 重新计算得分
- 元评审(每5次迭代进行一次)
Phase 5: Convergence Detection
阶段5:收敛检测
Complete when:
- 10 consecutive clean iterations
- All category scores >= 95/100
- All tests passing
- Game runs without crashes
满足以下条件时完成循环:
- 连续10次清洁迭代
- 所有分类得分≥95/100
- 所有测试通过
- 游戏运行无崩溃
State Schema
状态 Schema
json
{
"project": "diablo-starcraft",
"iteration": 0,
"consecutiveCleanIterations": 0,
"requiredCleanIterations": 10,
"completionPromise": "DIABLO_STARCRAFT_COMPLETE",
"categories": {},
"discoveryLog": [],
"lastReviewStyles": [],
"agentHistory": [],
"startedAt": "<timestamp>",
"lastUpdated": "<timestamp>"
}json
{
"project": "diablo-starcraft",
"iteration": 0,
"consecutiveCleanIterations": 0,
"requiredCleanIterations": 10,
"completionPromise": "DIABLO_STARCRAFT_COMPLETE",
"categories": {},
"discoveryLog": [],
"lastReviewStyles": [],
"agentHistory": [],
"startedAt": "<timestamp>",
"lastUpdated": "<timestamp>"
}Categories Schema
分类 Schema
json
{
"categories": {
"<category_name>": {
"score": 50,
"maxScore": 100,
"subcategories": {
"<subcategory_name>": {
"score": 50,
"issues": [],
"lastReviewed": null,
"reviewCount": 0
}
},
"discoveredAt": 0,
"lastUpdated": "<timestamp>"
}
}
}json
{
"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 |
| 风格 | 聚焦点 |
|---|---|
| NITPICKER | 格式、命名、细微不一致性 |
| REFACTORER | 代码重复、抽象优化机会 |
| DRY_ENFORCER | 复制粘贴代码、重复模式 |
| TYPE_ZEALOT | 类型安全、any使用、类型转换 |
| SOLID_ADHERENT | SOLID原则违反 |
| API_PURIST | 接口设计、契约、签名 |
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 |
| 风格 | 聚焦点 |
|---|---|
| DEBUGGER | 逻辑错误、差一错误、运算符误用 |
| EDGE_CASE_HUNTER | 边界条件、null/undefined处理 |
| ERROR_HANDLER | 缺失try/catch、未处理的Promise |
| STATE_MACHINE_ANALYST | 无效状态转换 |
| CONCURRENCY_EXPERT | 竞态条件、异步Bug |
| MEMORY_LEAK_HUNTER | 未移除的监听器、持续增长的数组 |
Performance
性能
| Style | Focus |
|---|---|
| PERFORMANCE_HAWK | O(n²), unnecessary renders, hot paths |
| ALLOCATION_AUDITOR | Object churn, GC pressure |
| RENDER_OPTIMIZER | DOM thrashing, layout thrashing |
| 风格 | 聚焦点 |
|---|---|
| PERFORMANCE_HAWK | O(n²)复杂度、不必要的渲染、热点路径 |
| ALLOCATION_AUDITOR | 对象频繁创建、GC压力 |
| RENDER_OPTIMIZER | DOM频繁操作、布局抖动 |
Security
安全性
| Style | Focus |
|---|---|
| SECURITY_AUDITOR | XSS, injection, unsafe operations |
| INPUT_VALIDATOR | Unsanitized user input |
| 风格 | 聚焦点 |
|---|---|
| SECURITY_AUDITOR | XSS、注入、不安全操作 |
| INPUT_VALIDATOR | 未 sanitize 的用户输入 |
Architecture
架构
| Style | Focus |
|---|---|
| ARCHITECT | Coupling, cohesion, separation of concerns |
| DEPENDENCY_AUDITOR | Circular deps, tight coupling |
| LAYER_GUARDIAN | Layer violations, wrong abstractions |
| 风格 | 聚焦点 |
|---|---|
| ARCHITECT | 耦合度、内聚性、关注点分离 |
| DEPENDENCY_AUDITOR | 循环依赖、紧耦合 |
| LAYER_GUARDIAN | 层级违规、错误抽象 |
Testing
测试
| Style | Focus |
|---|---|
| TEST_SKEPTIC | Coverage gaps, weak assertions |
| MUTATION_TESTER | Tests that always pass |
| INTEGRATION_ANALYST | Unit vs integration gaps |
| 风格 | 聚焦点 |
|---|---|
| TEST_SKEPTIC | 覆盖缺口、弱断言 |
| MUTATION_TESTER | 始终通过的测试用例 |
| INTEGRATION_ANALYST | 单元测试与集成测试的缺口 |
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 |
| 风格 | 聚焦点 |
|---|---|
| DIABLO_VETERAN | ARPG惯例、战利品、技能、战斗手感 |
| STARCRAFT_FAN | 派系特性、单位手感、星际争霸世界观 |
| GAME_FEEL_EXPERT | 游戏反馈、打磨、响应性 |
| BALANCE_DESIGNER | 数值、成长、公平性 |
| PLAYER_PSYCHOLOGY | 玩家动机、奖励循环 |
| SPEEDRUNNER | 游戏漏洞、序列跳过 |
| COMPLETIONIST | 内容中的缺失边缘场景 |
| FIRST_TIME_USER | 新手引导、易混淆点 |
Meta
元评审
| Style | Focus |
|---|---|
| FRESH_EYES | What would confuse a new developer? |
| DOCUMENTATION_STICKLER | Missing/wrong comments |
| FUTURE_MAINTAINER | Technical debt accumulation |
| 风格 | 聚焦点 |
|---|---|
| FRESH_EYES | 新开发者会困惑的点 |
| DOCUMENTATION_STICKLER | 缺失/错误的注释 |
| FUTURE_MAINTAINER | 技术债务累积 |
Agent Output Format
Agent 输出格式
json
{
"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
}json
{
"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
硬性要求
- PLAYABLE_LOCAL - Runs in browser, playable start-to-finish
- TDD_ENFORCED - No fix without failing test first
- ZERO_CRASHES - No unhandled exceptions in any path
- ALL_TESTS_PASS - 100% test suite green
- SCORES_95_PLUS - Every category at 95+/100
- CLEAN_CONVERGENCE - 10 consecutive clean iterations
- PLAYABLE_LOCAL - 可在浏览器中运行,从头至尾可玩
- TDD_ENFORCED - 无失败测试用例则不进行修复
- ZERO_CRASHES - 任何路径下均无未处理异常
- ALL_TESTS_PASS - 测试套件100%通过
- SCORES_95_PLUS - 所有分类得分≥95/100
- CLEAN_CONVERGENCE - 连续10次清洁迭代
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 loopLOOP:
1. 从 .ralph/state.json 加载状态
2. 从 .ralph/categories.json 加载分类
3. 增加迭代计数器
4. 选择3-5个得分最低的分类进行评审
5. 生成并行评审Agent(使用Task工具)
6. 收集所有Agent的发现结果
7. 按严重性排序发现结果(严重→主要→次要)
8. 对每个发现结果执行TDD修复:
a. 编写失败的测试用例
b. 实现最小化修复
c. 验证测试通过
d. 运行完整测试套件
9. 更新得分与状态
10. 检查收敛标准:
- 所有Agent均返回 cleanReview: true?
- 无严重/主要发现结果?
- 所有测试通过?
- 无新分类被发现?
11. 若清洁迭代:consecutiveCleanIterations++
若非清洁迭代:consecutiveCleanIterations = 0
12. 若 consecutiveCleanIterations ≥10 且所有得分≥95:
→ 已收敛:运行最终验证
否则:→ 继续循环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: achieved
{COMPLETION_PROMISE}
当满足收敛标准时:
- 运行完整测试套件
- TypeScript严格模式检查
- 构建生产包
- 验证游戏可加载并正常运行
- 生成完成报告
- 输出:已达成
{COMPLETION_PROMISE}
Game-Specific Categories (Diablo-StarCraft)
游戏特定分类(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)
- engine/ → 引擎(游戏、相机)
- mechanics/ → 机制(玩家、技能、物品)
- ai/ → AI(敌人、寻路)
- graphics/ → 图形(渲染器、视觉特效)
- audio/ → 音频(音频管理器)
- physics/ → 物理(碰撞)
- world/ → 世界(瓦片地图)
- persistence/ → 持久化(存档管理器)
- input/ → 输入(输入管理器)
- utils/ → 工具(等距投影)
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
- Combat → 伤害、抗性、暴击、持续伤害
- Skills → 技能、冷却、成长
- Loot → 掉落、稀有度、装备
- Progression → 经验值、等级、属性
- Waves → 生成、难度、Boss
- UI/HUD → 血条、增益效果、小地图
- Save/Load → 持久化、状态恢复