@ralph-orchestrator/ralph-cli 0.0.1 → 2.0.5

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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /node_modules
2
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ralph Orchestrator Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,477 @@
1
- # @ralph-orchestrator/ralph-cli
1
+ # Ralph Orchestrator
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
4
+ [![Rust](https://img.shields.io/badge/rust-1.75+-orange)](https://www.rust-lang.org/)
5
+ [![Build](https://img.shields.io/github/actions/workflow/status/mikeyobrien/ralph-orchestrator/ci.yml?branch=main&label=CI)](https://github.com/mikeyobrien/ralph-orchestrator/actions)
6
+ [![Mentioned in Awesome Claude Code](https://awesome.re/mentioned-badge.svg)](https://github.com/hesreallyhim/awesome-claude-code)
4
7
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
8
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
9
+ A hat-based multi-agent orchestration framework that keeps AI agents in a loop until the task is done.
8
10
 
9
- ## Purpose
11
+ > "Me fail English? That's unpossible!" - Ralph Wiggum
10
12
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@ralph-orchestrator/ralph-cli`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
13
+ **Alpha Notice:** Ralph Orchestrator is under active development. It works today, but expect rough edges and breaking changes between releases.
15
14
 
16
- ## What is OIDC Trusted Publishing?
15
+ v1.0.0 was ralphed into existence with little oversight and guidance. v2.0.0 is a simpler, more-structured implementation. Looking for the old version? See [v1.2.3](https://github.com/mikeyobrien/ralph-orchestrator/tree/v1.2.3).
17
16
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
17
+ ## Table of Contents
19
18
 
20
- ## Setup Instructions
19
+ - [What is Ralph?](#what-is-ralph)
20
+ - [Features](#features)
21
+ - [Installation](#installation)
22
+ - [Quick Start](#quick-start)
23
+ - [Configuration](#configuration)
24
+ - [Presets](#presets)
25
+ - [Key Concepts](#key-concepts)
26
+ - [CLI Reference](#cli-reference)
27
+ - [Architecture](#architecture)
28
+ - [Building & Testing](#building--testing)
29
+ - [Contributing](#contributing)
30
+ - [License](#license)
31
+ - [Acknowledgments](#acknowledgments)
21
32
 
22
- To properly configure OIDC trusted publishing for this package:
33
+ ## What is Ralph?
23
34
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
35
+ Ralph implements the [Ralph Wiggum technique](https://ghuntley.com/ralph/) autonomous task completion through continuous AI agent iteration. Unlike simple loops, Ralph v2 introduces **hat-based orchestration**: specialized agent roles that coordinate through events.
28
36
 
29
- ## DO NOT USE THIS PACKAGE
37
+ > "The orchestrator is a thin coordination layer, not a platform. Agents are smart; let them do the work."
30
38
 
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
39
+ ### The Ralph Tenets
36
40
 
37
- ## More Information
41
+ 1. **Fresh Context Is Reliability** — Each iteration clears context. Re-read specs, plan, code every cycle.
42
+ 2. **Backpressure Over Prescription** — Don't prescribe how; create gates that reject bad work.
43
+ 3. **The Plan Is Disposable** — Regeneration costs one planning loop. Cheap.
44
+ 4. **Disk Is State, Git Is Memory** — Files are the handoff mechanism.
45
+ 5. **Steer With Signals, Not Scripts** — Add signs, not scripts.
46
+ 6. **Let Ralph Ralph** — Sit *on* the loop, not *in* it.
38
47
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
48
+ See [AGENTS.md](AGENTS.md) for the full philosophy.
49
+
50
+ ## Features
51
+
52
+ - **Multi-Backend Support** — Works with Claude Code, Kiro, Gemini CLI, Codex, and Amp
53
+ - **Hat System** — Specialized agent personas with distinct behaviors
54
+ - **Event-Driven Coordination** — Hats communicate through typed events with glob pattern matching
55
+ - **Backpressure Enforcement** — Gates that reject incomplete work (tests, lint, typecheck)
56
+ - **Presets Library** — 20+ pre-configured workflows for common development patterns
57
+ - **Interactive TUI** — Real-time terminal UI for monitoring agent activity (experimental)
58
+ - **Session Recording** — Record and replay sessions for debugging and testing (experimental)
59
+
60
+ ## Installation
61
+
62
+ ### Prerequisites
63
+
64
+ - [Rust](https://rustup.rs/) 1.75+
65
+ - At least one AI CLI:
66
+ - [Claude Code](https://github.com/anthropics/claude-code) (recommended)
67
+ - [Kiro](https://kiro.dev/)
68
+ - [Gemini CLI](https://github.com/google-gemini/gemini-cli)
69
+ - [Codex](https://github.com/openai/codex)
70
+ - [Amp](https://github.com/sourcegraph/amp)
71
+
72
+ ### Via npm (Recommended)
73
+
74
+ ```bash
75
+ # Install globally
76
+ npm install -g @ralph-orchestrator/ralph
77
+
78
+ # Or run directly with npx
79
+ npx @ralph-orchestrator/ralph --version
80
+ ```
81
+
82
+ ### Via Cargo
83
+
84
+ ```bash
85
+ cargo install ralph-cli
86
+ ```
87
+
88
+ ### From Source
89
+
90
+ ```bash
91
+ git clone https://github.com/mikeyobrien/ralph-orchestrator.git
92
+ cd ralph-orchestrator
93
+ cargo build --release
94
+
95
+ # Add to PATH
96
+ export PATH="$PATH:$(pwd)/target/release"
97
+
98
+ # Or create symlink
99
+ sudo ln -s $(pwd)/target/release/ralph /usr/local/bin/ralph
100
+ ```
101
+
102
+ ### Verify Installation
103
+
104
+ ```bash
105
+ ralph --version
106
+ ralph --help
107
+ ```
108
+
109
+ ### Migrating from v1 (Python)
110
+
111
+ If you have the old Python-based Ralph v1 installed, uninstall it first to avoid conflicts:
112
+
113
+ ```bash
114
+ # If installed via pip
115
+ pip uninstall ralph-orchestrator
116
+
117
+ # If installed via pipx
118
+ pipx uninstall ralph-orchestrator
119
+
120
+ # If installed via uv
121
+ uv tool uninstall ralph-orchestrator
122
+
123
+ # Verify removal
124
+ which ralph # Should return nothing or point to new Rust version
125
+ ```
126
+
127
+ The v1 Python version is no longer maintained. See [v1.2.3](https://github.com/mikeyobrien/ralph-orchestrator/tree/v1.2.3) for historical reference.
128
+
129
+ ## Quick Start
130
+
131
+ ### 1. Initialize a Project
132
+
133
+ ```bash
134
+ # Minimal config for Claude (recommended)
135
+ ralph init --backend claude
136
+
137
+ # Use a preset workflow
138
+ ralph init --preset tdd-red-green
139
+
140
+ # Combine preset with different backend
141
+ ralph init --preset spec-driven --backend kiro
142
+
143
+ # See all available presets
144
+ ralph init --list-presets
145
+ ```
146
+
147
+ This creates `ralph.yml` in your current directory.
148
+
149
+ ### 2. Define Your Task
150
+
151
+ **Option A:** Create a `PROMPT.md` file:
152
+
153
+ ```bash
154
+ cat > PROMPT.md << 'EOF'
155
+ Build a REST API with the following endpoints:
156
+ - POST /users - Create a new user
157
+ - GET /users/:id - Get user by ID
158
+ - PUT /users/:id - Update user
159
+ - DELETE /users/:id - Delete user
160
+
161
+ Use Express.js with TypeScript. Include input validation
162
+ and proper error handling.
163
+ EOF
164
+ ```
165
+
166
+ **Option B:** Pass inline prompt when running:
167
+
168
+ ```bash
169
+ ralph run -p "Add input validation to the user API endpoints"
170
+ ```
171
+
172
+ ### 3. Run Ralph
173
+
174
+ ```bash
175
+ # Autonomous mode (headless, default)
176
+ ralph run
177
+
178
+ # With inline prompt
179
+ ralph run -p "Implement the login endpoint with JWT authentication"
180
+
181
+ # Interactive TUI mode (experimental)
182
+ ralph run -i
183
+
184
+ # Resume interrupted session
185
+ ralph resume
186
+
187
+ # Dry run (show what would execute)
188
+ ralph run --dry-run
189
+ ```
190
+
191
+ ## Configuration
192
+
193
+ Ralph uses a YAML configuration file (`ralph.yml` by default).
194
+
195
+ ### Minimal Configuration
196
+
197
+ ```yaml
198
+ # ralph.yml
199
+ cli:
200
+ backend: "claude"
201
+
202
+ event_loop:
203
+ completion_promise: "LOOP_COMPLETE"
204
+ max_iterations: 100
205
+ ```
206
+
207
+ ### Full Configuration Reference
208
+
209
+ ```yaml
210
+ # Event loop settings
211
+ event_loop:
212
+ completion_promise: "LOOP_COMPLETE" # Output that signals completion
213
+ max_iterations: 100 # Maximum orchestration loops
214
+ max_runtime_seconds: 14400 # 4 hours max runtime
215
+ idle_timeout_secs: 1800 # 30 min idle timeout
216
+ starting_event: "task.start" # First event published
217
+
218
+ # CLI backend settings
219
+ cli:
220
+ backend: "claude" # claude, kiro, gemini, codex, amp, custom
221
+ prompt_mode: "arg" # arg (CLI argument) or stdin
222
+ experimental_tui: false # Enable TUI mode support
223
+
224
+ # Core behaviors (always injected into prompts)
225
+ core:
226
+ scratchpad: ".agent/scratchpad.md" # Shared memory across iterations
227
+ specs_dir: "./specs/" # Directory for specifications
228
+ guardrails: # Rules injected into every prompt
229
+ - "Fresh context each iteration - scratchpad is memory"
230
+ - "Don't assume 'not implemented' - search first"
231
+ - "Backpressure is law - tests/typecheck/lint must pass"
232
+
233
+ # Custom hats (omit to use default planner/builder)
234
+ hats:
235
+ my_hat:
236
+ name: "My Hat Name" # Display name
237
+ triggers: ["some.event"] # Events that activate this hat
238
+ publishes: ["other.event"] # Events this hat can emit
239
+ instructions: | # Prompt instructions
240
+ What this hat should do...
241
+ ```
242
+
243
+
244
+ ## Presets
245
+
246
+ Presets are pre-configured workflows for common development patterns.
247
+
248
+ ### Development Workflows
249
+
250
+ | Preset | Pattern | Description |
251
+ |--------|---------|-------------|
252
+ | `feature` | Planner-Builder | Standard feature development |
253
+ | `feature-minimal` | Single hat | Minimal feature development |
254
+ | `tdd-red-green` | Test-Implement-Refactor | TDD with red-green-refactor cycle |
255
+ | `spec-driven` | Spec-Build-Verify | Specification-first development |
256
+ | `refactor` | Analyze-Plan-Execute | Code refactoring workflow |
257
+
258
+ ### Debugging & Investigation
259
+
260
+ | Preset | Pattern | Description |
261
+ |--------|---------|-------------|
262
+ | `debug` | Investigate-Fix-Verify | Bug investigation and fixing |
263
+ | `incident-response` | Triage-Fix-Postmortem | Production incident handling |
264
+ | `code-archaeology` | Explore-Document-Present | Legacy code understanding |
265
+
266
+ ### Review & Quality
267
+
268
+ | Preset | Pattern | Description |
269
+ |--------|---------|-------------|
270
+ | `review` | Analyze-Critique-Suggest | Code review workflow |
271
+ | `pr-review` | Multi-Perspective | PR review with specialized reviewers |
272
+ | `adversarial-review` | Critic-Defender | Devil's advocate review style |
273
+
274
+ ### Documentation
275
+
276
+ | Preset | Pattern | Description |
277
+ |--------|---------|-------------|
278
+ | `docs` | Write-Review-Publish | Documentation writing |
279
+ | `documentation-first` | Doc-Implement-Sync | Doc-first development |
280
+
281
+ ### Specialized
282
+
283
+ | Preset | Pattern | Description |
284
+ |--------|---------|-------------|
285
+ | `api-design` | Design-Implement-Document | API-first development |
286
+ | `migration-safety` | Analyze-Migrate-Verify | Safe code migrations |
287
+ | `performance-optimization` | Profile-Optimize-Benchmark | Performance tuning |
288
+ | `scientific-method` | Hypothesis-Experiment-Conclude | Experimental approach |
289
+ | `mob-programming` | Rotate roles | Simulated mob programming |
290
+ | `socratic-learning` | Question-Answer-Synthesize | Learning through dialogue |
291
+ | `research` | Gather-Analyze-Synthesize | Research and analysis |
292
+ | `gap-analysis` | Current-Target-Plan | Gap identification |
293
+
294
+ ### Using Presets
295
+
296
+ ```bash
297
+ # List all available presets
298
+ ralph init --list-presets
299
+
300
+ # Initialize with a preset
301
+ ralph init --preset tdd-red-green
302
+
303
+ # Use preset with different backend
304
+ ralph init --preset spec-driven --backend gemini
305
+
306
+ # Override existing config
307
+ ralph init --preset debug --force
308
+ ```
309
+
310
+ ## Key Concepts
311
+
312
+ ### Hats
313
+
314
+ Hats are specialized agent personas. Each hat has:
315
+
316
+ - **Triggers**: Events that activate this hat
317
+ - **Publishes**: Events this hat can emit
318
+ - **Instructions**: Prompt injected when hat is active
319
+
320
+ View event history:
321
+
322
+ ```bash
323
+ ralph events
324
+ ```
325
+
326
+ ### Scratchpad
327
+
328
+ All hats share `.agent/scratchpad.md` — persistent memory across iterations. This enables hats to build on previous work rather than starting fresh.
329
+
330
+ The scratchpad is the primary mechanism for:
331
+ - Task tracking (with `[ ]`, `[x]`, `[~]` markers)
332
+ - Context preservation between iterations
333
+ - Handoff between hats
334
+
335
+ ### Backpressure
336
+
337
+ Ralph enforces quality gates through backpressure. When a builder publishes `build.done`, it must include evidence:
338
+
339
+ ```
340
+ tests: pass, lint: pass, typecheck: pass
341
+ ```
342
+
343
+ ## CLI Reference
344
+
345
+ ### Commands
346
+
347
+ | Command | Description |
348
+ |---------|-------------|
349
+ | `ralph run` | Run the orchestration loop (default) |
350
+ | `ralph resume` | Resume from existing scratchpad |
351
+ | `ralph events` | View event history |
352
+ | `ralph init` | Initialize configuration file |
353
+ | `ralph clean` | Clean up `.agent/` directory |
354
+ | `ralph emit` | Emit an event to the event log |
355
+
356
+ ### Global Options
357
+
358
+ | Option | Description |
359
+ |--------|-------------|
360
+ | `-c, --config <FILE>` | Config file path (default: `ralph.yml`) |
361
+ | `-v, --verbose` | Verbose output |
362
+ | `--color <MODE>` | Color output: `auto`, `always`, `never` |
363
+
364
+ ### `ralph run` Options
365
+
366
+ | Option | Description |
367
+ |--------|-------------|
368
+ | `-p, --prompt <TEXT>` | Inline prompt text |
369
+ | `-P, --prompt-file <FILE>` | Prompt file path |
370
+ | `--max-iterations <N>` | Override max iterations |
371
+ | `--completion-promise <TEXT>` | Override completion trigger |
372
+ | `--dry-run` | Show what would execute |
373
+ | `-i, --interactive` | Enable TUI mode (experimental) |
374
+ | `-a, --autonomous` | Force headless mode |
375
+ | `--idle-timeout <SECS>` | TUI idle timeout (default: 30) |
376
+ | `--record-session <FILE>` | Record session to JSONL |
377
+ | `-q, --quiet` | Suppress output (for CI) |
378
+
379
+ ### `ralph init` Options
380
+
381
+ | Option | Description |
382
+ |--------|-------------|
383
+ | `--backend <NAME>` | Backend: `claude`, `kiro`, `gemini`, `codex`, `amp` |
384
+ | `--preset <NAME>` | Use preset configuration |
385
+ | `--list-presets` | List available presets |
386
+ | `--force` | Overwrite existing config |
387
+
388
+ ## Architecture
389
+
390
+ Ralph is organized as a Cargo workspace with six crates:
391
+
392
+ | Crate | Purpose |
393
+ |-------|---------|
394
+ | `ralph-proto` | Protocol types: Event, Hat, Topic, Error |
395
+ | `ralph-core` | Business logic: EventLoop, HatRegistry, Config |
396
+ | `ralph-adapters` | CLI backend integrations (Claude, Kiro, Gemini, etc.) |
397
+ | `ralph-tui` | Terminal UI with ratatui |
398
+ | `ralph-cli` | Binary entry point and CLI parsing |
399
+ | `ralph-bench` | Benchmarking harness (dev-only) |
400
+
401
+ ## Building & Testing
402
+
403
+ ### Build
404
+
405
+ ```bash
406
+ cargo build # Debug build
407
+ cargo build --release # Release build
408
+ ```
409
+
410
+ ### Test
411
+
412
+ ```bash
413
+ # Run all tests (includes smoke tests with JSONL replay)
414
+ cargo test
415
+
416
+ # Run smoke tests specifically
417
+ cargo test -p ralph-core smoke_runner
418
+
419
+ # Run Kiro-specific smoke tests
420
+ cargo test -p ralph-core kiro
421
+ ```
422
+
423
+ ### Smoke Tests
424
+
425
+ Smoke tests use recorded JSONL fixtures instead of live API calls — fast, free, and deterministic.
426
+
427
+ **Fixture locations:**
428
+ - `crates/ralph-core/tests/fixtures/basic_session.jsonl` — Claude CLI session
429
+ - `crates/ralph-core/tests/fixtures/kiro/` — Kiro CLI sessions
430
+
431
+ **Recording new fixtures:**
432
+
433
+ ```bash
434
+ # Record a session
435
+ ralph run -c ralph.yml --record-session session.jsonl -p "your prompt"
436
+
437
+ # Or capture raw CLI output
438
+ claude -p "your prompt" 2>&1 | tee output.txt
439
+ ```
440
+
441
+ ### Linting
442
+
443
+ ```bash
444
+ cargo clippy --all-targets --all-features
445
+ cargo fmt --check
446
+ ```
447
+
448
+ ## Contributing
449
+
450
+ Contributions are welcome! Please:
451
+
452
+ 1. Fork the repository
453
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
454
+ 3. Write tests for new functionality
455
+ 4. Ensure `cargo test` passes
456
+ 5. Run `cargo clippy` and `cargo fmt`
457
+ 6. Commit your changes (`git commit -m 'Add amazing feature'`)
458
+ 7. Push to the branch (`git push origin feature/amazing-feature`)
459
+ 8. Open a Pull Request
460
+
461
+ See [AGENTS.md](AGENTS.md) for development philosophy and conventions.
462
+
463
+ ## License
464
+
465
+ MIT License — See [LICENSE](LICENSE) for details.
466
+
467
+ ## Acknowledgments
468
+
469
+ - **[Geoffrey Huntley](https://ghuntley.com/ralph/)** — Creator of the Ralph Wiggum technique
470
+ - **[Harper Reed](https://harper.blog/)** — Spec-driven development methodology
471
+ - **[Strands Agent SOPs](https://github.com/strands-agents/agent-sop)** — Natural language workflows that enable AI agents to perform complex, multi-step tasks with consistency and reliability.
472
+ - **[ratatui](https://ratatui.rs/)** — Terminal UI framework
473
+ - **[portable-pty](https://crates.io/crates/portable-pty)** — Cross-platform PTY support
42
474
 
43
475
  ---
44
476
 
45
- **Maintained for OIDC setup purposes only**
477
+ *"I'm learnding!" - Ralph Wiggum*