@graypark/ralph-codex 0.3.0 → 0.4.1
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 +9 -0
- package/README.md +120 -116
- 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 +273 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ralph-codex",
|
|
3
|
+
"description": "Cross-platform Ralph Loop with interactive interview, multi-agent orchestration, and smart command generation for iterative AI development.",
|
|
4
|
+
"version": "0.4.1",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "graypark",
|
|
7
|
+
"email": "vcz.graypark@gmail.com"
|
|
8
|
+
}
|
|
9
|
+
}
|
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,76 +29,84 @@ 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
|
|
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 |
|
|
36
38
|
|
|
37
39
|
### What Gets Installed
|
|
38
40
|
|
|
39
41
|
```
|
|
40
|
-
~/.codex/
|
|
41
|
-
├── plugins/ralph-codex/
|
|
42
|
-
├── hooks.json
|
|
42
|
+
~/.codex/ (or ~/.claude/)
|
|
43
|
+
├── plugins/ralph-codex/ # Core plugin files
|
|
44
|
+
├── hooks.json # Stop hook (merged with existing)
|
|
43
45
|
└── skills/
|
|
44
|
-
├── ralph-loop/
|
|
45
|
-
├── cancel-ralph/
|
|
46
|
-
|
|
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
|
|
47
50
|
```
|
|
48
51
|
|
|
49
52
|
## Commands
|
|
50
53
|
|
|
51
|
-
### `/ralph-interview` —
|
|
54
|
+
### `/ralph-interview` — Smart Command Generator
|
|
52
55
|
|
|
53
|
-
**The
|
|
56
|
+
**The recommended way to start.** Interviews you about your task, evaluates whether subagents would help, then generates an optimized command.
|
|
54
57
|
|
|
55
58
|
```
|
|
56
59
|
/ralph-interview
|
|
57
60
|
```
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
2. The interview asks 3–5 targeted questions (scope, success criteria, verification commands, etc.)
|
|
63
|
-
3. It generates a copy-paste-ready `/ralph-loop` command with:
|
|
64
|
-
- Proper phase separation (analysis vs. implementation)
|
|
65
|
-
- Self-correcting work cycles (modify → verify → retry)
|
|
66
|
-
- Escape hatches for when you're stuck
|
|
67
|
-
- Objective completion criteria
|
|
68
|
-
- Atomic git commits per work item
|
|
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
|
|
69
65
|
|
|
70
|
-
**Auto-execute
|
|
66
|
+
**Auto-execute:** Add "run immediately" or "바로 실행" to start without confirmation:
|
|
71
67
|
|
|
72
68
|
```
|
|
73
|
-
/ralph-interview
|
|
69
|
+
/ralph-interview Refactor the auth module across 3 services, run immediately
|
|
74
70
|
```
|
|
75
71
|
|
|
76
|
-
|
|
72
|
+
### `/ralph-orchestrator` — Multi-Agent Patterns
|
|
73
|
+
|
|
74
|
+
Analyzes your task and recommends the best orchestration strategy:
|
|
75
|
+
|
|
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 |
|
|
83
|
+
|
|
84
|
+
**Decision matrix** — the orchestrator scores your task automatically:
|
|
77
85
|
|
|
78
86
|
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
83
97
|
```
|
|
84
98
|
|
|
85
99
|
### `/ralph-loop` — Run a Loop Directly
|
|
86
100
|
|
|
87
|
-
If you already know how to write a good prompt:
|
|
88
|
-
|
|
89
101
|
```
|
|
90
|
-
/ralph-loop "Build a REST API
|
|
102
|
+
/ralph-loop "Build a REST API" --max-iterations 30 --completion-promise "ALL_TESTS_PASS"
|
|
91
103
|
```
|
|
92
104
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
| `
|
|
98
|
-
| `--max-iterations N` | 20 | Maximum loop iterations (0 = unlimited) |
|
|
99
|
-
| `--completion-promise TEXT` | "TADA" | Phrase that signals task completion |
|
|
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 |
|
|
100
110
|
|
|
101
111
|
### `/cancel-ralph` — Stop the Loop
|
|
102
112
|
|
|
@@ -111,7 +121,7 @@ If you already know how to write a good prompt:
|
|
|
111
121
|
│ /ralph-loop "Build feature X" │
|
|
112
122
|
│ │
|
|
113
123
|
│ ┌──────────┐ ┌──────────┐ │
|
|
114
|
-
│ │
|
|
124
|
+
│ │ Agent │───▶│ Works │ │
|
|
115
125
|
│ │ starts │ │ on task │ │
|
|
116
126
|
│ └──────────┘ └────┬─────┘ │
|
|
117
127
|
│ │ │
|
|
@@ -128,131 +138,125 @@ If you already know how to write a good prompt:
|
|
|
128
138
|
│ │ │ Promise found?│─┼──Yes──▶ EXIT
|
|
129
139
|
│ │ └───────┬───────┘ │ │
|
|
130
140
|
│ │ No │ │
|
|
131
|
-
│ │ │ │ │
|
|
132
141
|
│ │ Block exit + │ │
|
|
133
142
|
│ │ re-inject prompt │ │
|
|
134
143
|
│ └─────────┬─────────┘ │
|
|
135
144
|
│ │ │
|
|
136
|
-
│ ▼ │
|
|
137
145
|
│ ┌──────────────┐ │
|
|
138
|
-
│ │
|
|
139
|
-
│ │
|
|
146
|
+
│ │ Sees previous │──── loop ────┘
|
|
147
|
+
│ │ work in files │
|
|
140
148
|
│ └──────────────┘
|
|
141
149
|
```
|
|
142
150
|
|
|
143
|
-
|
|
151
|
+
## Multi-Agent Orchestration Example
|
|
144
152
|
|
|
145
|
-
|
|
153
|
+
For a task like "audit and fix auth across frontend, backend, and auth-service":
|
|
146
154
|
|
|
147
155
|
```
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
150
160
|
|
|
151
|
-
|
|
161
|
+
Phase 2 — Merge & Plan:
|
|
162
|
+
└── Ralph Loop: Read all reports → create prioritized fix plan
|
|
152
163
|
|
|
153
|
-
|
|
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
|
|
154
168
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
### 1. Split into Phases
|
|
158
|
-
|
|
159
|
-
```
|
|
160
|
-
/ralph-loop "Phase 1: Set up project scaffold.
|
|
161
|
-
Phase 2: Implement core logic.
|
|
162
|
-
Phase 3: Add tests.
|
|
163
|
-
Output <promise>DONE</promise> when all phases complete." --max-iterations 30
|
|
169
|
+
Phase 4 — Integration:
|
|
170
|
+
└── Ralph Loop: Merge branches → run full test suite → fix conflicts
|
|
164
171
|
```
|
|
165
172
|
|
|
166
|
-
|
|
173
|
+
The `/ralph-interview` skill generates this automatically when it detects multi-service scope.
|
|
167
174
|
|
|
168
|
-
|
|
169
|
-
/ralph-loop "Implement the auth module.
|
|
170
|
-
Done when: all tests pass, no TypeScript errors, coverage > 80%." --completion-promise "AUTH_COMPLETE" --max-iterations 25
|
|
171
|
-
```
|
|
175
|
+
## Updating
|
|
172
176
|
|
|
173
|
-
|
|
177
|
+
To update to the latest version:
|
|
174
178
|
|
|
175
|
-
|
|
179
|
+
```bash
|
|
180
|
+
npx @graypark/ralph-codex --global --force
|
|
181
|
+
```
|
|
176
182
|
|
|
177
|
-
|
|
183
|
+
Or if installed via git:
|
|
178
184
|
|
|
179
|
-
```
|
|
180
|
-
|
|
185
|
+
```bash
|
|
186
|
+
cd ralph-codex
|
|
187
|
+
git pull
|
|
188
|
+
node bin/install.mjs --global --force
|
|
181
189
|
```
|
|
182
190
|
|
|
183
191
|
## Windows Support
|
|
184
192
|
|
|
185
|
-
|
|
193
|
+
Works natively on Windows without WSL or Git Bash:
|
|
186
194
|
|
|
187
195
|
- All paths use `path.join()` (no hardcoded slashes)
|
|
188
|
-
-
|
|
196
|
+
- Installer copies files instead of symlinks on Windows
|
|
189
197
|
- State files use JSON (no Unix-specific formats)
|
|
190
198
|
- Hooks use `node` as the interpreter (cross-platform)
|
|
191
199
|
|
|
192
|
-
Tested on: Windows 10/11, macOS, Linux (Ubuntu/Debian).
|
|
193
|
-
|
|
194
200
|
## Uninstall
|
|
195
201
|
|
|
196
202
|
```bash
|
|
197
203
|
npx @graypark/ralph-codex uninstall
|
|
198
|
-
# or
|
|
199
|
-
node bin/uninstall.mjs --global
|
|
200
204
|
```
|
|
201
205
|
|
|
202
|
-
|
|
206
|
+
## Claude Code Plugin
|
|
207
|
+
|
|
208
|
+
This package includes a `.claude-plugin/plugin.json` manifest for Claude Code marketplace compatibility. To use as a Claude Code plugin:
|
|
203
209
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
- Any active state file
|
|
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
|
|
208
213
|
|
|
209
214
|
## Architecture
|
|
210
215
|
|
|
211
216
|
```
|
|
212
217
|
ralph-codex/
|
|
218
|
+
├── .claude-plugin/
|
|
219
|
+
│ └── plugin.json # Claude Code marketplace manifest
|
|
213
220
|
├── bin/
|
|
214
|
-
│ ├── install.mjs
|
|
215
|
-
│ └── uninstall.mjs
|
|
221
|
+
│ ├── install.mjs # Cross-platform installer
|
|
222
|
+
│ └── uninstall.mjs # Clean uninstaller
|
|
216
223
|
├── hooks/
|
|
217
|
-
│ ├── hooks.json
|
|
218
|
-
│ └── stop-hook.mjs
|
|
224
|
+
│ ├── hooks.json # Hook registration (reference)
|
|
225
|
+
│ └── stop-hook.mjs # Stop hook — core loop engine
|
|
219
226
|
├── commands/
|
|
220
|
-
│ ├── ralph-loop.md
|
|
221
|
-
│ └── cancel-ralph.md
|
|
227
|
+
│ ├── ralph-loop.md # /ralph-loop command
|
|
228
|
+
│ └── cancel-ralph.md # /cancel-ralph command
|
|
222
229
|
├── skills/
|
|
223
|
-
│
|
|
224
|
-
│
|
|
230
|
+
│ ├── ralph-interview/
|
|
231
|
+
│ │ └── SKILL.md # Interactive command generator
|
|
232
|
+
│ └── ralph-orchestrator/
|
|
233
|
+
│ └── SKILL.md # Multi-agent orchestration patterns
|
|
225
234
|
├── lib/
|
|
226
|
-
│ ├── paths.mjs
|
|
227
|
-
│ ├── state.mjs
|
|
228
|
-
│ └── stop-hook-core.mjs
|
|
229
|
-
├── tests/
|
|
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)
|
|
230
239
|
└── package.json
|
|
231
240
|
```
|
|
232
241
|
|
|
233
|
-
##
|
|
242
|
+
## Comparison
|
|
234
243
|
|
|
235
|
-
| Feature
|
|
236
|
-
|
|
|
237
|
-
| Runtime
|
|
238
|
-
|
|
|
239
|
-
|
|
|
240
|
-
|
|
|
241
|
-
|
|
|
242
|
-
|
|
|
243
|
-
|
|
|
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 |
|
|
244
253
|
|
|
245
254
|
## Development
|
|
246
255
|
|
|
247
256
|
```bash
|
|
248
|
-
# Install dev dependencies
|
|
249
257
|
npm install
|
|
250
|
-
|
|
251
|
-
#
|
|
252
|
-
npm test
|
|
253
|
-
|
|
254
|
-
# Run tests in watch mode
|
|
255
|
-
npx vitest
|
|
258
|
+
npm test # 32 test cases
|
|
259
|
+
npx vitest # watch mode
|
|
256
260
|
```
|
|
257
261
|
|
|
258
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.1",
|
|
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,273 @@
|
|
|
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
|
+
- model: "sonnet" | "opus" | "haiku" (optional model override)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Best practices:**
|
|
162
|
+
|
|
163
|
+
- Use `subagent_type: "Explore"` for read-only scanning — faster and safer
|
|
164
|
+
- Use `isolation: "worktree"` when agents write to files — prevents merge conflicts
|
|
165
|
+
- Launch parallel agents in a single message with multiple Agent tool calls
|
|
166
|
+
- Use `run_in_background: true` for truly independent work streams
|
|
167
|
+
|
|
168
|
+
### Codex CLI (experimental)
|
|
169
|
+
|
|
170
|
+
Codex spawns subagents via natural language prompts with keywords: "spawn", "parallel", "delegate", "one agent per".
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
# Enable in ~/.codex/config.toml
|
|
174
|
+
[agents]
|
|
175
|
+
max_threads = 6 # Max concurrent agent threads (default: 6)
|
|
176
|
+
max_depth = 1 # No grandchild agents (default: 1)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Custom agent definitions** in `.codex/agents/` (TOML):
|
|
180
|
+
|
|
181
|
+
```toml
|
|
182
|
+
# .codex/agents/scanner.toml
|
|
183
|
+
name = "scanner"
|
|
184
|
+
description = "Read-only codebase explorer for pattern extraction"
|
|
185
|
+
model = "gpt-5.4-mini" # Faster model for exploration
|
|
186
|
+
model_reasoning_effort = "low"
|
|
187
|
+
sandbox_mode = "read-only"
|
|
188
|
+
developer_instructions = """
|
|
189
|
+
Scan files for the requested pattern. Report findings with file paths and line numbers.
|
|
190
|
+
Do NOT modify any files.
|
|
191
|
+
"""
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Spawning in prompts:**
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
"Spawn one agent per service directory to scan for auth issues:
|
|
198
|
+
1. scanner on src/frontend/** → .ralph/reports/frontend.md
|
|
199
|
+
2. scanner on src/backend/** → .ralph/reports/backend.md
|
|
200
|
+
3. scanner on src/auth/** → .ralph/reports/auth.md
|
|
201
|
+
Wait for all, then summarize findings by severity."
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Batch processing** with `spawn_agents_on_csv`:
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
# For 100+ similar items, use CSV-driven batch spawning:
|
|
208
|
+
spawn_agents_on_csv:
|
|
209
|
+
csv_path: .ralph/items.csv
|
|
210
|
+
instruction: "Review {file_path} for {issue_type}. Return JSON via report_agent_job_result"
|
|
211
|
+
output_schema: { file: string, severity: string, fix: string }
|
|
212
|
+
output_csv_path: .ralph/reports/batch-results.csv
|
|
213
|
+
max_concurrency: 6
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Model Selection Guide (Codex)
|
|
217
|
+
|
|
218
|
+
| Role | Recommended Model | Reasoning Effort |
|
|
219
|
+
| ----------------------- | ------------------- | ---------------- |
|
|
220
|
+
| Coordinator / main loop | gpt-5.4 | medium |
|
|
221
|
+
| Explorer / scanner | gpt-5.4-mini | low |
|
|
222
|
+
| Reviewer / security | gpt-5.4 | high |
|
|
223
|
+
| Quick iteration / TDD | gpt-5.3-codex-spark | medium |
|
|
224
|
+
|
|
225
|
+
### Key Constraints
|
|
226
|
+
|
|
227
|
+
| Setting | Default | Note |
|
|
228
|
+
| -------------------- | ------- | ----------------------------------------------------------------------- |
|
|
229
|
+
| `agents.max_threads` | 6 | Hard cap on concurrent agents |
|
|
230
|
+
| `agents.max_depth` | 1 | No recursive agent spawning |
|
|
231
|
+
| File conflicts | N/A | Multiple agents writing same file = conflicts. Use ownership isolation. |
|
|
232
|
+
| Token usage | Higher | Each subagent does own inference. Use faster models for workers. |
|
|
233
|
+
|
|
234
|
+
## Report Directory Convention
|
|
235
|
+
|
|
236
|
+
All subagent outputs should follow this structure:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
.ralph/
|
|
240
|
+
└── reports/
|
|
241
|
+
├── {agent-name}.md # Individual agent output
|
|
242
|
+
├── merged.md # Combined findings (created by orchestrator)
|
|
243
|
+
└── plan.md # Action plan derived from findings
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
This directory should be in `.gitignore` — reports are ephemeral working artifacts.
|
|
247
|
+
|
|
248
|
+
## Decision Matrix
|
|
249
|
+
|
|
250
|
+
When analyzing a task, use this scoring to decide the orchestration pattern:
|
|
251
|
+
|
|
252
|
+
| Factor | Score | Pattern |
|
|
253
|
+
| ------------------------------ | ----- | ------------------- |
|
|
254
|
+
| Files span 3+ directories | +2 | Parallel |
|
|
255
|
+
| Items are independent | +2 | Parallel |
|
|
256
|
+
| Need full context to decide | -2 | Sequential |
|
|
257
|
+
| Order matters | -2 | Sequential |
|
|
258
|
+
| 10+ similar items | +1 | Parallel |
|
|
259
|
+
| Needs cross-file understanding | -1 | Sequential |
|
|
260
|
+
| Multiple services/repos | +3 | Divide by Ownership |
|
|
261
|
+
|
|
262
|
+
- **Score >= 3**: Recommend parallel subagents
|
|
263
|
+
- **Score 0–2**: Recommend sequential with optional scout phase
|
|
264
|
+
- **Score < 0**: Recommend single sequential Ralph Loop
|
|
265
|
+
|
|
266
|
+
## Integration with Ralph Interview
|
|
267
|
+
|
|
268
|
+
When `/ralph-interview` invokes this skill, provide:
|
|
269
|
+
|
|
270
|
+
1. **Recommended pattern** — which orchestration pattern fits best
|
|
271
|
+
2. **Agent breakdown** — list of subagents with their roles and file boundaries
|
|
272
|
+
3. **Phase structure** — how phases connect and what checkpoints exist
|
|
273
|
+
4. **Prompt snippets** — ready-to-embed subagent instructions for the ralph-loop prompt
|