@graypark/ralph-codex 0.7.1 → 0.8.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/README.md CHANGED
@@ -1,15 +1,80 @@
1
- # ralph-codex
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/vcz-Gray/ralph-codex/main/assets/ralph-codex-banner.svg" alt="ralph-codex" width="600" />
3
+ </p>
2
4
 
3
- Self-referential iterative development loops for **Codex CLI** and **Claude Code** — with multi-agent orchestration, interactive command generation, and cross-platform stop hooks.
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@graypark/ralph-codex"><img src="https://img.shields.io/npm/v/@graypark/ralph-codex.svg?style=flat-square&color=blue" alt="npm version" /></a>
7
+ <a href="https://www.npmjs.com/package/@graypark/ralph-codex"><img src="https://img.shields.io/npm/dm/@graypark/ralph-codex.svg?style=flat-square&color=green" alt="npm downloads" /></a>
8
+ <a href="https://github.com/vcz-Gray/ralph-codex/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="license" /></a>
9
+ <img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg?style=flat-square" alt="node version" />
10
+ <img src="https://img.shields.io/badge/platform-Codex%20CLI%20%7C%20Claude%20Code-purple.svg?style=flat-square" alt="platform" />
11
+ </p>
12
+
13
+ <p align="center">
14
+ <b>Iterative AI development loops with PRD-driven task tracking, multi-agent orchestration, and interactive command generation.</b>
15
+ </p>
16
+
17
+ ---
4
18
 
5
19
  ## What is Ralph Loop?
6
20
 
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.
21
+ An AI agent works on a task in a continuous loop. Each iteration starts with **fresh context** reading the PRD and progress files to decide what to do next. The agent implements one story, commits, updates progress, and exits. The stop hook intercepts the exit and re-injects the prompt. Repeat until all stories pass.
22
+
23
+ ```
24
+ ┌──────────────────────┐
25
+ │ /ralph-interview │
26
+ │ Describe your task │
27
+ └──────────┬───────────┘
28
+
29
+ ┌──────────▼───────────┐
30
+ │ Generate prd.json │
31
+ │ + progress.txt │
32
+ └──────────┬───────────┘
33
+
34
+ ┌────────────────▼────────────────┐
35
+ │ Ralph Loop │
36
+ │ │
37
+ │ 1. Read prd.json + progress │
38
+ │ 2. Pick next story (passes=false)│
39
+ │ 3. Implement + verify │
40
+ │ 4. Commit + update progress │
41
+ │ 5. Exit attempt │
42
+ │ │ │
43
+ │ Stop Hook intercepts │
44
+ │ Re-injects prompt │
45
+ │ │ │
46
+ │ Back to step 1 ──────────────┘
47
+ │ │
48
+ │ All stories pass? │
49
+ │ → <promise>COMPLETE</promise> │
50
+ └─────────────────────────────────┘
51
+ ```
52
+
53
+ ## Quick Start
54
+
55
+ ```bash
56
+ npx @graypark/ralph-codex --global
57
+ ```
58
+
59
+ Then in your AI coding session:
60
+
61
+ ```
62
+ /ralph-interview Add user authentication with JWT, bcrypt, and login UI
63
+ ```
64
+
65
+ That's it. The interview generates a PRD, activates the loop, and starts implementing story by story.
8
66
 
9
- ## Requirements
67
+ ## Features
10
68
 
11
- - **Node.js** 18+
12
- - **Codex CLI** v0.114+ or **Claude Code** (any version with plugin support)
69
+ | Feature | Description |
70
+ | ----------------------------- | -------------------------------------------------------------------------- |
71
+ | **PRD-driven loops** | `prd.json` + `progress.txt` — resumable, inspectable, git-friendly |
72
+ | **Interactive interview** | `/ralph-interview` asks targeted questions, generates optimized commands |
73
+ | **Multi-agent orchestration** | `/ralph-orchestrator` — 5 patterns for parallel work streams |
74
+ | **One story per iteration** | Focused context, clean commits, no context rot |
75
+ | **Cross-platform** | Node.js stop hook — Windows, macOS, Linux without WSL |
76
+ | **Ecosystem compatible** | Works with `ralph-skills:prd`, `ralph-skills:ralph`, official `ralph-loop` |
77
+ | **Stop & resume** | Stop anytime. Restart the same command — picks up where it left off |
13
78
 
14
79
  ## Installation
15
80
 
@@ -19,7 +84,7 @@ An AI agent works on a task in a continuous loop, seeing its own previous work e
19
84
  npx @graypark/ralph-codex --global
20
85
  ```
21
86
 
22
- ### Git clone
87
+ ### Clone & install
23
88
 
24
89
  ```bash
25
90
  git clone https://github.com/vcz-Gray/ralph-codex.git
@@ -27,19 +92,18 @@ cd ralph-codex
27
92
  node bin/install.mjs --global
28
93
  ```
29
94
 
30
- ### Options
95
+ | Flag | Description |
96
+ | ----------- | --------------------------------------- |
97
+ | `--global` | Install to `~/.codex/` (default) |
98
+ | `--local` | Install to `.codex/` in current project |
99
+ | `--dry-run` | Preview without changes |
100
+ | `--force` | Overwrite existing |
31
101
 
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
-
39
- ### What Gets Installed
102
+ <details>
103
+ <summary>What gets installed</summary>
40
104
 
41
105
  ```
42
- ~/.codex/ (or ~/.claude/)
106
+ ~/.codex/
43
107
  ├── plugins/ralph-codex/ # Core plugin files
44
108
  ├── hooks.json # Stop hook (merged with existing)
45
109
  └── skills/
@@ -49,218 +113,148 @@ node bin/install.mjs --global
49
113
  └── ralph-orchestrator/ # /ralph-orchestrator — multi-agent patterns
50
114
  ```
51
115
 
116
+ </details>
117
+
52
118
  ## Commands
53
119
 
54
- ### `/ralph-interview` — Smart Command Generator
120
+ ### `/ralph-interview` — The Main Entry Point
55
121
 
56
- **The recommended way to start.** Interviews you about your task, evaluates whether subagents would help, then generates an optimized command.
122
+ Interviews you about your task, generates a PRD with right-sized stories, activates the loop, and starts working immediately.
57
123
 
58
124
  ```
59
- /ralph-interview
125
+ /ralph-interview Refactor auth module across frontend and backend
60
126
  ```
61
127
 
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
65
-
66
- **Auto-execute:** Add "run immediately" or "바로 실행" to start without confirmation:
128
+ **What happens:**
67
129
 
68
- ```
69
- /ralph-interview Refactor the auth module across 3 services, run immediately
70
- ```
130
+ 1. 3-5 targeted questions (scope, verification, parallelism, etc.)
131
+ 2. Generates `prd.json` with properly sized and ordered stories
132
+ 3. Writes `progress.txt` for iteration tracking
133
+ 4. Activates stop hook and starts implementing US-001
71
134
 
72
- **Multi-phase tasks:** The interview generates `.ralph/prd.md` + `.ralph/progress.md` files. The loop reads these each iteration to track phases and items:
135
+ **Quick-run** skip the "Ready?" prompt:
73
136
 
74
137
  ```
75
- .ralph/
76
- ├── prd.md # All phases and work items
77
- └── progress.md # What's done, what's next, what's blocked
138
+ /ralph-interview Add pagination to users API, run immediately
78
139
  ```
79
140
 
80
- The loop naturally transitions between phases by reading progress. Stop anytime — restart the same command and it picks up where it left off.
81
-
82
141
  ### `/ralph-orchestrator` — Multi-Agent Patterns
83
142
 
84
- Analyzes your task and recommends the best orchestration strategy:
143
+ Recommends the best execution strategy based on your task structure:
85
144
 
86
- | Pattern | Best For |
87
- | ------------------------------------------- | ------------------------------------------------- |
88
- | **Parallel Explore → Sequential Implement** | Large codebase research + targeted fixes |
89
- | **Divide by Ownership** | Multi-service changes (frontend + backend + auth) |
90
- | **Fan-Out / Fan-In** | Comprehensive audits (security + perf + a11y) |
91
- | **Scout-Then-Execute** | Unfamiliar codebases |
92
- | **Pipeline with Checkpoints** | Complex multi-stage transformations |
145
+ | Pattern | When to use |
146
+ | --------------------------------------- | ---------------------------------------- |
147
+ | Parallel Explore → Sequential Implement | Research across large codebase, then fix |
148
+ | Divide by Ownership | Multi-service changes (fe + be + auth) |
149
+ | Fan-Out / Fan-In | Parallel audits (security + perf + a11y) |
150
+ | Scout-Then-Execute | Unfamiliar codebase |
151
+ | Pipeline with Checkpoints | Multi-stage transformations |
93
152
 
94
- **Decision matrix**the orchestrator scores your task automatically:
95
-
96
- ```
97
- Files span 3+ directories → +2
98
- Items are independent → +2
99
- Multiple services/repos → +3
100
- 10+ similar items → +1
101
- Need full context → -2
102
- Order matters → -2
103
-
104
- Score >= 3 → Parallel subagents
105
- Score 0–2 → Sequential + optional scout
106
- Score < 0 → Single loop
107
- ```
153
+ ### `/ralph-loop`Direct Loop
108
154
 
109
- ### `/ralph-loop` Run a Loop Directly
155
+ If you already have a PRD or want to write your own prompt:
110
156
 
111
157
  ```
112
- /ralph-loop "Build a REST API" --max-iterations 30 --completion-promise "ALL_TESTS_PASS"
158
+ /ralph-loop "Read prd.json, pick next story, implement, verify, commit" --max-iterations 20 --completion-promise "COMPLETE"
113
159
  ```
114
160
 
115
- | Parameter | Default | Description |
116
- | --------------------------- | ---------- | ------------------------------ |
117
- | `PROMPT` | (required) | Task description |
118
- | `--max-iterations N` | 20 | Max iterations (0 = unlimited) |
119
- | `--completion-promise TEXT` | "TADA" | Phrase that signals completion |
120
-
121
- ### `/cancel-ralph` — Stop the Loop
161
+ ### `/cancel-ralph` Stop
122
162
 
123
163
  ```
124
164
  /cancel-ralph
125
165
  ```
126
166
 
127
- ## How the Loop Works
128
-
129
- ```
130
- ┌─────────────────────────────────────────────┐
131
- │ /ralph-loop "Build feature X" │
132
- │ │
133
- ┌──────────┐ ┌──────────┐ │
134
- │ Agent │───▶│ Works │ │
135
- │ starts │ │ on task │ │
136
- └──────────┘ └────┬─────┘ │
137
- │ │ │
138
- │ ▼ │
139
- │ ┌──────────────┐ │
140
- │ │ Tries to exit │ │
141
- │ └───────┬──────┘ │
142
- │ │ │
143
- │ ▼ │
144
- │ ┌───────────────────┐ │
145
- │ │ Stop Hook │ │
146
- │ │ ┌───────────────┐ │ │
147
- │ │ │ Max reached? │─┼──Yes──▶ EXIT
148
- │ │ │ Promise found?│─┼──Yes──▶ EXIT
149
- │ │ └───────┬───────┘ │ │
150
- │ │ No │ │
151
- │ │ Block exit + │ │
152
- │ │ re-inject prompt │ │
153
- │ └─────────┬─────────┘ │
154
- │ │ │
155
- │ ┌──────────────┐ │
156
- │ │ Sees previous │──── loop ────┘
157
- │ │ work in files │
158
- │ └──────────────┘
167
+ ## PRD Format
168
+
169
+ ralph-codex uses the **ralph-skills compatible** `prd.json` format:
170
+
171
+ ```json
172
+ {
173
+ "project": "MyApp",
174
+ "branchName": "ralph/auth-system",
175
+ "description": "JWT authentication with login UI",
176
+ "userStories": [
177
+ {
178
+ "id": "US-001",
179
+ "title": "Add users table with password hash",
180
+ "description": "As a developer, I need user storage for auth",
181
+ "acceptanceCriteria": [
182
+ "Users table with email, password_hash columns",
183
+ "Migration runs successfully",
184
+ "Typecheck passes"
185
+ ],
186
+ "priority": 1,
187
+ "passes": false,
188
+ "notes": ""
189
+ }
190
+ ]
191
+ }
159
192
  ```
160
193
 
161
- ## Multi-Agent Orchestration Example
194
+ Each story is sized to complete in **one iteration** (one context window). Dependencies are ordered by priority.
162
195
 
163
- For a task like "audit and fix auth across frontend, backend, and auth-service":
196
+ ## Ecosystem Compatibility
164
197
 
165
- ```
166
- Phase 1 — Parallel Exploration (3 subagents):
167
- ├── Agent "fe-scan": Search frontend for auth issues → report
168
- ├── Agent "be-scan": Search backend for auth issues → report
169
- └── Agent "auth-scan": Search auth-service for issues report
198
+ ralph-codex works seamlessly with existing Ralph tools:
199
+
200
+ | Tool | Compatibility |
201
+ | ---------------------------- | -------------------------------------------------------------------- |
202
+ | `ralph-skills:prd` | Same `prd.json` format generate PRD there, loop here |
203
+ | `ralph-skills:ralph` | Same `progress.txt`, same `passes` tracking, same `COMPLETE` promise |
204
+ | Official `ralph-loop` plugin | PRD files work with either stop hook |
205
+ | `snarktank/ralph` | Compatible PRD structure and iteration pattern |
206
+
207
+ ## Multi-Agent Orchestration
170
208
 
171
- Phase 2 Merge & Plan:
172
- └── Ralph Loop: Read all reports → create prioritized fix plan
209
+ For tasks spanning multiple services or requiring broad exploration:
173
210
 
174
- Phase 3 — Parallel Implementation:
175
- ├── Agent "fe-dev" (worktree): Fix frontend items
176
- ├── Agent "be-dev" (worktree): Fix backend items
177
- └── Agent "auth-dev" (worktree): Fix auth-service items
211
+ ```
212
+ Phase 1 Parallel Scan (3 agents):
213
+ ├── Agent "fe-scan": Search frontend/** for auth gaps
214
+ ├── Agent "be-scan": Search backend/** for auth gaps
215
+ └── Agent "db-scan": Review schema for missing constraints
178
216
 
179
- Phase 4Integration:
180
- └── Ralph Loop: Merge branches run full test suite → fix conflicts
217
+ Phase 2Sequential Fix (ralph-loop):
218
+ └── Read merged findingsimplement fixes story by story
181
219
  ```
182
220
 
183
- The `/ralph-interview` skill generates this automatically when it detects multi-service scope.
221
+ The interview automatically evaluates parallelism potential using a scoring matrix.
184
222
 
185
223
  ## Updating
186
224
 
187
- To update to the latest version:
188
-
189
225
  ```bash
190
226
  npx @graypark/ralph-codex --global --force
191
227
  ```
192
228
 
193
- Or if installed via git:
194
-
195
- ```bash
196
- cd ralph-codex
197
- git pull
198
- node bin/install.mjs --global --force
199
- ```
200
-
201
- ## Windows Support
202
-
203
- Works natively on Windows without WSL or Git Bash:
204
-
205
- - All paths use `path.join()` (no hardcoded slashes)
206
- - Installer copies files instead of symlinks on Windows
207
- - State files use JSON (no Unix-specific formats)
208
- - Hooks use `node` as the interpreter (cross-platform)
209
-
210
- ## Uninstall
229
+ ## Uninstalling
211
230
 
212
231
  ```bash
213
232
  npx @graypark/ralph-codex uninstall
214
233
  ```
215
234
 
216
- ## Claude Code Plugin
217
-
218
- This package includes a `.claude-plugin/plugin.json` manifest for Claude Code marketplace compatibility. To use as a Claude Code plugin:
219
-
220
- 1. Clone the repo to your machine
221
- 2. In Claude Code, reference the plugin directory
222
- 3. Skills (`ralph-interview`, `ralph-orchestrator`, etc.) will be auto-discovered
223
-
224
235
  ## Architecture
225
236
 
226
237
  ```
227
238
  ralph-codex/
228
- ├── .claude-plugin/
229
- │ └── plugin.json # Claude Code marketplace manifest
239
+ ├── .claude-plugin/plugin.json # Claude Code marketplace manifest
230
240
  ├── bin/
231
- │ ├── install.mjs # Cross-platform installer
232
- │ └── uninstall.mjs # Clean uninstaller
241
+ │ ├── install.mjs # Cross-platform installer
242
+ │ └── uninstall.mjs # Clean uninstaller
233
243
  ├── hooks/
234
- ├── hooks.json # Hook registration (reference)
235
- │ └── stop-hook.mjs # Stop hook — core loop engine
244
+ └── stop-hook.mjs # Core loop engine (Node.js)
236
245
  ├── commands/
237
- │ ├── ralph-loop.md # /ralph-loop command
238
- │ └── cancel-ralph.md # /cancel-ralph command
246
+ │ ├── ralph-loop.md # /ralph-loop command
247
+ │ └── cancel-ralph.md # /cancel-ralph command
239
248
  ├── skills/
240
- │ ├── ralph-interview/
241
- └── SKILL.md # Interactive command generator
242
- │ └── ralph-orchestrator/
243
- │ └── SKILL.md # Multi-agent orchestration patterns
249
+ │ ├── ralph-interview/SKILL.md # Interactive command generator
250
+ │ └── ralph-orchestrator/SKILL.md # Multi-agent patterns
244
251
  ├── lib/
245
- │ ├── paths.mjs # Cross-platform path utilities
246
- │ ├── state.mjs # Loop state management
247
- │ └── stop-hook-core.mjs # Testable stop hook logic
248
- ├── tests/ # 32 test cases (vitest)
249
- └── package.json
252
+ │ ├── paths.mjs # Cross-platform paths
253
+ │ ├── state.mjs # Loop state management
254
+ │ └── stop-hook-core.mjs # Testable hook logic
255
+ └── tests/ # 32 test cases (vitest)
250
256
  ```
251
257
 
252
- ## Comparison
253
-
254
- | Feature | Claude Code (official) | Codex CLI (builtin) | ralph-codex (this) |
255
- | ---------------------- | ---------------------- | ------------------- | ------------------------ |
256
- | Runtime | Bash (sh/perl) | Rust | Node.js (cross-platform) |
257
- | Windows | WSL required | Experimental | Native |
258
- | Hook protocol | JSON | JSON | Same |
259
- | Command generator | None | None | `/ralph-interview` |
260
- | Multi-agent | Manual | Experimental | `/ralph-orchestrator` |
261
- | Orchestration patterns | None | None | 5 built-in patterns |
262
- | Plugin format | `.claude-plugin` | `.codex/skills` | Both |
263
-
264
258
  ## Development
265
259
 
266
260
  ```bash
@@ -272,3 +266,9 @@ npx vitest # watch mode
272
266
  ## License
273
267
 
274
268
  MIT
269
+
270
+ ---
271
+
272
+ <p align="center">
273
+ Built for <a href="https://github.com/openai/codex">Codex CLI</a> and <a href="https://docs.anthropic.com/en/docs/claude-code">Claude Code</a>
274
+ </p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graypark/ralph-codex",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
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",
@@ -181,6 +181,7 @@ The `## Codebase Patterns` section at the top is read first by each iteration to
181
181
  - **No oversized stories**: Each story must be completable in ONE iteration. Split if too big.
182
182
  - **Always use prd.json format**: Ensures compatibility with ralph-skills ecosystem.
183
183
  - **Default promise is COMPLETE**: Use `<promise>COMPLETE</promise>` to match ralph-skills convention.
184
+ - **Always overwrite**: Never ask before overwriting prd.json or progress.txt. Just write them.
184
185
 
185
186
  ## Conversation Flow
186
187
 
@@ -202,6 +203,8 @@ Skip the "Ready?" prompt. Go straight to activation after showing the PRD briefl
202
203
 
203
204
  When the user confirms (or quick-run), execute ALL of these steps in a SINGLE response. Do NOT stop between steps.
204
205
 
206
+ IMPORTANT: Always overwrite existing prd.json and progress.txt without asking. Do NOT check if they exist. Do NOT ask the user for confirmation before overwriting. Do NOT archive old files. Just write them.
207
+
205
208
  ### Step 1: Write prd.json via Bash
206
209
 
207
210
  ```bash
@@ -224,30 +227,21 @@ EOF
224
227
  Write the ralph-loop state file that makes the stop hook intercept session exits:
225
228
 
226
229
  ```bash
227
- mkdir -p .claude
228
- cat > .claude/ralph-loop.local.md << 'EOF'
229
- ---
230
- active: true
231
- iteration: 1
232
- session_id:
233
- max_iterations: <N>
234
- completion_promise: "COMPLETE"
235
- started_at: "<now>"
236
- ---
237
-
238
- Read prd.json for task plan. Read progress.txt for status (Codebase Patterns first).
239
- Check correct branch from branchName. If not on it, create from main.
240
- Pick highest priority story where passes is false.
241
- Implement that ONE story.
242
- Run verification: <command>.
243
- On failure: fix and retry, max 3 times.
244
- On success: commit 'feat: [Story ID] - [Title]'.
245
- Update prd.json: set passes to true. Append to progress.txt with learnings.
246
- If ALL stories pass: <promise>COMPLETE</promise>.
247
- When stuck: set notes in prd.json, skip to next story.
230
+ mkdir -p .codex
231
+ cat > .codex/ralph-loop.state.json << 'EOF'
232
+ {
233
+ "active": true,
234
+ "prompt": "Read prd.json for task plan. Read progress.txt for status (Codebase Patterns first). Check correct branch from branchName. If not on it, create from main. Pick highest priority story where passes is false. Implement that ONE story. Run verification: <VERIFY_CMD>. On failure: fix and retry, max 3 times. On success: commit with feat: [Story ID] - [Title]. Update prd.json: set passes to true. Append to progress.txt with learnings. If ALL stories pass: output <promise>COMPLETE</promise>. When stuck: set notes in prd.json, skip to next story.",
235
+ "completionPromise": "COMPLETE",
236
+ "maxIterations": <N>,
237
+ "currentIteration": 0,
238
+ "sessionId": ""
239
+ }
248
240
  EOF
249
241
  ```
250
242
 
243
+ Replace `<VERIFY_CMD>` with the actual verification command and `<N>` with the recommended max iterations.
244
+
251
245
  ### Step 4: START WORKING ON US-001 IMMEDIATELY
252
246
 
253
247
  This is the critical step. After writing files, you MUST begin actual work in the SAME response: