关于 iterative-loop
面向 Claude Code 的迭代开发技能,让 Agent 根据测试、Lint 和指标等明确条件反复修改,直到任务完成。它强调逐轮验证、从失败中调整,并为循环设置次数上限和停滞处理规则。
主要功能
- 01依据可测量条件迭代开发
- 02每轮运行测试与验证
- 03利用失败结果调整后续修改
- 04设置最大迭代次数与停滞处理
- 05支持并行 Agent 迭代
适用场景
- 01通过测试驱动开发实现功能
- 02修复可复现的缺陷
- 03提高测试覆盖率
- 04根据基准结果优化性能
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ proffesor-for-testing/ agentic-qe --skill iterative-loop安装后在 Claude Code 中输入/iterative-loop确认已加载。
详细介绍
迭代循环
概述
迭代循环技能实现了由 AI 驱动的持续开发循环,并会一直运行,直到满足完成标准。受 Ralph Wiggum 技术启发,这种方法能够实现自主、自我纠正的开发周期:AI 可以通过文件和 Git 历史查看之前的工作,并不断迭代改进,直到成功。
核心理念
- 迭代胜过完美——不要追求一次就做到完美;让循环不断完善成果
- 失败也是数据——每次失败都能提供信息,帮助改进下一次尝试
- 标准要明确——成功必须可以客观衡量(测试、指标、验证)
- 坚持就能成功——持续尝试直到成功;循环会自动处理重试逻辑
前提条件
- 支持会话管理的 Claude Code
- 明确的完成标准(测试、Lint、指标)
- 用于跟踪迭代的版本控制(git)
快速开始
基本迭代式开发模式
# Define task with clear completion criteria
TASK="Implement user authentication with JWT.
Success criteria:
- All unit tests pass
- Integration tests pass
- No TypeScript errors
- Security audit passes
Output <promise>COMPLETE</promise> when all criteria met."
# Execute iterative loop (conceptual)
while ! task_complete; do
claude_execute "$TASK"
check_completion_criteria
done
AQE v3 集成示例
# Using claude-flow hooks for iterative task
npx --no-install ruflo hooks pre-task --description "Implement auth with iteration" --taskId "auth-impl"
# Store iteration state in memory
npx --no-install ruflo memory store \
--key "iteration-auth" \
--value '{"iteration": 1, "maxIterations": 20, "criteria": "all tests pass"}' \
--namespace iterations
分步指南
第 1 步:明确成功标准
必不可少:每项迭代任务都必须有可客观衡量的完成标准。
良好标准示例:
✅ All unit tests pass (npm test returns exit code 0)
✅ Coverage > 80% (coverage report shows 80%+)
✅ No TypeScript errors (tsc --noEmit returns 0)
✅ Linting passes (eslint returns 0)
✅ Performance < 100ms (benchmark shows < 100ms)
不良标准示例:
❌ "Code looks good" (subjective)
❌ "Works properly" (undefined)
❌ "Well-structured" (no measurable check)
第 2 步:将任务划分为多个阶段
将复杂任务拆分为渐进式阶段:
## Task: Implement User Authentication
### Phase 1: Data Layer
- Create User model with Prisma schema
- Write migration
- Run tests: `npm test -- --grep "User model"`
- Criteria: Model tests pass
### Phase 2: Service Layer
- Implement AuthService with JWT
- Add token generation/validation
- Run tests: `npm test -- --grep "AuthService"`
- Criteria: Service tests pass
### Phase 3: API Layer
- Create /auth/login endpoint
- Create /auth/register endpoint
- Run tests: `npm test -- --grep "auth API"`
- Criteria: API tests pass
### Phase 4: Integration
- End-to-end authentication flow
- Run tests: `npm test`
- Criteria: ALL tests pass
Output <promise>AUTH_COMPLETE</promise> when Phase 4 passes.
第 3 步:实施安全机制
始终设置退出条件:
## Safety Rules
1. **Max Iterations**: Stop after 20 attempts
2. **Stuck Detection**: After 5 iterations without progress:
- Document what's blocking
- List attempted approaches
- Suggest alternative strategies
3. **Critical Errors**: Stop immediately if:
- Database corruption detected
- Security vulnerability introduced
- Breaking changes to existing features
第 4 步:执行并验证
每次迭代都应:
- 进行有针对性的更改
- 运行验证(测试、Lint、构建)
- 分析结果
- 根据反馈规划下一次迭代
# Iteration pattern
1. Read previous state (files, git log)
2. Identify remaining work
3. Implement specific change
4. Run verification suite
5. If all pass -> output completion promise
6. If failures -> analyze and continue iteration
迭代模式
模式 1:测试驱动迭代
## TDD Iteration Task
1. Write failing test for [feature]
2. Implement minimal code to pass test
3. Run `npm test`
4. If test fails -> debug and fix implementation
5. If test passes -> check if more tests needed
6. Repeat until all acceptance tests pass
7. Refactor if needed
8. Output <promise>TDD_COMPLETE</promise>
模式 2:Bug 修复迭代
## Bug Fix Task
1. Write failing test that reproduces bug
2. Implement fix
3. Run test suite
4. If reproduction test fails -> analyze why fix didn't work
5. If other tests fail -> fix regressions
6. If all tests pass -> output <promise>BUG_FIXED</promise>
Max iterations: 10
After 5 iterations without fix:
- Document root cause analysis
- Suggest alternative approaches
模式 3:提升覆盖率迭代
## Coverage Improvement Task
Target: 80% line coverage
1. Run coverage analysis
2. Identify uncovered code paths
3. Write test for highest-impact uncovered path
4. Run tests with coverage
5. If coverage >= 80% -> output <promise>COVERAGE_ACHIEVED</promise>
6. If coverage < 80% -> continue iteration
Max iterations: 30
Progress check: If coverage doesn't improve for 3 iterations -> analyze blockers
模式 4:性能优化迭代
## Performance Optimization Task
Target: Response time < 100ms
1. Run performance benchmark
2. Identify slowest operation
3. Implement optimization
4. Run benchmark again
5. If target met -> output <promise>PERF_TARGET_MET</promise>
6. If not improved -> try different approach
Max iterations: 15
Record metrics each iteration for trend analysis
与 Claude Flow 集成
增强记忆的迭代
# Store iteration state
npx --no-install ruflo memory store \
--key "current-iteration" \
--value '{"task": "auth", "iteration": 5, "lastResult": "2 tests failing"}' \
--namespace iterations
# Search for similar past iterations
npx --no-install ruflo memory search \
--query "auth implementation" \
--namespace iterations
# Learn from successful completions
npx --no-install ruflo hooks post-task \
--taskId "auth-impl" \
--success true \
--quality 0.9
Swarm 协同迭代
对于复杂任务,可使用多个 Agent 并行迭代:
# Initialize swarm for parallel iteration
npx --no-install ruflo swarm init --topology mesh --max-agents 5
# Spawn specialized iterators
Task("Iterate on unit tests", "Fix failing unit tests until all pass", "tester")
Task("Iterate on integration", "Fix integration tests until all pass", "tester")
Task("Iterate on performance", "Optimize until benchmarks pass", "performance-engineer")
最佳实践
迭代提示词工程
应包含:
- 明确的完成标准及验证命令
- 复杂任务的分阶段拆解
- 安全限制(最大迭代次数)
- 进度跟踪说明
- 卡住时的检测和恢复流程
结构良好的提示词示例:
## Task: Implement Feature X
### Success Criteria (ALL must pass):
1. `npm test` exits with code 0
2. `npm run lint` exits with code 0
3. `npm run typecheck` exits with code 0
4. No console.log statements in production code
### Phases:
1. Write failing tests
2. Implement feature
3. Fix any failures
4. Clean up and refactor
### Safety:
- Max iterations: 20
- After 10 iterations: summarize blockers
- Stop if security issues detected
### Completion:
When ALL success criteria pass, output:
<promise>FEATURE_X_COMPLETE</promise>
何时使用迭代循环
适用场景:
- 定义明确且成功可衡量的任务
- 测试驱动开发
- 有可复现测试的 Bug 修复
- 提升覆盖率
- 性能优化
- 修复 Lint / 格式问题
不适用场景:
- 需要人工判断的任务
- 设计决策
- 目标模糊或主观的任务
- 一次性操作
- 没有测试的生产环境调试
故障排查
问题:无限循环 / 没有进展
症状:相同错误反复出现,没有改善
解决方案:
- 提高完成标准的明确程度
- 增加“卡住检测”机制,并提供替代方案
- 降低最大迭代次数
- 将任务拆分为更小的阶段
问题:误判为完成
症状:循环结束,但任务实际上尚未完成
解决方案:
- 添加更多验证命令
- 明确完成标准
- 在单元测试之外添加集成测试
问题:后续迭代引入回归
症状:新增更改后,之前通过的测试失败
解决方案:
- 添加回归检查步骤
- 使用 git 对比各次迭代
- 实施更小、更有针对性的更改
相关技能
- tdd-london-chicago - 适用于迭代开发的 TDD 方法
- qe-iterative-loop - 针对 AQE v3 fleet 的迭代模式
- hooks-automation - 用于自动化的 Claude Flow hooks
资源
- Ralph Wiggum Technique - 原始方法论
- Ralph Orchestrator - 编排工具
- Claude Code Plugins - 官方插件
来源:基于 claude-code 仓库(anthropics/claude-code)中的 Ralph Wiggum 插件 适配对象:集成 Claude Flow 的 Agentic QE v3
评论
支持 Markdown