iterative-loop について
テストの合格や指標など、明確な条件を満たすまで変更と検証を繰り返す、Claude Code 向けの開発スキルです。失敗を次の試行に活用し、反復回数の上限や停滞時の対応も定めます。
主な機能
- 01測定可能な完了条件に沿った反復
- 02各回でのテストと検証
- 03失敗を次の変更に反映
- 04反復上限と停滞時の対応設定
- 05エージェントの並列反復
活用シーン
- 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
- 明確な完了基準(テスト、リンティング、メトリクス)
- 反復を追跡するためのバージョン管理(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:検証しながら実行する
各反復では、次の作業を行います。
- 対象を絞った変更を加える
- 検証を実行する(テスト、リンティング、ビルド)
- 結果を分析する
- フィードバックに基づいて次の反復を計画する
# 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 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
スウォームで連携する反復
複雑なタスクでは、複数のエージェントを使って並行して反復します。
# 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>
反復ループを使用する場面
適しています:
- 明確に定義され、成功を測定できるタスク
- テスト駆動開発
- 再現可能なテストがあるバグ修正
- カバレッジの改善
- パフォーマンスの最適化
- リンティングやフォーマットの修正
適していません:
- 人間の判断が必要なタスク
- 設計上の決定
- 曖昧または主観的な目標
- 一度限りの操作
- テストなしで行う本番環境のデバッグ
トラブルシューティング
問題:無限ループ/進捗がない
症状:改善がないまま、同じエラーが繰り返されます
解決策:
- 完了基準をより具体的にする
- 別のアプローチを用いる「停滞検出」を追加する
- 最大反復回数を減らす
- タスクをより小さなフェーズに分割する
問題:誤った完了判定
症状:タスクが実際には完了していないのに、ループが終了します
解決策:
- 検証コマンドを追加する
- 完了基準をより明確にする
- 単体テストと並行して統合テストを追加する
問題:後続の反復でデグレードが発生する
症状:新しい変更の後、以前は成功していたテストが失敗します
解決策:
- リグレッション確認の手順を追加する
- git を使って反復間の変更を比較する
- より小さく、対象を絞った変更を実施する
関連スキル
- tdd-london-chicago - 反復開発のための TDD アプローチ
- qe-iterative-loop - AQE v3 フリート固有の反復パターン
- hooks-automation - 自動化のための Claude Flow フック
リソース
- Ralph Wiggum Technique - 元の手法
- Ralph Orchestrator - オーケストレーションツール
- Claude Code Plugins - 公式プラグイン
起源: claude-code リポジトリ(anthropics/claude-code)の Ralph Wiggum プラグインに基づいています 適用先: Claude Flow と統合した Agentic QE v3
コメント
Markdown 対応