🤖
寝ている間にAIがコードを書いてくれるralph loopを簡単に試せるようにした
最近,X で Ryan Carson さんが紹介していた Ralph という自律コーディングエージェントのループに触発されて,自分でも似たものを作ってみました.
アイデアは,AI エージェントにタスクリストを与えて,自動でタスクを選択・実装・テスト・コミットし,進捗を更新しながらループを回すというものです.
そこで,どんな CLI ベースの AI エージェントでも使えるシンプルなものを作ってみました.
元々は claude code の plugin として実装されていたようです.
以下のリポジトリで ralph がどんなものか簡単に試すことができます.
https://github.com/syuya2036/ralph-loop
Ralph とは?
Ralph は,bash スクリプトで実装された自律的なコーディングループです.
- タスクリスト(
prd.json)とコンテキストプロンプトを AI エージェントに渡す - AI がストーリーを 1 つ選んで実装し,テストを実行,コミット,進捗を更新
- すべてのストーリーが完了するまで繰り返す
2 の部分で AI エージェントは進捗や学んだことを適宜progress.txtに書きこみ,次のループでそれをまた参照します.
また,タスク単位でブランチを切ってくれます.
セットアップ
-
リポジトリをクローン
git clone https://github.com/syuya2036/ralph-loop.git cd ralph-loop -
タスクリストを作成:
prd.jsonにユーザーストーリーを書く- サンプルとしてrustで簡単なwcコマンドを実装するタスクリストが入っています.
prd.jsonのサンプル
{
"branchName": "feat/mini-wc-cli",
"userStories": [
{
"id": "US-001",
"title": "Initialize Rust project and Basic Setup",
"acceptanceCriteria": [
"Initialize a new binary project with cargo init if Cargo.toml doesn't exist",
"Create a main.rs that prints 'Hello, mini-wc!'",
"cargo run executes successfully",
"cargo check passes"
],
"priority": 1,
"passes": false,
"notes": ""
},
{
"id": "US-002",
"title": "Add Argument Parsing",
"acceptanceCriteria": [
"Add clap dependency to Cargo.toml",
"Update main.rs to accept a file path as an argument",
"If no argument is provided, print usage help",
"cargo check passes"
],
"priority": 2,
"passes": false,
"notes": ""
},
{
"id": "US-003",
"title": "Implement Line Counting",
"acceptanceCriteria": [
"Read the file specified by the argument",
"Count the number of lines in the file",
"Print the line count to stdout (e.g., 'Lines: 10')",
"Handle file not found errors gracefully",
"cargo test passes (add a unit test for counting logic if possible)"
],
"priority": 3,
"passes": false,
"notes": ""
},
{
"id": "US-004",
"title": "Implement Word and Byte Counting",
"acceptanceCriteria": [
"Extend logic to count words and bytes as well",
"Print all three stats: Lines, Words, Bytes",
"Ensure format is readable",
"cargo test passes"
],
"priority": 4,
"passes": false,
"notes": ""
}
]
}
- 実行権限を付与
chmod +x ./ralph-loop/ralph.sh
使い方
スクリプトを実行し,第一引数に AI エージェントの CLI コマンドを渡します.
prd.json のタスクが終了するまでループが周りますが,安全のために第二引数で最大ループ回数を指定できます.
./ralph-loop/ralph.sh "<YOUR_AGENT_COMMAND>" [MAX_ITERATIONS]
具体例
Codex CLI
./ralph-loop/ralph.sh "codex exec --full-auto" 20
Gemini CLI
./ralph-loop/ralph.sh "gemini --yolo" 20
Qwen Code
設定で YOLO モードを有効にしてから:
./ralph-loop/ralph.sh "qwen" 20
まとめ
ralph loop をどんな ai エージェントでも簡単に使えるようにしてみました.
興味があればぜひ試してみてください!
→ https://github.com/syuya2036/ralph-loop
Discussion