openralph 1.0.12 → 2.0.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.
Files changed (3) hide show
  1. package/README.md +194 -53
  2. package/bin/ralph +27 -9
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -1,22 +1,40 @@
1
- # openralph
1
+ <div align="center">
2
2
 
3
- AI agent loop for autonomous task execution. Reads a PRD, picks one task, completes it, commits, repeats.
3
+ # OpenRalph
4
+
5
+ [![npm version](https://img.shields.io/npm/v/openralph?style=flat-square&color=blue)](https://www.npmjs.com/package/openralph)
6
+ [![npm downloads](https://img.shields.io/npm/dm/openralph?style=flat-square&color=green)](https://www.npmjs.com/package/openralph)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
8
+ [![Bun](https://img.shields.io/badge/Bun-v1.0+-black?style=flat-square&logo=bun)](https://bun.sh)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
10
+
11
+ **AI agent loop for autonomous task execution.**
12
+
13
+ Reads a PRD, picks one task, completes it, commits, repeats.
14
+
15
+ [Quick Start](#quick-start) •
16
+ [Features](#features) •
17
+ [Usage](#usage) •
18
+ [Config](#configuration) •
19
+ [Docs](#writing-prds)
20
+
21
+ </div>
22
+
23
+ ---
4
24
 
5
25
  <p align="center">
6
- <img src="ralph-task.jpg" alt="Ralph TUI - Task view with PRD items" width="100%" />
26
+ <img src="assets/images/ralph-task.jpg" alt="Ralph TUI - Task view with PRD items" width="100%" />
7
27
  </p>
8
28
 
9
29
  <p align="center">
10
- <img src="ralph-output details.jpg" alt="Ralph TUI - Output view showing agent activity" width="100%" />
30
+ <img src="assets/images/ralph-output details.jpg" alt="Ralph TUI - Output view showing agent activity" width="100%" />
11
31
  </p>
12
32
 
13
33
  <p align="center">
14
- <img src="openralph-terminal.jpg" alt="Ralph with openralph terminal side-by-side" width="100%" />
34
+ <img src="assets/images/openralph-terminal.jpg" alt="Ralph with openralph terminal side-by-side" width="100%" />
15
35
  </p>
16
36
 
17
- ## Acknowledgements
18
-
19
- openralph is a fork of the original `opencode-ralph` project. Huge thanks to Hona for the original work and inspiration: https://github.com/hona/opencode-ralph.
37
+ ---
20
38
 
21
39
  ## Quick Start
22
40
 
@@ -43,6 +61,21 @@ bun install
43
61
  bun run build:single # compiles for current platform
44
62
  ```
45
63
 
64
+ ---
65
+
66
+ ## Features
67
+
68
+ - **Autonomous Task Execution** — AI agent reads your PRD, picks tasks, and completes them one by one
69
+ - **Context-Aware Loop** — Re-reads full context every iteration, eliminating context drift
70
+ - **Beautiful TUI** — Real-time progress dashboard with task tracking and agent activity logs
71
+ - **Multiple Adapters** — Works with OpenCode server, opencode-run, or Codex CLI
72
+ - **Headless Mode** — CI-friendly output with JSON/JSONL/text formats
73
+ - **Session Safety** — Lock files prevent multiple instances; graceful shutdown with state persistence
74
+ - **Smart Resume** — Automatically resumes from where it left off after interruption
75
+ - **PRD Conversion** — Convert markdown plans to structured PRD JSON with `ralph init --from`
76
+
77
+ ---
78
+
46
79
  ## What is Ralph?
47
80
 
48
81
  Ralph-driven development forces an AI agent to re-read full context every iteration, eliminating context drift. Each loop:
@@ -60,7 +93,11 @@ The agent never pushes—only commits—so you maintain review control.
60
93
  - `AGENTS.md` accumulates wisdom so future iterations don't rediscover fire.
61
94
  - Human review checkpoint before anything goes live.
62
95
 
63
- See: [ghuntley.com/ralph](https://ghuntley.com/ralph/) · [lukeparker.dev/stop-chatting-with-ai-start-loops-ralph-driven-development](https://lukeparker.dev/stop-chatting-with-ai-start-loops-ralph-driven-development)
96
+ **Learn more:**
97
+ - [ghuntley.com/ralph](https://ghuntley.com/ralph/)
98
+ - [lukeparker.dev/stop-chatting-with-ai-start-loops-ralph-driven-development](https://lukeparker.dev/stop-chatting-with-ai-start-loops-ralph-driven-development)
99
+
100
+ ---
64
101
 
65
102
  ## Usage
66
103
 
@@ -73,6 +110,8 @@ ralph --reset # remove generated files and state, then exit
73
110
  ralph init --from plan.md # convert unstructured plan to PRD JSON
74
111
  ```
75
112
 
113
+ ### CLI Options
114
+
76
115
  | Option | Default | Description |
77
116
  |--------|---------|-------------|
78
117
  | `--plan, -p` | `prd.json` | PRD file path |
@@ -93,25 +132,66 @@ ralph init --from plan.md # convert unstructured plan to PRD JSON
93
132
  | `--debug, -d` | `false` | Manual session creation |
94
133
  | `--yes` | `false` | Auto-confirm prompts |
95
134
  | `--auto-reset` | `true` | Auto-reset when no TTY prompt |
135
+ | `--force` | `false` | Force acquire session lock |
136
+ | `--fallback-agent` | (none) | Fallback agent mapping (format: `primary:fallback`) |
96
137
 
97
138
  ### Init Subcommand
98
139
 
99
140
  ```bash
100
- ralph init # create template PRD and prompt
141
+ ralph init # create template PRD, prompt, plugin, and AGENTS.md
101
142
  ralph init --from plan.md # convert markdown plan to PRD JSON
102
143
  ralph init --force # overwrite existing files
103
144
  ```
104
145
 
146
+ Creates these files:
147
+ - `prd.json` — PRD plan file (wrapped format with metadata)
148
+ - `progress.txt` — Progress log
149
+ - `.ralph-prompt.md` — Prompt template
150
+ - `.opencode/plugin/ralph-write-guardrail.ts` — Write guardrail plugin
151
+ - `AGENTS.md` — Project configuration for AI agents (never overwritten)
152
+ - `.gitignore` entries — Adds Ralph runtime files to .gitignore
153
+
105
154
  | Option | Description |
106
155
  |--------|-------------|
107
156
  | `--from` | Source plan or notes to convert into PRD JSON |
108
- | `--force` | Overwrite existing files |
157
+ | `--force` | Overwrite existing files (except AGENTS.md) |
158
+
159
+ <details>
160
+ <summary><strong>Default Prompt Template</strong></summary>
109
161
 
110
- **Default prompt:**
111
162
  ```
112
163
  READ all of {plan} and {progress}. Pick ONE task with passes=false (prefer highest-risk/highest-impact). Keep changes small: one logical change per commit. Update {plan} by setting passes=true and adding notes or steps as needed. Append a brief entry to {progress} with what changed and why. Run feedback loops before committing: bun run typecheck, bun test, bun run lint (if missing, note it in {progress} and continue). Commit change (update {plan} in the same commit). ONLY do one task unless GLARINGLY OBVIOUS steps should run together. Quality bar: production code, maintainable, tests when appropriate. If you learn a critical operational detail, update AGENTS.md. When ALL tasks complete, create .ralph-done and output <promise>COMPLETE</promise>. NEVER GIT PUSH. ONLY COMMIT.
113
164
  ```
114
165
 
166
+ </details>
167
+
168
+ ### Converting Plans to PRDs
169
+
170
+ When running `ralph init --from plan.md`, OpenRalph intelligently converts your markdown notes into a structured `prd.json`.
171
+
172
+ #### Best Practice `plan.md` Format:
173
+ To get the most out of the conversion, use this format in your markdown plans:
174
+
175
+ ```markdown
176
+ # My Project Plan
177
+
178
+ - [x] [setup] Initialize repository and project structure
179
+ - [x] [ui] Design the landing page hero section
180
+ - [ ] [feat] Implement user authentication logic
181
+ - [ ] [feat] Add database persistence for tasks
182
+ - [ ] Plain list items are also picked up
183
+ * Asterisk lists work too
184
+ 1. Numbered lists are also supported
185
+ ```
186
+
187
+ **Why this works:**
188
+ - **Status Syncing**: Ralph detects `[x]` as completed (`passes: true`) and `[ ]` as pending (`passes: false`).
189
+ - **Category Tags**: Placing a bracketed tag like `[ui]` or `[feat]` at the start of a task automatically sets the `category` field in the generated PRD.
190
+ - **Deduplication**: Ralph automatically removes duplicate tasks during the conversion process.
191
+ - **Universal Support**: Works across Windows, macOS, and Linux with any standard terminal.
192
+
193
+ ---
194
+
115
195
  ## Configuration
116
196
 
117
197
  Ralph reads configuration from `~/.config/ralph/config.json`:
@@ -129,9 +209,23 @@ Ralph reads configuration from `~/.config/ralph/config.json`:
129
209
 
130
210
  CLI arguments override config file values.
131
211
 
132
- ### Adapters
212
+ ### Environment Variables
133
213
 
134
- Ralph supports multiple adapters for running the AI agent:
214
+ | Variable | Description |
215
+ |----------|-------------|
216
+ | `RALPH_MODEL` | Override model |
217
+ | `RALPH_ADAPTER` | Override adapter |
218
+ | `RALPH_PLAN` | Override plan file path |
219
+ | `RALPH_PROGRESS` | Override progress log path |
220
+ | `RALPH_SERVER` | Override OpenCode server URL |
221
+
222
+ ### Safety & Reliability
223
+
224
+ - **Session Locking** — Prevents multiple Ralph instances from running in the same directory
225
+ - **Error Backoff** — Retries failed agent iterations with exponential backoff
226
+ - **Graceful Shutdown** — Double Ctrl+C for force quit, single for confirmed exit
227
+
228
+ ### Adapters
135
229
 
136
230
  | Adapter | Description |
137
231
  |---------|-------------|
@@ -139,27 +233,7 @@ Ralph supports multiple adapters for running the AI agent:
139
233
  | `opencode-run` | Spawns `opencode run` as PTY subprocess |
140
234
  | `codex` | Spawns OpenAI Codex CLI as PTY subprocess |
141
235
 
142
- ## Workflow Files
143
-
144
- | File | Purpose |
145
- |------|---------|
146
- | `prd.json` | PRD plan items with `passes` state |
147
- | `progress.txt` | Progress log appended each iteration |
148
- | `.ralph-prompt.md` | Prompt template used for loop runs |
149
- | `.ralph-state.json` | Persisted state for resume after Ctrl+C |
150
- | `.ralph-lock` | Prevents multiple instances |
151
- | `.ralph-done` | Agent creates this when all tasks complete |
152
- | `.ralph-pause` | Created by `p` key to pause loop |
153
-
154
- **Generated file markers:** Files created by `ralph init` include markers so `ralph --reset` can identify and remove them safely without touching user-created files:
155
- - `prd.json`: Wrapped with `{ metadata: { generated: true, ... }, items: [...] }`
156
- - `.ralph-prompt.md`: YAML frontmatter with `generated: true`
157
- - `progress.txt`: Contains "Initialized via ralph init." marker
158
-
159
- Add to `.gitignore`:
160
- ```
161
- .ralph-*
162
- ```
236
+ ---
163
237
 
164
238
  ## Writing PRDs
165
239
 
@@ -199,17 +273,35 @@ Prefer PRD JSON with `passes` flags so Ralph can track scope and progress. Two f
199
273
  }
200
274
  ```
201
275
 
202
- **Guidelines:**
203
- - Small, isolated tasks—one commit each
276
+ **Tips:**
277
+ - Small, isolated tasks one commit each
204
278
  - Explicit verification steps
205
279
  - Set `passes` to true only when verified
206
280
  - 1000+ lines is normal; more detail = fewer hallucinations
281
+ - Legacy markdown checkboxes work too, but `ralph init --from plan.md` is the upgrade path
282
+
283
+ ---
207
284
 
208
- Legacy markdown checkboxes are still supported, but `ralph init --from plan.md` is the recommended upgrade path.
285
+ ## Workflow Files
286
+
287
+ | File | Purpose |
288
+ |------|---------|
289
+ | `prd.json` | PRD plan items with `passes` state |
290
+ | `progress.txt` | Progress log appended each iteration |
291
+ | `.ralph-prompt.md` | Prompt template used for loop runs |
292
+ | `.ralph-state.json` | Persisted state for resume after Ctrl+C |
293
+ | `.ralph-lock` | Prevents multiple instances |
294
+ | `.ralph-done` | Agent creates this when all tasks complete |
295
+ | `.ralph-pause` | Created by `p` key to pause loop |
296
+ | `.opencode/plugin/ralph-write-guardrail.ts` | Protects files from AI modification |
297
+ | `AGENTS.md` | Project configuration for AI agents |
209
298
 
210
- ## Progress Log
299
+ Add to `.gitignore`:
300
+ ```
301
+ .ralph-*
302
+ ```
211
303
 
212
- Append a short entry each iteration. Example:
304
+ ### Progress Log Example
213
305
 
214
306
  ```
215
307
  ## Iteration 3 - 2025-01-10T12:34:56Z
@@ -219,7 +311,7 @@ Append a short entry each iteration. Example:
219
311
  - Notes: Added retry logic for timeouts
220
312
  ```
221
313
 
222
- ## AGENTS.md
314
+ ### AGENTS.md
223
315
 
224
316
  Ralph writes operational learnings here. Future iterations read it.
225
317
 
@@ -233,11 +325,14 @@ Ralph writes operational learnings here. Future iterations read it.
233
325
  - Never import from `solid-js`, use `@opentui/solid`
234
326
  ```
235
327
 
328
+ ---
329
+
236
330
  ## Keybindings
237
331
 
238
332
  | Key | Action |
239
333
  |-----|--------|
240
- | `q` / `Ctrl+C` | Quit |
334
+ | `q` / `Ctrl+C` | Quit (shows confirmation) |
335
+ | `Ctrl+C` (double) | Force quit |
241
336
  | `p` | Pause/Resume loop |
242
337
  | `c` | Open command palette |
243
338
  | `:` | Steering mode (send message to agent) |
@@ -245,30 +340,41 @@ Ralph writes operational learnings here. Future iterations read it.
245
340
  | `Shift+T` | Toggle tasks panel |
246
341
  | `o` | Toggle Details/Output view |
247
342
  | `d` | Toggle progress dashboard |
343
+ | `x` | Toggle task status (staged) |
248
344
  | `?` | Show help overlay |
249
345
  | `↑` / `k` | Navigate up (in tasks panel) |
250
346
  | `↓` / `j` | Navigate down (in tasks panel) |
251
347
  | `n` | New session (debug mode only) |
252
348
  | `Escape` | Close overlay/panel |
253
349
 
350
+ ---
351
+
254
352
  ## Architecture
255
353
 
256
354
  ```
257
355
  src/
258
- ├── index.ts # CLI entry, wires TUI to loop
259
- ├── loop.ts # Main agent loop (prompt → events → commit)
260
- ├── app.tsx # Solid.js TUI root component
261
- ├── state.ts # State types and persistence
262
- ├── plan.ts # PRD + markdown plan parser
263
- ├── git.ts # Git operations (hash, diff, commits)
264
- ├── lock.ts # Lock file management
265
- ├── prompt.ts # User confirmation prompts
266
- ├── components/ # TUI components (header, log, footer)
267
- └── util/ # Helpers (time formatting, logging)
356
+ ├── index.ts # CLI entry, wires TUI to loop
357
+ ├── loop.ts # Main agent loop (prompt → events → commit)
358
+ ├── app.tsx # Solid.js TUI root component
359
+ ├── state.ts # State types and persistence
360
+ ├── plan.ts # PRD + markdown plan parser
361
+ ├── git.ts # Git operations (hash, diff, commits)
362
+ ├── prompt.ts # User confirmation prompts
363
+ ├── adapters/ # Adapter implementations (opencode, codex)
364
+ ├── components/ # TUI components (header, log, footer, panels)
365
+ ├── context/ # React-style contexts (theme, dialog, toast)
366
+ ├── hooks/ # Custom hooks (keyboard, loop state, stats)
367
+ ├── lib/ # Core utilities (config, logging, theming, time)
368
+ ├── pty/ # PTY subprocess management
369
+ ├── templates/ # Init templates (agents, plugins)
370
+ ├── types/ # TypeScript type definitions
371
+ └── ui/ # Dialog components
268
372
  ```
269
373
 
270
374
  **Data flow:** `index.ts` starts the TUI (`app.tsx`) and the loop (`loop.ts`) in parallel. The loop sends callbacks to update TUI state. State persists to `.ralph-state.json` for resume capability.
271
375
 
376
+ ---
377
+
272
378
  ## Testing
273
379
 
274
380
  ```bash
@@ -285,7 +391,42 @@ tests/
285
391
  └── helpers/ # Mock factories, temp file utils
286
392
  ```
287
393
 
394
+ ---
395
+
288
396
  ## Requirements
289
397
 
290
398
  - [Bun](https://bun.sh) v1.0+
291
- - [OpenCode](https://opencode.ai) CLI running
399
+ - [OpenCode](https://opencode.ai) CLI running (or alternative adapter)
400
+
401
+ ---
402
+
403
+ ## Contributing
404
+
405
+ Contributions are welcome! Feel free to submit a Pull Request.
406
+
407
+ 1. Fork the repo
408
+ 2. Create your feature branch (`git checkout -b feature/cool-stuff`)
409
+ 3. Commit your changes (`git commit -m 'Add cool stuff'`)
410
+ 4. Push to the branch (`git push origin feature/cool-stuff`)
411
+ 5. Open a Pull Request
412
+
413
+ ---
414
+
415
+ ## Credits
416
+
417
+ - Thanks to [Geoffrey Huntley](https://ghuntley.com) for the original Ralph Wiggum loop concept
418
+ - OpenRalph is a fork of [`opencode-ralph`](https://github.com/hona/opencode-ralph) — huge thanks to [Hona](https://github.com/hona) for the original implementation
419
+
420
+ ---
421
+
422
+ ## License
423
+
424
+ MIT License - see [LICENSE](LICENSE) for details.
425
+
426
+ ---
427
+
428
+ <div align="center">
429
+
430
+ Made by the ralph development community
431
+
432
+ </div>
package/bin/ralph CHANGED
@@ -8,6 +8,7 @@ import { fileURLToPath } from "node:url";
8
8
 
9
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
10
  const require = createRequire(import.meta.url);
11
+ const projectRoot = path.resolve(__dirname, "..");
11
12
 
12
13
  const platformMap = {
13
14
  darwin: "darwin",
@@ -26,18 +27,35 @@ const packageName = `openralph-${platform}-${arch}`;
26
27
  const binaryName = platform === "windows" ? "ralph.exe" : "ralph";
27
28
 
28
29
  let binaryPath;
29
- try {
30
- const packageJsonPath = require.resolve(`${packageName}/package.json`);
31
- const packageDir = path.dirname(packageJsonPath);
32
- binaryPath = path.join(packageDir, "bin", binaryName);
33
- } catch (error) {
34
- const message = error instanceof Error ? error.message : String(error);
35
- console.error(`Failed to resolve ${packageName}: ${message}`);
36
- process.exit(1);
30
+
31
+ // First, check for locally built binary in dist/ directory
32
+ const localBinaryPath = path.join(projectRoot, "dist", packageName, "bin", binaryName);
33
+ if (fs.existsSync(localBinaryPath)) {
34
+ binaryPath = localBinaryPath;
35
+ } else {
36
+ // Fall back to npm package resolution for installed packages
37
+ try {
38
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
39
+ const packageDir = path.dirname(packageJsonPath);
40
+ binaryPath = path.join(packageDir, "bin", binaryName);
41
+ } catch (error) {
42
+ // No local build and no npm package found
43
+ console.error(`Error: No ralph binary found for ${platform}-${arch}.`);
44
+ console.error("");
45
+ console.error("To fix this, run:");
46
+ console.error(" bun run build:single # Build for current platform");
47
+ console.error("");
48
+ console.error("Or install globally:");
49
+ console.error(" bun install -g openralph");
50
+ process.exit(1);
51
+ }
37
52
  }
38
53
 
39
54
  if (!fs.existsSync(binaryPath)) {
40
- console.error(`Binary not found at ${binaryPath}`);
55
+ console.error(`Error: Binary not found at ${binaryPath}`);
56
+ console.error("");
57
+ console.error("To fix this, run:");
58
+ console.error(" bun run build:single # Rebuild for current platform");
41
59
  process.exit(1);
42
60
  }
43
61
 
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "openralph",
3
- "version": "1.0.12",
3
+ "version": "2.0.0",
4
4
  "description": "Ralph Driven Development using OpenCode SDK and OpenTUI",
5
5
  "bin": {
6
6
  "ralph": "./bin/ralph"
7
7
  },
8
8
  "optionalDependencies": {
9
- "openralph-darwin-arm64": "1.0.12",
10
- "openralph-darwin-x64": "1.0.12",
11
- "openralph-linux-arm64": "1.0.12",
12
- "openralph-linux-x64": "1.0.12",
13
- "openralph-windows-x64": "1.0.12"
9
+ "openralph-darwin-arm64": "2.0.0",
10
+ "openralph-darwin-x64": "2.0.0",
11
+ "openralph-linux-arm64": "2.0.0",
12
+ "openralph-linux-x64": "2.0.0",
13
+ "openralph-windows-x64": "2.0.0"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",