@graypark/ralph-codex 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +25 -0
- package/README.md +163 -85
- package/bin/install.mjs +1 -1
- package/bin/uninstall.mjs +6 -1
- package/package.json +7 -3
- package/skills/ralph-interview/SKILL.md +58 -0
- package/skills/ralph-orchestrator/SKILL.md +211 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ralph-codex",
|
|
3
|
+
"description": "Cross-platform Ralph Loop with interactive interview, multi-agent orchestration, and smart command generation. Run AI in self-referential iterative loops until task completion.",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "graypark",
|
|
6
|
+
"email": "vcz.graypark@gmail.com",
|
|
7
|
+
"url": "https://github.com/vcz-Gray"
|
|
8
|
+
},
|
|
9
|
+
"version": "0.4.0",
|
|
10
|
+
"repository": "https://github.com/vcz-Gray/ralph-codex",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ralph-loop",
|
|
14
|
+
"iterative-development",
|
|
15
|
+
"multi-agent",
|
|
16
|
+
"orchestration",
|
|
17
|
+
"stop-hook",
|
|
18
|
+
"cross-platform"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"claude-code": ">=1.0.0",
|
|
22
|
+
"codex-cli": ">=0.114.0"
|
|
23
|
+
},
|
|
24
|
+
"compatibility": ["claude-code", "codex-cli"]
|
|
25
|
+
}
|
package/README.md
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
# ralph-codex
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Self-referential iterative development loops for **Codex CLI** and **Claude Code** — with multi-agent orchestration, interactive command generation, and cross-platform stop hooks.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## What is Ralph Loop?
|
|
6
|
+
|
|
7
|
+
An AI agent works on a task in a continuous loop, seeing its own previous work each iteration, until a completion condition is met. ralph-codex adds smart orchestration on top: automatic phase splitting, parallel subagent spawning, and an interview-driven command generator.
|
|
6
8
|
|
|
7
9
|
## Requirements
|
|
8
10
|
|
|
9
11
|
- **Node.js** 18+
|
|
10
|
-
- **Codex CLI** v0.114+ (
|
|
12
|
+
- **Codex CLI** v0.114+ or **Claude Code** (any version with plugin support)
|
|
11
13
|
|
|
12
14
|
## Installation
|
|
13
15
|
|
|
14
|
-
###
|
|
16
|
+
### npx (recommended)
|
|
15
17
|
|
|
16
18
|
```bash
|
|
17
19
|
npx @graypark/ralph-codex --global
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
###
|
|
22
|
+
### Git clone
|
|
21
23
|
|
|
22
24
|
```bash
|
|
23
25
|
git clone https://github.com/vcz-Gray/ralph-codex.git
|
|
@@ -27,158 +29,234 @@ node bin/install.mjs --global
|
|
|
27
29
|
|
|
28
30
|
### Options
|
|
29
31
|
|
|
30
|
-
| Flag | Description
|
|
31
|
-
| ----------- |
|
|
32
|
-
| `--global` | Install to `~/.codex/` (default)
|
|
33
|
-
| `--local` | Install to `.codex/` in current project
|
|
34
|
-
| `--dry-run` | Preview changes without modifying anything
|
|
35
|
-
| `--force` | Overwrite existing installation
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
32
|
+
| Flag | Description |
|
|
33
|
+
| ----------- | ------------------------------------------------ |
|
|
34
|
+
| `--global` | Install to `~/.codex/` or `~/.claude/` (default) |
|
|
35
|
+
| `--local` | Install to `.codex/` in current project |
|
|
36
|
+
| `--dry-run` | Preview changes without modifying anything |
|
|
37
|
+
| `--force` | Overwrite existing installation |
|
|
38
38
|
|
|
39
|
-
###
|
|
40
|
-
|
|
41
|
-
In Codex CLI, use the slash command:
|
|
39
|
+
### What Gets Installed
|
|
42
40
|
|
|
43
41
|
```
|
|
44
|
-
/
|
|
42
|
+
~/.codex/ (or ~/.claude/)
|
|
43
|
+
├── plugins/ralph-codex/ # Core plugin files
|
|
44
|
+
├── hooks.json # Stop hook (merged with existing)
|
|
45
|
+
└── skills/
|
|
46
|
+
├── ralph-loop/ # /ralph-loop — run loops
|
|
47
|
+
├── cancel-ralph/ # /cancel-ralph — stop loops
|
|
48
|
+
├── ralph-interview/ # /ralph-interview — generate commands
|
|
49
|
+
└── ralph-orchestrator/ # /ralph-orchestrator — multi-agent patterns
|
|
45
50
|
```
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
## Commands
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
| --------------------------- | ---------- | --------------------------------------- |
|
|
51
|
-
| `PROMPT` | (required) | Task description |
|
|
52
|
-
| `--max-iterations N` | 20 | Maximum loop iterations (0 = unlimited) |
|
|
53
|
-
| `--completion-promise TEXT` | "TADA" | Phrase that signals task completion |
|
|
54
|
+
### `/ralph-interview` — Smart Command Generator
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
**The recommended way to start.** Interviews you about your task, evaluates whether subagents would help, then generates an optimized command.
|
|
56
57
|
|
|
57
58
|
```
|
|
58
|
-
/
|
|
59
|
+
/ralph-interview
|
|
59
60
|
```
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
1. Describe your task
|
|
63
|
+
2. Answer 3–5 targeted questions (scope, verification, parallelism potential, etc.)
|
|
64
|
+
3. Get a ready-to-run command with phases, escape hatches, and orchestration
|
|
62
65
|
|
|
63
|
-
|
|
66
|
+
**Auto-execute:** Add "run immediately" or "바로 실행" to start without confirmation:
|
|
64
67
|
|
|
65
68
|
```
|
|
66
|
-
/ralph-interview
|
|
69
|
+
/ralph-interview Refactor the auth module across 3 services, run immediately
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
### `/ralph-orchestrator` — Multi-Agent Patterns
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
Analyzes your task and recommends the best orchestration strategy:
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
| Pattern | Best For |
|
|
77
|
+
| ------------------------------------------- | ------------------------------------------------- |
|
|
78
|
+
| **Parallel Explore → Sequential Implement** | Large codebase research + targeted fixes |
|
|
79
|
+
| **Divide by Ownership** | Multi-service changes (frontend + backend + auth) |
|
|
80
|
+
| **Fan-Out / Fan-In** | Comprehensive audits (security + perf + a11y) |
|
|
81
|
+
| **Scout-Then-Execute** | Unfamiliar codebases |
|
|
82
|
+
| **Pipeline with Checkpoints** | Complex multi-stage transformations |
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
**Decision matrix** — the orchestrator scores your task automatically:
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
```
|
|
87
|
+
Files span 3+ directories → +2
|
|
88
|
+
Items are independent → +2
|
|
89
|
+
Multiple services/repos → +3
|
|
90
|
+
10+ similar items → +1
|
|
91
|
+
Need full context → -2
|
|
92
|
+
Order matters → -2
|
|
93
|
+
|
|
94
|
+
Score >= 3 → Parallel subagents
|
|
95
|
+
Score 0–2 → Sequential + optional scout
|
|
96
|
+
Score < 0 → Single loop
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `/ralph-loop` — Run a Loop Directly
|
|
84
100
|
|
|
85
101
|
```
|
|
86
|
-
|
|
102
|
+
/ralph-loop "Build a REST API" --max-iterations 30 --completion-promise "ALL_TESTS_PASS"
|
|
87
103
|
```
|
|
88
104
|
|
|
89
|
-
|
|
105
|
+
| Parameter | Default | Description |
|
|
106
|
+
| --------------------------- | ---------- | ------------------------------ |
|
|
107
|
+
| `PROMPT` | (required) | Task description |
|
|
108
|
+
| `--max-iterations N` | 20 | Max iterations (0 = unlimited) |
|
|
109
|
+
| `--completion-promise TEXT` | "TADA" | Phrase that signals completion |
|
|
110
|
+
|
|
111
|
+
### `/cancel-ralph` — Stop the Loop
|
|
90
112
|
|
|
91
|
-
|
|
113
|
+
```
|
|
114
|
+
/cancel-ralph
|
|
115
|
+
```
|
|
92
116
|
|
|
93
|
-
|
|
117
|
+
## How the Loop Works
|
|
94
118
|
|
|
95
119
|
```
|
|
96
|
-
|
|
120
|
+
┌─────────────────────────────────────────────┐
|
|
121
|
+
│ /ralph-loop "Build feature X" │
|
|
122
|
+
│ │
|
|
123
|
+
│ ┌──────────┐ ┌──────────┐ │
|
|
124
|
+
│ │ Agent │───▶│ Works │ │
|
|
125
|
+
│ │ starts │ │ on task │ │
|
|
126
|
+
│ └──────────┘ └────┬─────┘ │
|
|
127
|
+
│ │ │
|
|
128
|
+
│ ▼ │
|
|
129
|
+
│ ┌──────────────┐ │
|
|
130
|
+
│ │ Tries to exit │ │
|
|
131
|
+
│ └───────┬──────┘ │
|
|
132
|
+
│ │ │
|
|
133
|
+
│ ▼ │
|
|
134
|
+
│ ┌───────────────────┐ │
|
|
135
|
+
│ │ Stop Hook │ │
|
|
136
|
+
│ │ ┌───────────────┐ │ │
|
|
137
|
+
│ │ │ Max reached? │─┼──Yes──▶ EXIT
|
|
138
|
+
│ │ │ Promise found?│─┼──Yes──▶ EXIT
|
|
139
|
+
│ │ └───────┬───────┘ │ │
|
|
140
|
+
│ │ No │ │
|
|
141
|
+
│ │ Block exit + │ │
|
|
142
|
+
│ │ re-inject prompt │ │
|
|
143
|
+
│ └─────────┬─────────┘ │
|
|
144
|
+
│ │ │
|
|
145
|
+
│ ┌──────────────┐ │
|
|
146
|
+
│ │ Sees previous │──── loop ────┘
|
|
147
|
+
│ │ work in files │
|
|
148
|
+
│ └──────────────┘
|
|
97
149
|
```
|
|
98
150
|
|
|
99
|
-
|
|
151
|
+
## Multi-Agent Orchestration Example
|
|
152
|
+
|
|
153
|
+
For a task like "audit and fix auth across frontend, backend, and auth-service":
|
|
100
154
|
|
|
101
155
|
```
|
|
102
|
-
|
|
156
|
+
Phase 1 — Parallel Exploration (3 subagents):
|
|
157
|
+
├── Agent "fe-scan": Search frontend for auth issues → report
|
|
158
|
+
├── Agent "be-scan": Search backend for auth issues → report
|
|
159
|
+
└── Agent "auth-scan": Search auth-service for issues → report
|
|
160
|
+
|
|
161
|
+
Phase 2 — Merge & Plan:
|
|
162
|
+
└── Ralph Loop: Read all reports → create prioritized fix plan
|
|
163
|
+
|
|
164
|
+
Phase 3 — Parallel Implementation:
|
|
165
|
+
├── Agent "fe-dev" (worktree): Fix frontend items
|
|
166
|
+
├── Agent "be-dev" (worktree): Fix backend items
|
|
167
|
+
└── Agent "auth-dev" (worktree): Fix auth-service items
|
|
168
|
+
|
|
169
|
+
Phase 4 — Integration:
|
|
170
|
+
└── Ralph Loop: Merge branches → run full test suite → fix conflicts
|
|
103
171
|
```
|
|
104
172
|
|
|
105
|
-
|
|
173
|
+
The `/ralph-interview` skill generates this automatically when it detects multi-service scope.
|
|
106
174
|
|
|
107
|
-
|
|
175
|
+
## Updating
|
|
108
176
|
|
|
109
|
-
|
|
177
|
+
To update to the latest version:
|
|
110
178
|
|
|
179
|
+
```bash
|
|
180
|
+
npx @graypark/ralph-codex --global --force
|
|
111
181
|
```
|
|
112
|
-
|
|
182
|
+
|
|
183
|
+
Or if installed via git:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
cd ralph-codex
|
|
187
|
+
git pull
|
|
188
|
+
node bin/install.mjs --global --force
|
|
113
189
|
```
|
|
114
190
|
|
|
115
191
|
## Windows Support
|
|
116
192
|
|
|
117
|
-
|
|
193
|
+
Works natively on Windows without WSL or Git Bash:
|
|
118
194
|
|
|
119
195
|
- All paths use `path.join()` (no hardcoded slashes)
|
|
120
|
-
-
|
|
196
|
+
- Installer copies files instead of symlinks on Windows
|
|
121
197
|
- State files use JSON (no Unix-specific formats)
|
|
122
198
|
- Hooks use `node` as the interpreter (cross-platform)
|
|
123
199
|
|
|
124
|
-
Tested on: Windows 10/11, macOS, Linux (Ubuntu/Debian).
|
|
125
|
-
|
|
126
200
|
## Uninstall
|
|
127
201
|
|
|
128
202
|
```bash
|
|
129
203
|
npx @graypark/ralph-codex uninstall
|
|
130
|
-
# or
|
|
131
|
-
node bin/uninstall.mjs --global
|
|
132
204
|
```
|
|
133
205
|
|
|
134
|
-
|
|
206
|
+
## Claude Code Plugin
|
|
135
207
|
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
208
|
+
This package includes a `.claude-plugin/plugin.json` manifest for Claude Code marketplace compatibility. To use as a Claude Code plugin:
|
|
209
|
+
|
|
210
|
+
1. Clone the repo to your machine
|
|
211
|
+
2. In Claude Code, reference the plugin directory
|
|
212
|
+
3. Skills (`ralph-interview`, `ralph-orchestrator`, etc.) will be auto-discovered
|
|
140
213
|
|
|
141
214
|
## Architecture
|
|
142
215
|
|
|
143
216
|
```
|
|
144
217
|
ralph-codex/
|
|
218
|
+
├── .claude-plugin/
|
|
219
|
+
│ └── plugin.json # Claude Code marketplace manifest
|
|
145
220
|
├── bin/
|
|
146
|
-
│ ├── install.mjs
|
|
147
|
-
│ └── uninstall.mjs
|
|
221
|
+
│ ├── install.mjs # Cross-platform installer
|
|
222
|
+
│ └── uninstall.mjs # Clean uninstaller
|
|
148
223
|
├── hooks/
|
|
149
|
-
│ ├── hooks.json
|
|
150
|
-
│ └── stop-hook.mjs
|
|
224
|
+
│ ├── hooks.json # Hook registration (reference)
|
|
225
|
+
│ └── stop-hook.mjs # Stop hook — core loop engine
|
|
151
226
|
├── commands/
|
|
152
|
-
│ ├── ralph-loop.md
|
|
153
|
-
│ └── cancel-ralph.md
|
|
227
|
+
│ ├── ralph-loop.md # /ralph-loop command
|
|
228
|
+
│ └── cancel-ralph.md # /cancel-ralph command
|
|
229
|
+
├── skills/
|
|
230
|
+
│ ├── ralph-interview/
|
|
231
|
+
│ │ └── SKILL.md # Interactive command generator
|
|
232
|
+
│ └── ralph-orchestrator/
|
|
233
|
+
│ └── SKILL.md # Multi-agent orchestration patterns
|
|
154
234
|
├── lib/
|
|
155
|
-
│ ├── paths.mjs
|
|
156
|
-
│
|
|
235
|
+
│ ├── paths.mjs # Cross-platform path utilities
|
|
236
|
+
│ ├── state.mjs # Loop state management
|
|
237
|
+
│ └── stop-hook-core.mjs # Testable stop hook logic
|
|
238
|
+
├── tests/ # 32 test cases (vitest)
|
|
157
239
|
└── package.json
|
|
158
240
|
```
|
|
159
241
|
|
|
160
|
-
##
|
|
242
|
+
## Comparison
|
|
161
243
|
|
|
162
|
-
| Feature
|
|
163
|
-
|
|
|
164
|
-
| Runtime
|
|
165
|
-
|
|
|
166
|
-
|
|
|
167
|
-
|
|
|
168
|
-
|
|
|
169
|
-
|
|
|
244
|
+
| Feature | Claude Code (official) | Codex CLI (builtin) | ralph-codex (this) |
|
|
245
|
+
| ---------------------- | ---------------------- | ------------------- | ------------------------ |
|
|
246
|
+
| Runtime | Bash (sh/perl) | Rust | Node.js (cross-platform) |
|
|
247
|
+
| Windows | WSL required | Experimental | Native |
|
|
248
|
+
| Hook protocol | JSON | JSON | Same |
|
|
249
|
+
| Command generator | None | None | `/ralph-interview` |
|
|
250
|
+
| Multi-agent | Manual | Experimental | `/ralph-orchestrator` |
|
|
251
|
+
| Orchestration patterns | None | None | 5 built-in patterns |
|
|
252
|
+
| Plugin format | `.claude-plugin` | `.codex/skills` | Both |
|
|
170
253
|
|
|
171
254
|
## Development
|
|
172
255
|
|
|
173
256
|
```bash
|
|
174
|
-
# Install dev dependencies
|
|
175
257
|
npm install
|
|
176
|
-
|
|
177
|
-
#
|
|
178
|
-
npm test
|
|
179
|
-
|
|
180
|
-
# Run tests in watch mode
|
|
181
|
-
npx vitest
|
|
258
|
+
npm test # 32 test cases
|
|
259
|
+
npx vitest # watch mode
|
|
182
260
|
```
|
|
183
261
|
|
|
184
262
|
## License
|
package/bin/install.mjs
CHANGED
|
@@ -174,7 +174,7 @@ async function installSkills() {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// Standalone skills (ralph-interview, etc.)
|
|
177
|
-
const standaloneSkills = ["ralph-interview"];
|
|
177
|
+
const standaloneSkills = ["ralph-interview", "ralph-orchestrator"];
|
|
178
178
|
for (const name of standaloneSkills) {
|
|
179
179
|
const srcDir = join(PROJECT_ROOT, "skills", name);
|
|
180
180
|
const destDir = join(skillsDir, name);
|
package/bin/uninstall.mjs
CHANGED
|
@@ -83,7 +83,12 @@ export async function uninstall({ dryRun = false, local = false } = {}) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// 3. Remove skill directories
|
|
86
|
-
const skillNames = [
|
|
86
|
+
const skillNames = [
|
|
87
|
+
"ralph-loop",
|
|
88
|
+
"cancel-ralph",
|
|
89
|
+
"ralph-interview",
|
|
90
|
+
"ralph-orchestrator",
|
|
91
|
+
];
|
|
87
92
|
for (const name of skillNames) {
|
|
88
93
|
const skillDir = join(skillsDir, name);
|
|
89
94
|
if (await fileExists(skillDir)) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graypark/ralph-codex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Ralph Loop for
|
|
5
|
+
"description": "Ralph Loop for Codex CLI & Claude Code — iterative dev loops with multi-agent orchestration, interactive interview, and stop hooks",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "graypark",
|
|
8
8
|
"repository": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"commands/",
|
|
26
26
|
"lib/",
|
|
27
27
|
"skills/",
|
|
28
|
+
".claude-plugin/",
|
|
28
29
|
"README.md",
|
|
29
30
|
"LICENSE"
|
|
30
31
|
],
|
|
@@ -42,7 +43,10 @@
|
|
|
42
43
|
"ai-agent",
|
|
43
44
|
"iterative-development",
|
|
44
45
|
"stop-hook",
|
|
45
|
-
"cross-platform"
|
|
46
|
+
"cross-platform",
|
|
47
|
+
"multi-agent",
|
|
48
|
+
"orchestration",
|
|
49
|
+
"claude-code"
|
|
46
50
|
],
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"vitest": "^4.1.0"
|
|
@@ -15,6 +15,7 @@ When the user describes a task, conduct a brief interview to gather missing cont
|
|
|
15
15
|
- **Escape hatches required**: Always specify what to do when stuck after N retries.
|
|
16
16
|
- **Atomic commits**: Instruct a git commit per logical work unit.
|
|
17
17
|
- **Objective completion criteria only**: Never use subjective criteria like "make it good." Use test passes, linter clears, checklist completion, or other verifiable conditions.
|
|
18
|
+
- **Parallel when possible**: Use the ralph-orchestrator patterns to spawn subagents for independent work streams (exploration, multi-service changes, audits).
|
|
18
19
|
|
|
19
20
|
## Interview Process
|
|
20
21
|
|
|
@@ -34,6 +35,7 @@ Skip items already covered. Bundle questions — max 3–5 per round, one round
|
|
|
34
35
|
| **Constraints** | Must not break existing tests? Library restrictions? |
|
|
35
36
|
| **When stuck** | User's preferred fallback (document it? skip? suggest alternative?) |
|
|
36
37
|
| **Commit strategy** | Per-item commits? Bulk? Commit message convention? |
|
|
38
|
+
| **Parallelism potential** | Multiple services? Independent file groups? Broad search needed? |
|
|
37
39
|
|
|
38
40
|
## Phase Design
|
|
39
41
|
|
|
@@ -44,6 +46,30 @@ Skip items already covered. Bundle questions — max 3–5 per round, one round
|
|
|
44
46
|
- **Dependencies exist** → Prerequisite work in a prior Phase
|
|
45
47
|
- **5 or fewer simple items** → Single Phase is fine
|
|
46
48
|
|
|
49
|
+
### When to Use Subagents (via ralph-orchestrator)
|
|
50
|
+
|
|
51
|
+
Evaluate the task against the ralph-orchestrator decision matrix:
|
|
52
|
+
|
|
53
|
+
| Factor | Score |
|
|
54
|
+
| ------------------------------ | ----- |
|
|
55
|
+
| Files span 3+ directories | +2 |
|
|
56
|
+
| Items are independent | +2 |
|
|
57
|
+
| Need full context to decide | -2 |
|
|
58
|
+
| Order matters | -2 |
|
|
59
|
+
| 10+ similar items | +1 |
|
|
60
|
+
| Needs cross-file understanding | -1 |
|
|
61
|
+
| Multiple services/repos | +3 |
|
|
62
|
+
|
|
63
|
+
- **Score >= 3** → Use parallel subagents. Pick from orchestrator patterns:
|
|
64
|
+
- _Parallel Explore → Sequential Implement_ for research-heavy tasks
|
|
65
|
+
- _Divide by Ownership_ for multi-service changes
|
|
66
|
+
- _Fan-Out / Fan-In_ for comprehensive audits
|
|
67
|
+
- _Scout-Then-Execute_ for unfamiliar codebases
|
|
68
|
+
- **Score 0–2** → Sequential loop, optional scout phase
|
|
69
|
+
- **Score < 0** → Single sequential Ralph Loop
|
|
70
|
+
|
|
71
|
+
When subagents are recommended, embed subagent spawn instructions directly in the generated ralph-loop prompt using the Agent tool (Claude Code) or experimental multi-agent config (Codex CLI).
|
|
72
|
+
|
|
47
73
|
### Recommended max-iterations
|
|
48
74
|
|
|
49
75
|
| Task type | Iterations |
|
|
@@ -96,6 +122,38 @@ After [N] retries on any single item:
|
|
|
96
122
|
Output <promise>[PROMISE]</promise>" --max-iterations [N] --completion-promise "[PROMISE]"
|
|
97
123
|
```
|
|
98
124
|
|
|
125
|
+
### With Subagents
|
|
126
|
+
|
|
127
|
+
When the orchestrator score is >= 3, embed subagent instructions in the prompt:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
/ralph-loop:ralph-loop "## Goal
|
|
131
|
+
[Task summary]
|
|
132
|
+
|
|
133
|
+
## Phase 1 — Parallel Exploration
|
|
134
|
+
Spawn these subagents simultaneously using the Agent tool:
|
|
135
|
+
|
|
136
|
+
1. Agent 'scan-frontend' (subagent_type: Explore, run_in_background: true):
|
|
137
|
+
Search src/frontend/** for [pattern]. Write findings to .ralph/reports/frontend.md
|
|
138
|
+
|
|
139
|
+
2. Agent 'scan-backend' (subagent_type: Explore, run_in_background: true):
|
|
140
|
+
Search src/backend/** for [pattern]. Write findings to .ralph/reports/backend.md
|
|
141
|
+
|
|
142
|
+
After ALL agents complete, merge reports into .ralph/reports/merged.md
|
|
143
|
+
|
|
144
|
+
## Phase 2 — Sequential Implementation
|
|
145
|
+
Read .ralph/reports/merged.md, then for each item:
|
|
146
|
+
1. Apply the fix
|
|
147
|
+
2. Run [verification command]
|
|
148
|
+
3. git commit
|
|
149
|
+
|
|
150
|
+
## Completion Criteria
|
|
151
|
+
- All items from merged.md addressed
|
|
152
|
+
- [Verification command] passes
|
|
153
|
+
|
|
154
|
+
Output <promise>[PROMISE]</promise>" --max-iterations [N] --completion-promise "[PROMISE]"
|
|
155
|
+
```
|
|
156
|
+
|
|
99
157
|
### Multi-Phase
|
|
100
158
|
|
|
101
159
|
Generate each Phase as a separate `/ralph-loop:ralph-loop` command:
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ralph-orchestrator
|
|
3
|
+
description: "Orchestration patterns for ralph-loop: subagent spawning, parallel exploration, and task decomposition strategies"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Ralph Orchestrator — Multi-Agent Loop Patterns
|
|
7
|
+
|
|
8
|
+
You are an expert at designing optimal execution strategies for Ralph Loop tasks.
|
|
9
|
+
When asked to orchestrate a task, analyze its structure and recommend the best combination of sequential loops, parallel subagents, and phased execution.
|
|
10
|
+
|
|
11
|
+
## Core Concept
|
|
12
|
+
|
|
13
|
+
Not every task should run in a single linear loop. Complex tasks benefit from:
|
|
14
|
+
|
|
15
|
+
- **Parallel exploration** — spawn subagents to search/analyze independently, then merge results
|
|
16
|
+
- **Divide and conquer** — split work by service/directory/concern with isolated agents
|
|
17
|
+
- **Pipeline stages** — sequential phases where each feeds into the next
|
|
18
|
+
- **Hybrid patterns** — combine parallel research with sequential implementation
|
|
19
|
+
|
|
20
|
+
## When to Use Subagents
|
|
21
|
+
|
|
22
|
+
### Use Subagents (Parallel) When:
|
|
23
|
+
|
|
24
|
+
| Signal | Example |
|
|
25
|
+
| --------------------------- | ---------------------------------------------------------- |
|
|
26
|
+
| **Broad codebase search** | "Find all API endpoints that lack auth checks" |
|
|
27
|
+
| **Independent file groups** | Frontend components + backend routes + database migrations |
|
|
28
|
+
| **Multi-service changes** | auth-service + api-gateway + frontend simultaneously |
|
|
29
|
+
| **Audit/review tasks** | Security audit + performance audit + accessibility audit |
|
|
30
|
+
| **Pattern extraction** | Scan 50+ files for inconsistent patterns |
|
|
31
|
+
|
|
32
|
+
### Do NOT Use Subagents When:
|
|
33
|
+
|
|
34
|
+
| Signal | Reason |
|
|
35
|
+
| --------------------------- | ---------------------------------------------------- |
|
|
36
|
+
| **Sequential dependencies** | Step 2 needs Step 1's output |
|
|
37
|
+
| **Shared mutable state** | Multiple agents editing the same file = conflicts |
|
|
38
|
+
| **Small scope (< 5 files)** | Overhead outweighs benefit |
|
|
39
|
+
| **Context-heavy tasks** | Agent needs deep understanding of full codebase flow |
|
|
40
|
+
|
|
41
|
+
## Orchestration Patterns
|
|
42
|
+
|
|
43
|
+
### Pattern 1: Parallel Explore → Sequential Implement
|
|
44
|
+
|
|
45
|
+
Best for: Large codebases where you need to understand before you change.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
Phase 1 (Parallel Subagents):
|
|
49
|
+
├── Agent A: Scan src/frontend/** for pattern X → report-frontend.md
|
|
50
|
+
├── Agent B: Scan src/backend/** for pattern X → report-backend.md
|
|
51
|
+
└── Agent C: Scan src/shared/** for pattern X → report-shared.md
|
|
52
|
+
|
|
53
|
+
Phase 2 (Sequential Loop):
|
|
54
|
+
└── Ralph Loop: Read all reports → implement fixes in priority order
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Prompt pattern for Phase 1:**
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
## Subagent Tasks (run in parallel)
|
|
61
|
+
Use the Agent tool to spawn these subagents simultaneously:
|
|
62
|
+
|
|
63
|
+
1. Agent "frontend-scan": Search src/frontend/** for [pattern].
|
|
64
|
+
Write findings to .ralph/reports/frontend-scan.md
|
|
65
|
+
2. Agent "backend-scan": Search src/backend/** for [pattern].
|
|
66
|
+
Write findings to .ralph/reports/backend-scan.md
|
|
67
|
+
3. Agent "shared-scan": Search src/shared/** for [pattern].
|
|
68
|
+
Write findings to .ralph/reports/shared-scan.md
|
|
69
|
+
|
|
70
|
+
After ALL agents complete, merge reports into .ralph/reports/merged.md
|
|
71
|
+
with a unified priority list.
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Pattern 2: Divide by Ownership
|
|
75
|
+
|
|
76
|
+
Best for: Multi-service changes where files don't overlap.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
Phase 1 (Parallel Implementation):
|
|
80
|
+
├── Agent "fe-dev": Modify src/frontend/** only → commit per item
|
|
81
|
+
├── Agent "be-dev": Modify src/backend/** only → commit per item
|
|
82
|
+
└── Agent "auth-dev": Modify src/auth/** only → commit per item
|
|
83
|
+
|
|
84
|
+
Phase 2 (Integration Verification):
|
|
85
|
+
└── Ralph Loop: Run full test suite, fix any integration issues
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Prompt pattern:**
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
## Parallel Work Streams
|
|
92
|
+
Spawn these agents with strict file ownership:
|
|
93
|
+
|
|
94
|
+
1. Agent "fe-dev" (isolation: worktree):
|
|
95
|
+
- ONLY touch files in src/frontend/**
|
|
96
|
+
- Tasks: [frontend items]
|
|
97
|
+
- Commit each fix individually
|
|
98
|
+
|
|
99
|
+
2. Agent "be-dev" (isolation: worktree):
|
|
100
|
+
- ONLY touch files in src/backend/**
|
|
101
|
+
- Tasks: [backend items]
|
|
102
|
+
- Commit each fix individually
|
|
103
|
+
|
|
104
|
+
After all agents complete, merge their branches and run integration tests.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Pattern 3: Fan-Out / Fan-In Research
|
|
108
|
+
|
|
109
|
+
Best for: Tasks that need comprehensive analysis before any action.
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
Fan-Out (Parallel):
|
|
113
|
+
├── Agent 1: Analyze problem from angle A → findings-a.md
|
|
114
|
+
├── Agent 2: Analyze problem from angle B → findings-b.md
|
|
115
|
+
└── Agent 3: Analyze problem from angle C → findings-c.md
|
|
116
|
+
|
|
117
|
+
Fan-In (Sequential):
|
|
118
|
+
└── Ralph Loop: Synthesize all findings → create action plan → implement
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Pattern 4: Pipeline with Checkpoints
|
|
122
|
+
|
|
123
|
+
Best for: Complex multi-stage transformations.
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Stage 1 (Ralph Loop): Parse + validate input → intermediate.json
|
|
127
|
+
↓ checkpoint: verify intermediate.json schema
|
|
128
|
+
Stage 2 (Ralph Loop): Transform data → output draft
|
|
129
|
+
↓ checkpoint: run regression tests
|
|
130
|
+
Stage 3 (Parallel Agents): Apply fixes to multiple output files
|
|
131
|
+
↓ checkpoint: final integration test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Pattern 5: Scout-Then-Execute
|
|
135
|
+
|
|
136
|
+
Best for: Unfamiliar codebases or risky changes.
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
Scout Phase (Single Agent, read-only):
|
|
140
|
+
└── Agent "scout": Explore codebase, map dependencies, identify risks
|
|
141
|
+
→ .ralph/reports/scout-report.md
|
|
142
|
+
|
|
143
|
+
Execute Phase (Ralph Loop):
|
|
144
|
+
└── Ralph Loop: Use scout report as reference, implement changes
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Subagent Configuration Reference
|
|
148
|
+
|
|
149
|
+
### Claude Code (Agent tool)
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
Agent tool parameters:
|
|
153
|
+
- description: "short task description"
|
|
154
|
+
- prompt: "detailed instructions"
|
|
155
|
+
- subagent_type: "general-purpose" | "Explore" | "Plan" | "coder-fe" | "coder-be" | etc.
|
|
156
|
+
- isolation: "worktree" (optional — gives agent an isolated repo copy)
|
|
157
|
+
- run_in_background: true (for parallel execution)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Codex CLI (experimental)
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
# Enable multi-agent via config
|
|
164
|
+
[experimental]
|
|
165
|
+
multi_agent = true
|
|
166
|
+
|
|
167
|
+
# In prompt, instruct Codex to use its built-in agent spawning:
|
|
168
|
+
"Spawn a subagent to explore src/api/** for unused endpoints.
|
|
169
|
+
Write results to .ralph/reports/api-scan.md"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Report Directory Convention
|
|
173
|
+
|
|
174
|
+
All subagent outputs should follow this structure:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
.ralph/
|
|
178
|
+
└── reports/
|
|
179
|
+
├── {agent-name}.md # Individual agent output
|
|
180
|
+
├── merged.md # Combined findings (created by orchestrator)
|
|
181
|
+
└── plan.md # Action plan derived from findings
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
This directory should be in `.gitignore` — reports are ephemeral working artifacts.
|
|
185
|
+
|
|
186
|
+
## Decision Matrix
|
|
187
|
+
|
|
188
|
+
When analyzing a task, use this scoring to decide the orchestration pattern:
|
|
189
|
+
|
|
190
|
+
| Factor | Score | Pattern |
|
|
191
|
+
| ------------------------------ | ----- | ------------------- |
|
|
192
|
+
| Files span 3+ directories | +2 | Parallel |
|
|
193
|
+
| Items are independent | +2 | Parallel |
|
|
194
|
+
| Need full context to decide | -2 | Sequential |
|
|
195
|
+
| Order matters | -2 | Sequential |
|
|
196
|
+
| 10+ similar items | +1 | Parallel |
|
|
197
|
+
| Needs cross-file understanding | -1 | Sequential |
|
|
198
|
+
| Multiple services/repos | +3 | Divide by Ownership |
|
|
199
|
+
|
|
200
|
+
- **Score >= 3**: Recommend parallel subagents
|
|
201
|
+
- **Score 0–2**: Recommend sequential with optional scout phase
|
|
202
|
+
- **Score < 0**: Recommend single sequential Ralph Loop
|
|
203
|
+
|
|
204
|
+
## Integration with Ralph Interview
|
|
205
|
+
|
|
206
|
+
When `/ralph-interview` invokes this skill, provide:
|
|
207
|
+
|
|
208
|
+
1. **Recommended pattern** — which orchestration pattern fits best
|
|
209
|
+
2. **Agent breakdown** — list of subagents with their roles and file boundaries
|
|
210
|
+
3. **Phase structure** — how phases connect and what checkpoints exist
|
|
211
|
+
4. **Prompt snippets** — ready-to-embed subagent instructions for the ralph-loop prompt
|