openralph 1.0.13 → 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 (2) hide show
  1. package/README.md +191 -61
  2. 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,6 +132,8 @@ 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
 
@@ -102,24 +143,55 @@ ralph init --from plan.md # convert markdown plan to PRD JSON
102
143
  ralph init --force # overwrite existing files
103
144
  ```
104
145
 
105
- The `init` command creates:
106
- - `prd.json` - PRD plan file (wrapped format with metadata)
107
- - `progress.txt` - Progress log
108
- - `.ralph-prompt.md` - Prompt template
109
- - `.opencode/plugin/ralph-write-guardrail.ts` - Write guardrail plugin
110
- - `AGENTS.md` - Project configuration for AI agents (never overwritten)
111
- - `.gitignore` entries - Adds Ralph runtime files to .gitignore
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
112
153
 
113
154
  | Option | Description |
114
155
  |--------|-------------|
115
156
  | `--from` | Source plan or notes to convert into PRD JSON |
116
157
  | `--force` | Overwrite existing files (except AGENTS.md) |
117
158
 
118
- **Default prompt:**
159
+ <details>
160
+ <summary><strong>Default Prompt Template</strong></summary>
161
+
119
162
  ```
120
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.
121
164
  ```
122
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
+
123
195
  ## Configuration
124
196
 
125
197
  Ralph reads configuration from `~/.config/ralph/config.json`:
@@ -137,9 +209,23 @@ Ralph reads configuration from `~/.config/ralph/config.json`:
137
209
 
138
210
  CLI arguments override config file values.
139
211
 
140
- ### Adapters
212
+ ### Environment Variables
141
213
 
142
- 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
143
229
 
144
230
  | Adapter | Description |
145
231
  |---------|-------------|
@@ -147,29 +233,7 @@ Ralph supports multiple adapters for running the AI agent:
147
233
  | `opencode-run` | Spawns `opencode run` as PTY subprocess |
148
234
  | `codex` | Spawns OpenAI Codex CLI as PTY subprocess |
149
235
 
150
- ## Workflow Files
151
-
152
- | File | Purpose |
153
- |------|---------|
154
- | `prd.json` | PRD plan items with `passes` state |
155
- | `progress.txt` | Progress log appended each iteration |
156
- | `.ralph-prompt.md` | Prompt template used for loop runs |
157
- | `.ralph-state.json` | Persisted state for resume after Ctrl+C |
158
- | `.ralph-lock` | Prevents multiple instances |
159
- | `.ralph-done` | Agent creates this when all tasks complete |
160
- | `.ralph-pause` | Created by `p` key to pause loop |
161
- | `.opencode/plugin/ralph-write-guardrail.ts` | Protects files from AI modification |
162
- | `AGENTS.md` | Project configuration for AI agents |
163
-
164
- **Generated file markers:** Files created by `ralph init` include markers so `ralph --reset` can identify and remove them safely without touching user-created files:
165
- - `prd.json`: Wrapped with `{ metadata: { generated: true, ... }, items: [...] }`
166
- - `.ralph-prompt.md`: YAML frontmatter with `generated: true`
167
- - `progress.txt`: Contains "Initialized via ralph init." marker
168
-
169
- Add to `.gitignore`:
170
- ```
171
- .ralph-*
172
- ```
236
+ ---
173
237
 
174
238
  ## Writing PRDs
175
239
 
@@ -209,17 +273,35 @@ Prefer PRD JSON with `passes` flags so Ralph can track scope and progress. Two f
209
273
  }
210
274
  ```
211
275
 
212
- **Guidelines:**
213
- - Small, isolated tasks—one commit each
276
+ **Tips:**
277
+ - Small, isolated tasks one commit each
214
278
  - Explicit verification steps
215
279
  - Set `passes` to true only when verified
216
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
217
282
 
218
- Legacy markdown checkboxes are still supported, but `ralph init --from plan.md` is the recommended upgrade path.
283
+ ---
219
284
 
220
- ## Progress Log
285
+ ## Workflow Files
221
286
 
222
- Append a short entry each iteration. Example:
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 |
298
+
299
+ Add to `.gitignore`:
300
+ ```
301
+ .ralph-*
302
+ ```
303
+
304
+ ### Progress Log Example
223
305
 
224
306
  ```
225
307
  ## Iteration 3 - 2025-01-10T12:34:56Z
@@ -229,7 +311,7 @@ Append a short entry each iteration. Example:
229
311
  - Notes: Added retry logic for timeouts
230
312
  ```
231
313
 
232
- ## AGENTS.md
314
+ ### AGENTS.md
233
315
 
234
316
  Ralph writes operational learnings here. Future iterations read it.
235
317
 
@@ -243,43 +325,56 @@ Ralph writes operational learnings here. Future iterations read it.
243
325
  - Never import from `solid-js`, use `@opentui/solid`
244
326
  ```
245
327
 
328
+ ---
329
+
246
330
  ## Keybindings
247
331
 
248
332
  | Key | Action |
249
333
  |-----|--------|
250
- | `q` / `Ctrl+C` | Quit |
334
+ | `q` / `Ctrl+C` | Quit (shows confirmation) |
335
+ | `Ctrl+C` (double) | Force quit |
251
336
  | `p` | Pause/Resume loop |
252
337
  | `c` | Open command palette |
253
338
  | `:` | Steering mode (send message to agent) |
254
339
  | `t` | Launch terminal with attach command |
255
340
  | `Shift+T` | Toggle tasks panel |
256
- | `Shift+C` | Toggle completed tasks / Copy attach command |
257
341
  | `o` | Toggle Details/Output view |
258
342
  | `d` | Toggle progress dashboard |
343
+ | `x` | Toggle task status (staged) |
259
344
  | `?` | Show help overlay |
260
345
  | `↑` / `k` | Navigate up (in tasks panel) |
261
346
  | `↓` / `j` | Navigate down (in tasks panel) |
262
347
  | `n` | New session (debug mode only) |
263
348
  | `Escape` | Close overlay/panel |
264
349
 
350
+ ---
351
+
265
352
  ## Architecture
266
353
 
267
354
  ```
268
355
  src/
269
- ├── index.ts # CLI entry, wires TUI to loop
270
- ├── loop.ts # Main agent loop (prompt → events → commit)
271
- ├── app.tsx # Solid.js TUI root component
272
- ├── state.ts # State types and persistence
273
- ├── plan.ts # PRD + markdown plan parser
274
- ├── git.ts # Git operations (hash, diff, commits)
275
- ├── lock.ts # Lock file management
276
- ├── prompt.ts # User confirmation prompts
277
- ├── components/ # TUI components (header, log, footer)
278
- └── 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
279
372
  ```
280
373
 
281
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.
282
375
 
376
+ ---
377
+
283
378
  ## Testing
284
379
 
285
380
  ```bash
@@ -296,7 +391,42 @@ tests/
296
391
  └── helpers/ # Mock factories, temp file utils
297
392
  ```
298
393
 
394
+ ---
395
+
299
396
  ## Requirements
300
397
 
301
398
  - [Bun](https://bun.sh) v1.0+
302
- - [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/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "openralph",
3
- "version": "1.0.13",
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.13",
10
- "openralph-darwin-x64": "1.0.13",
11
- "openralph-linux-arm64": "1.0.13",
12
- "openralph-linux-x64": "1.0.13",
13
- "openralph-windows-x64": "1.0.13"
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",