@ralph-orchestrator/ralph-cli 2.1.3 → 2.2.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/README.md +542 -9
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://www.rust-lang.org/)
|
|
5
5
|
[](https://github.com/mikeyobrien/ralph-orchestrator/actions)
|
|
6
|
+
[](coverage/index.html)
|
|
6
7
|
[](https://github.com/hesreallyhim/awesome-claude-code)
|
|
7
8
|
|
|
8
9
|
|
|
@@ -23,8 +24,10 @@ v1.0.0 was ralphed into existence with little oversight and guidance. v2.0.0 is
|
|
|
23
24
|
- [Installation](#installation)
|
|
24
25
|
- [Quick Start](#quick-start)
|
|
25
26
|
- [Configuration](#configuration)
|
|
27
|
+
- [Custom Backends and Per-Hat Configuration](#custom-backends-and-per-hat-configuration)
|
|
26
28
|
- [Presets](#presets)
|
|
27
29
|
- [Key Concepts](#key-concepts)
|
|
30
|
+
- [Orchestration and Coordination Patterns](#orchestration-and-coordination-patterns)
|
|
28
31
|
- [CLI Reference](#cli-reference)
|
|
29
32
|
- [Architecture](#architecture)
|
|
30
33
|
- [Building & Testing](#building--testing)
|
|
@@ -69,7 +72,9 @@ See [AGENTS.md](AGENTS.md) for the full philosophy.
|
|
|
69
72
|
- **Event-Driven Coordination** — Hats communicate through typed events with glob pattern matching
|
|
70
73
|
- **Backpressure Enforcement** — Gates that reject incomplete work (tests, lint, typecheck)
|
|
71
74
|
- **Presets Library** — 20+ pre-configured workflows for common development patterns
|
|
72
|
-
- **Interactive TUI** — Real-time terminal UI for monitoring Ralph's activity (
|
|
75
|
+
- **Interactive TUI** — Real-time terminal UI for monitoring Ralph's activity (enabled by default)
|
|
76
|
+
- **Memories** — Persistent learning across sessions stored in `.agent/memories.md`
|
|
77
|
+
- **Tasks** — Runtime work tracking stored in `.agent/tasks.jsonl`
|
|
73
78
|
- **Session Recording** — Record and replay sessions for debugging and testing (experimental)
|
|
74
79
|
|
|
75
80
|
## Installation
|
|
@@ -195,17 +200,17 @@ ralph run -p "Add input validation to the user API endpoints"
|
|
|
195
200
|
### 3. Run Ralph
|
|
196
201
|
|
|
197
202
|
```bash
|
|
198
|
-
#
|
|
203
|
+
# TUI mode (default) — real-time terminal UI for monitoring
|
|
199
204
|
ralph run
|
|
200
205
|
|
|
201
206
|
# With inline prompt
|
|
202
207
|
ralph run -p "Implement the login endpoint with JWT authentication"
|
|
203
208
|
|
|
204
|
-
#
|
|
205
|
-
ralph run --tui
|
|
209
|
+
# Headless mode (no TUI)
|
|
210
|
+
ralph run --no-tui
|
|
206
211
|
|
|
207
212
|
# Resume interrupted session
|
|
208
|
-
ralph
|
|
213
|
+
ralph run --continue
|
|
209
214
|
|
|
210
215
|
# Dry run (show what would execute)
|
|
211
216
|
ralph run --dry-run
|
|
@@ -303,6 +308,15 @@ core:
|
|
|
303
308
|
- "Don't assume 'not implemented' - search first"
|
|
304
309
|
- "Backpressure is law - tests/typecheck/lint must pass"
|
|
305
310
|
|
|
311
|
+
# Memories — persistent learning across sessions (enabled by default)
|
|
312
|
+
memories:
|
|
313
|
+
enabled: true # Set false to disable
|
|
314
|
+
inject: auto # auto, manual, or none
|
|
315
|
+
|
|
316
|
+
# Tasks — runtime work tracking (enabled by default)
|
|
317
|
+
tasks:
|
|
318
|
+
enabled: true # Set false to use scratchpad-only mode
|
|
319
|
+
|
|
306
320
|
# Custom hats (omit to use default planner/builder)
|
|
307
321
|
hats:
|
|
308
322
|
my_hat:
|
|
@@ -314,6 +328,81 @@ hats:
|
|
|
314
328
|
```
|
|
315
329
|
|
|
316
330
|
|
|
331
|
+
## Custom Backends and Per-Hat Configuration
|
|
332
|
+
|
|
333
|
+
### Custom Backends
|
|
334
|
+
|
|
335
|
+
Beyond the built-in backends (Claude, Kiro, Gemini, Codex, Amp, Copilot, OpenCode), you can define custom backends to integrate any CLI-based AI agent:
|
|
336
|
+
|
|
337
|
+
```yaml
|
|
338
|
+
cli:
|
|
339
|
+
backend: "custom"
|
|
340
|
+
command: "my-agent"
|
|
341
|
+
args: ["--headless", "--auto-approve"]
|
|
342
|
+
prompt_mode: "arg" # "arg" or "stdin"
|
|
343
|
+
prompt_flag: "-p" # Optional: flag for prompt argument
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
| Field | Description |
|
|
347
|
+
|-------|-------------|
|
|
348
|
+
| `command` | The CLI command to execute |
|
|
349
|
+
| `args` | Arguments inserted before the prompt |
|
|
350
|
+
| `prompt_mode` | How to pass the prompt: `arg` (command-line argument) or `stdin` |
|
|
351
|
+
| `prompt_flag` | Flag preceding the prompt (e.g., `-p`, `--prompt`). If omitted, prompt is positional. |
|
|
352
|
+
|
|
353
|
+
### Per-Hat Backend Configuration
|
|
354
|
+
|
|
355
|
+
Different hats can use different backends, enabling specialized tools for specialized tasks:
|
|
356
|
+
|
|
357
|
+
```yaml
|
|
358
|
+
cli:
|
|
359
|
+
backend: "claude" # Default for Ralph and hats without explicit backend
|
|
360
|
+
|
|
361
|
+
hats:
|
|
362
|
+
builder:
|
|
363
|
+
name: "🔨 Builder"
|
|
364
|
+
description: "Implements code"
|
|
365
|
+
triggers: ["build.task"]
|
|
366
|
+
publishes: ["build.done"]
|
|
367
|
+
backend: "claude" # Explicit: Claude for coding
|
|
368
|
+
|
|
369
|
+
researcher:
|
|
370
|
+
name: "🔍 Researcher"
|
|
371
|
+
description: "Researches technical questions"
|
|
372
|
+
triggers: ["research.task"]
|
|
373
|
+
publishes: ["research.done"]
|
|
374
|
+
backend: # Kiro with custom agent (has MCP tools)
|
|
375
|
+
type: "kiro"
|
|
376
|
+
agent: "researcher"
|
|
377
|
+
|
|
378
|
+
reviewer:
|
|
379
|
+
name: "👀 Reviewer"
|
|
380
|
+
description: "Reviews code changes"
|
|
381
|
+
triggers: ["review.task"]
|
|
382
|
+
publishes: ["review.done"]
|
|
383
|
+
backend: "gemini" # Different model for fresh perspective
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Backend Types:**
|
|
387
|
+
|
|
388
|
+
| Type | Syntax | Invocation |
|
|
389
|
+
|------|--------|------------|
|
|
390
|
+
| Named | `backend: "claude"` | Uses standard backend configuration |
|
|
391
|
+
| Kiro Agent | `backend: { type: "kiro", agent: "builder" }` | `kiro-cli --agent builder ...` |
|
|
392
|
+
| Custom | `backend: { command: "...", args: [...] }` | Your custom command |
|
|
393
|
+
|
|
394
|
+
**When to mix backends:**
|
|
395
|
+
|
|
396
|
+
| Scenario | Recommended Backend |
|
|
397
|
+
|----------|---------------------|
|
|
398
|
+
| Complex coding | Claude (best reasoning) |
|
|
399
|
+
| AWS/cloud tasks | Kiro with agent (MCP tools) |
|
|
400
|
+
| Code review | Different model (fresh perspective) |
|
|
401
|
+
| Internal tools | Custom backend |
|
|
402
|
+
| Cost optimization | Faster/cheaper model for simple tasks |
|
|
403
|
+
|
|
404
|
+
Hats without explicit `backend` inherit from `cli.backend`.
|
|
405
|
+
|
|
317
406
|
## Presets
|
|
318
407
|
|
|
319
408
|
Presets are pre-configured workflows for common development patterns.
|
|
@@ -396,9 +485,430 @@ View event history:
|
|
|
396
485
|
ralph events
|
|
397
486
|
```
|
|
398
487
|
|
|
399
|
-
|
|
488
|
+
## Orchestration and Coordination Patterns
|
|
489
|
+
|
|
490
|
+
Ralph's hat system enables sophisticated multi-agent workflows through event-driven coordination. This section covers the architectural patterns, event routing mechanics, and built-in workflow templates.
|
|
491
|
+
|
|
492
|
+
### How Hat-Based Orchestration Works
|
|
493
|
+
|
|
494
|
+
#### The Event-Driven Model
|
|
495
|
+
|
|
496
|
+
Hats communicate through a **pub/sub event system**:
|
|
497
|
+
|
|
498
|
+
1. **Ralph publishes a starting event** (e.g., `task.start`)
|
|
499
|
+
2. **The matching hat activates** — the hat subscribed to that event takes over
|
|
500
|
+
3. **The hat does its work** and publishes an event when done
|
|
501
|
+
4. **The next hat activates** — triggered by the new event
|
|
502
|
+
5. **The cycle continues** until a termination event or `LOOP_COMPLETE`
|
|
503
|
+
|
|
504
|
+
```
|
|
505
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
506
|
+
│ task.start → [Test Writer] → test.written → [Implementer] → │
|
|
507
|
+
│ test.passing → [Refactorer] → refactor.done ──┐ │
|
|
508
|
+
│ │ │
|
|
509
|
+
│ ┌─────────────────────────────────────────────┘ │
|
|
510
|
+
│ └──→ (loops back to Test Writer for next test) │
|
|
511
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
#### Ralph as the Constant Coordinator
|
|
515
|
+
|
|
516
|
+
In hat-based mode, **Ralph is always present**:
|
|
517
|
+
|
|
518
|
+
- Ralph cannot be removed or replaced
|
|
519
|
+
- Custom hats define the **topology** (who triggers whom)
|
|
520
|
+
- Ralph executes with **topology awareness** — knowing which hats exist and their relationships
|
|
521
|
+
- Ralph serves as the **universal fallback** — orphaned events automatically route to Ralph
|
|
522
|
+
|
|
523
|
+
This means custom hats don't execute directly. Instead, Ralph reads all pending events across all hats and decides what to do based on the defined topology. Ralph then either:
|
|
524
|
+
- Delegates to the appropriate hat by publishing an event
|
|
525
|
+
- Handles the work directly if no hat is suited
|
|
526
|
+
|
|
527
|
+
#### Event Routing and Topic Matching
|
|
528
|
+
|
|
529
|
+
Events route to hats using **glob-style pattern matching**:
|
|
530
|
+
|
|
531
|
+
| Pattern | Matches |
|
|
532
|
+
|---------|---------|
|
|
533
|
+
| `task.start` | Exactly `task.start` |
|
|
534
|
+
| `build.*` | `build.done`, `build.blocked`, `build.task`, etc. |
|
|
535
|
+
| `*.done` | `build.done`, `review.done`, `test.done`, etc. |
|
|
536
|
+
| `*` | Everything (global wildcard — used by Ralph as fallback) |
|
|
537
|
+
|
|
538
|
+
**Priority Rules:**
|
|
539
|
+
- Specific patterns take precedence over wildcards
|
|
540
|
+
- If multiple hats have specific subscriptions, that's an error (ambiguous routing)
|
|
541
|
+
- Global wildcard (`*`) only triggers if no specific handler exists
|
|
542
|
+
|
|
543
|
+
### Coordination Patterns
|
|
544
|
+
|
|
545
|
+
Ralph presets implement several proven coordination patterns:
|
|
546
|
+
|
|
547
|
+
#### 1. Linear Pipeline
|
|
548
|
+
|
|
549
|
+
The simplest pattern — work flows through a sequence of specialists.
|
|
550
|
+
|
|
551
|
+
```
|
|
552
|
+
Input → Hat A → Event → Hat B → Event → Hat C → Output
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
**Example: TDD Red-Green-Refactor** (`tdd-red-green.yml`)
|
|
556
|
+
|
|
557
|
+
```yaml
|
|
558
|
+
hats:
|
|
559
|
+
test_writer:
|
|
560
|
+
triggers: ["tdd.start", "refactor.done"]
|
|
561
|
+
publishes: ["test.written"]
|
|
562
|
+
|
|
563
|
+
implementer:
|
|
564
|
+
triggers: ["test.written"]
|
|
565
|
+
publishes: ["test.passing"]
|
|
566
|
+
|
|
567
|
+
refactorer:
|
|
568
|
+
triggers: ["test.passing"]
|
|
569
|
+
publishes: ["refactor.done", "cycle.complete"]
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
```
|
|
573
|
+
tdd.start → 🔴 Test Writer → test.written → 🟢 Implementer →
|
|
574
|
+
test.passing → 🔵 Refactorer → refactor.done ─┐
|
|
575
|
+
│
|
|
576
|
+
┌───────────────────────────────┘
|
|
577
|
+
└──→ (back to Test Writer)
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
**When to use:** Workflows with clear sequential phases where each step builds on the previous.
|
|
581
|
+
|
|
582
|
+
#### 2. Contract-First Pipeline
|
|
583
|
+
|
|
584
|
+
A variant where work must pass validation gates before proceeding.
|
|
585
|
+
|
|
586
|
+
**Example: Spec-Driven Development** (`spec-driven.yml`)
|
|
587
|
+
|
|
588
|
+
```yaml
|
|
589
|
+
hats:
|
|
590
|
+
spec_writer:
|
|
591
|
+
triggers: ["spec.start", "spec.rejected"]
|
|
592
|
+
publishes: ["spec.ready"]
|
|
593
|
+
|
|
594
|
+
spec_reviewer:
|
|
595
|
+
triggers: ["spec.ready"]
|
|
596
|
+
publishes: ["spec.approved", "spec.rejected"]
|
|
597
|
+
|
|
598
|
+
implementer:
|
|
599
|
+
triggers: ["spec.approved", "spec.violated"]
|
|
600
|
+
publishes: ["implementation.done"]
|
|
601
|
+
|
|
602
|
+
verifier:
|
|
603
|
+
triggers: ["implementation.done"]
|
|
604
|
+
publishes: ["task.complete", "spec.violated"]
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
```
|
|
608
|
+
spec.start → 📋 Spec Writer ──→ spec.ready ──→ 🔎 Spec Critic
|
|
609
|
+
↑ │
|
|
610
|
+
└────── spec.rejected ──────────────┤
|
|
611
|
+
↓
|
|
612
|
+
spec.approved
|
|
613
|
+
│
|
|
614
|
+
↓
|
|
615
|
+
task.complete ←── ✅ Verifier ←── impl.done ←── ⚙️ Implementer
|
|
616
|
+
│ ↑
|
|
617
|
+
└──── spec.violated ───────────┘
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
**When to use:** High-stakes changes where the spec must be rock-solid before implementation begins.
|
|
621
|
+
|
|
622
|
+
#### 3. Cyclic Rotation
|
|
623
|
+
|
|
624
|
+
Multiple roles take turns, each bringing a different perspective.
|
|
625
|
+
|
|
626
|
+
**Example: Mob Programming** (`mob-programming.yml`)
|
|
627
|
+
|
|
628
|
+
```yaml
|
|
629
|
+
hats:
|
|
630
|
+
navigator:
|
|
631
|
+
triggers: ["mob.start", "observation.noted"]
|
|
632
|
+
publishes: ["direction.set", "mob.complete"]
|
|
633
|
+
|
|
634
|
+
driver:
|
|
635
|
+
triggers: ["direction.set"]
|
|
636
|
+
publishes: ["code.written"]
|
|
637
|
+
|
|
638
|
+
observer:
|
|
639
|
+
triggers: ["code.written"]
|
|
640
|
+
publishes: ["observation.noted"]
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
```
|
|
644
|
+
mob.start → 🧭 Navigator → direction.set → ⌨️ Driver →
|
|
645
|
+
code.written → 👁️ Observer → observation.noted ─┐
|
|
646
|
+
│
|
|
647
|
+
┌─────────────────────────────────┘
|
|
648
|
+
└──→ (back to Navigator)
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
**When to use:** Complex features that benefit from multiple perspectives and continuous feedback.
|
|
652
|
+
|
|
653
|
+
#### 4. Adversarial Review
|
|
654
|
+
|
|
655
|
+
Two roles with opposing objectives ensure robustness.
|
|
656
|
+
|
|
657
|
+
**Example: Red Team / Blue Team** (`adversarial-review.yml`)
|
|
658
|
+
|
|
659
|
+
```yaml
|
|
660
|
+
hats:
|
|
661
|
+
builder:
|
|
662
|
+
name: "🔵 Blue Team (Builder)"
|
|
663
|
+
triggers: ["security.review", "fix.applied"]
|
|
664
|
+
publishes: ["build.ready"]
|
|
665
|
+
|
|
666
|
+
red_team:
|
|
667
|
+
name: "🔴 Red Team (Attacker)"
|
|
668
|
+
triggers: ["build.ready"]
|
|
669
|
+
publishes: ["vulnerability.found", "security.approved"]
|
|
670
|
+
|
|
671
|
+
fixer:
|
|
672
|
+
triggers: ["vulnerability.found"]
|
|
673
|
+
publishes: ["fix.applied"]
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
```
|
|
677
|
+
security.review → 🔵 Blue Team → build.ready → 🔴 Red Team
|
|
678
|
+
↑ │
|
|
679
|
+
│ ├─→ security.approved ✓
|
|
680
|
+
│ │
|
|
681
|
+
│ └─→ vulnerability.found
|
|
682
|
+
│ │
|
|
683
|
+
└────── fix.applied ←── 🛡️ Fixer ←──────┘
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
**When to use:** Security-sensitive code, authentication systems, or any code where adversarial thinking improves quality.
|
|
687
|
+
|
|
688
|
+
#### 5. Hypothesis-Driven Investigation
|
|
689
|
+
|
|
690
|
+
The scientific method applied to debugging.
|
|
691
|
+
|
|
692
|
+
**Example: Scientific Method** (`scientific-method.yml`)
|
|
693
|
+
|
|
694
|
+
```yaml
|
|
695
|
+
hats:
|
|
696
|
+
observer:
|
|
697
|
+
triggers: ["science.start", "hypothesis.rejected"]
|
|
698
|
+
publishes: ["observation.made"]
|
|
699
|
+
|
|
700
|
+
theorist:
|
|
701
|
+
triggers: ["observation.made"]
|
|
702
|
+
publishes: ["hypothesis.formed"]
|
|
703
|
+
|
|
704
|
+
experimenter:
|
|
705
|
+
triggers: ["hypothesis.formed"]
|
|
706
|
+
publishes: ["hypothesis.confirmed", "hypothesis.rejected"]
|
|
707
|
+
|
|
708
|
+
fixer:
|
|
709
|
+
triggers: ["hypothesis.confirmed"]
|
|
710
|
+
publishes: ["fix.applied"]
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
```
|
|
714
|
+
science.start → 🔬 Observer → observation.made → 🧠 Theorist →
|
|
715
|
+
hypothesis.formed → 🧪 Experimenter ──┬─→ hypothesis.confirmed → 🔧 Fixer
|
|
716
|
+
│
|
|
717
|
+
└─→ hypothesis.rejected ─┐
|
|
718
|
+
│
|
|
719
|
+
┌────────────────────────────────────────────────┘
|
|
720
|
+
└──→ (back to Observer with new data)
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
**When to use:** Complex bugs where the root cause isn't obvious. Forces systematic investigation over random fixes.
|
|
724
|
+
|
|
725
|
+
#### 6. Coordinator-Specialist (Fan-Out)
|
|
726
|
+
|
|
727
|
+
A coordinator delegates to specialists based on the work type.
|
|
728
|
+
|
|
729
|
+
**Example: Gap Analysis** (`gap-analysis.yml`)
|
|
730
|
+
|
|
731
|
+
```yaml
|
|
732
|
+
hats:
|
|
733
|
+
analyzer:
|
|
734
|
+
triggers: ["gap.start", "verify.complete", "report.complete"]
|
|
735
|
+
publishes: ["analyze.spec", "verify.request", "report.request"]
|
|
736
|
+
|
|
737
|
+
verifier:
|
|
738
|
+
triggers: ["analyze.spec", "verify.request"]
|
|
739
|
+
publishes: ["verify.complete"]
|
|
740
|
+
|
|
741
|
+
reporter:
|
|
742
|
+
triggers: ["report.request"]
|
|
743
|
+
publishes: ["report.complete"]
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
```
|
|
747
|
+
┌─→ analyze.spec ──→ 🔍 Verifier ──┐
|
|
748
|
+
│ │
|
|
749
|
+
gap.start → 📊 Analyzer ←── verify.complete ──────────┘
|
|
750
|
+
│
|
|
751
|
+
└─→ report.request ──→ 📝 Reporter ──→ report.complete
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
**When to use:** Work that naturally decomposes into independent specialist tasks (analysis, verification, reporting).
|
|
755
|
+
|
|
756
|
+
#### 7. Adaptive Entry Point
|
|
757
|
+
|
|
758
|
+
A bootstrapping hat detects input type and routes to the appropriate workflow.
|
|
759
|
+
|
|
760
|
+
**Example: Code-Assist** (`code-assist.yml`)
|
|
761
|
+
|
|
762
|
+
```yaml
|
|
763
|
+
hats:
|
|
764
|
+
planner:
|
|
765
|
+
triggers: ["build.start"]
|
|
766
|
+
publishes: ["tasks.ready"]
|
|
767
|
+
# Detects: PDD directory vs. code task file vs. description
|
|
768
|
+
|
|
769
|
+
builder:
|
|
770
|
+
triggers: ["tasks.ready", "validation.failed", "task.complete"]
|
|
771
|
+
publishes: ["implementation.ready", "task.complete"]
|
|
772
|
+
|
|
773
|
+
validator:
|
|
774
|
+
triggers: ["implementation.ready"]
|
|
775
|
+
publishes: ["validation.passed", "validation.failed"]
|
|
776
|
+
|
|
777
|
+
committer:
|
|
778
|
+
triggers: ["validation.passed"]
|
|
779
|
+
publishes: ["commit.complete"]
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
```
|
|
783
|
+
build.start → 📋 Planner ─── (detects input type) ───→ tasks.ready
|
|
784
|
+
│
|
|
785
|
+
┌───────────────────────────────────────────────────────┘
|
|
786
|
+
│
|
|
787
|
+
↓
|
|
788
|
+
⚙️ Builder ←─────────────── validation.failed ←─────┐
|
|
789
|
+
│ │
|
|
790
|
+
├── task.complete ──→ (loop for PDD mode) ──────┤
|
|
791
|
+
│ │
|
|
792
|
+
└── implementation.ready ──→ ✅ Validator ──────┤
|
|
793
|
+
│ │
|
|
794
|
+
└─→ validation.passed
|
|
795
|
+
│
|
|
796
|
+
↓
|
|
797
|
+
📦 Committer → commit.complete
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
**When to use:** Workflows that need to handle multiple input formats or adapt their behavior based on context.
|
|
801
|
+
|
|
802
|
+
### Designing Custom Hat Collections
|
|
803
|
+
|
|
804
|
+
#### Hat Configuration Schema
|
|
805
|
+
|
|
806
|
+
```yaml
|
|
807
|
+
hats:
|
|
808
|
+
my_hat:
|
|
809
|
+
name: "🎯 Display Name" # Shown in TUI and logs
|
|
810
|
+
description: "What this hat does" # REQUIRED — Ralph uses this for delegation
|
|
811
|
+
triggers: ["event.a", "event.b"] # Events that activate this hat
|
|
812
|
+
publishes: ["event.c", "event.d"] # Events this hat can emit
|
|
813
|
+
default_publishes: "event.c" # Fallback if hat forgets to emit
|
|
814
|
+
max_activations: 10 # Optional cap on activations
|
|
815
|
+
backend: "claude" # Optional backend override
|
|
816
|
+
instructions: |
|
|
817
|
+
Prompt injected when this hat is active.
|
|
818
|
+
Tell the hat what to do, not how to do it.
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
#### Design Principles
|
|
822
|
+
|
|
823
|
+
1. **Description is critical** — Ralph uses hat descriptions to decide when to delegate. Make them clear and specific.
|
|
824
|
+
|
|
825
|
+
2. **One hat, one responsibility** — Each hat should have a clear, focused purpose. If you're writing "and" in the description, consider splitting.
|
|
826
|
+
|
|
827
|
+
3. **Events are routing signals, not data** — Keep payloads brief. Store detailed output in files and reference them in events.
|
|
828
|
+
|
|
829
|
+
4. **Design for recovery** — If a hat fails or forgets to publish, Ralph catches the orphaned event. Your topology should handle unexpected states gracefully.
|
|
830
|
+
|
|
831
|
+
5. **Test with simple prompts first** — Complex topologies can have emergent behavior. Start simple, validate the flow, then add complexity.
|
|
400
832
|
|
|
401
|
-
|
|
833
|
+
#### Validation Rules
|
|
834
|
+
|
|
835
|
+
Ralph validates hat configurations:
|
|
836
|
+
|
|
837
|
+
- **Required description**: Every hat must have a description (Ralph needs it for delegation context)
|
|
838
|
+
- **Reserved triggers**: `task.start` and `task.resume` are reserved for Ralph
|
|
839
|
+
- **No ambiguous routing**: Each trigger pattern must map to exactly one hat
|
|
840
|
+
|
|
841
|
+
```
|
|
842
|
+
ERROR: Ambiguous routing for trigger 'build.done'.
|
|
843
|
+
Both 'planner' and 'reviewer' trigger on 'build.done'.
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
### Event Emission
|
|
847
|
+
|
|
848
|
+
Hats emit events to signal completion or hand off work:
|
|
849
|
+
|
|
850
|
+
```bash
|
|
851
|
+
# Simple event with payload
|
|
852
|
+
ralph emit "build.done" "tests: pass, lint: pass"
|
|
853
|
+
|
|
854
|
+
# Event with JSON payload
|
|
855
|
+
ralph emit "review.done" --json '{"status": "approved", "issues": 0}'
|
|
856
|
+
|
|
857
|
+
# Direct handoff to specific hat (bypasses routing)
|
|
858
|
+
ralph emit "handoff" --target reviewer "Please review the changes"
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
**In agent output**, events are embedded as XML tags:
|
|
862
|
+
|
|
863
|
+
```xml
|
|
864
|
+
<event topic="impl.done">Implementation complete</event>
|
|
865
|
+
<event topic="handoff" target="reviewer">Please review</event>
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
### Choosing a Pattern
|
|
869
|
+
|
|
870
|
+
| Scenario | Recommended Pattern | Preset |
|
|
871
|
+
|----------|---------------------|--------|
|
|
872
|
+
| Sequential workflow with clear phases | Linear Pipeline | `tdd-red-green` |
|
|
873
|
+
| Spec must be approved before coding | Contract-First | `spec-driven` |
|
|
874
|
+
| Need multiple perspectives | Cyclic Rotation | `mob-programming` |
|
|
875
|
+
| Security review required | Adversarial | `adversarial-review` |
|
|
876
|
+
| Debugging complex issues | Hypothesis-Driven | `scientific-method` |
|
|
877
|
+
| Work decomposes into specialist tasks | Coordinator-Specialist | `gap-analysis` |
|
|
878
|
+
| Multiple input formats | Adaptive Entry | `code-assist` |
|
|
879
|
+
| Standard feature development | Basic delegation | `feature` |
|
|
880
|
+
|
|
881
|
+
### When Not to Use Hats
|
|
882
|
+
|
|
883
|
+
Hat-based orchestration adds complexity. Use **traditional mode** (no hats) when:
|
|
884
|
+
|
|
885
|
+
- The task is straightforward and single-focused
|
|
886
|
+
- You don't need role separation or handoffs
|
|
887
|
+
- You're prototyping and want minimal configuration
|
|
888
|
+
- The work doesn't naturally decompose into distinct phases
|
|
889
|
+
|
|
890
|
+
Traditional mode is just Ralph in a loop until completion — simpler, faster to set up, and often sufficient.
|
|
891
|
+
|
|
892
|
+
### Memories and Tasks
|
|
893
|
+
|
|
894
|
+
Ralph uses two complementary systems for persistent state (both enabled by default):
|
|
895
|
+
|
|
896
|
+
**Memories** (`.agent/memories.md`) — Accumulated wisdom across sessions:
|
|
897
|
+
- Codebase patterns and conventions discovered
|
|
898
|
+
- Architectural decisions and rationale
|
|
899
|
+
- Recurring problem solutions (fixes)
|
|
900
|
+
- Project-specific context
|
|
901
|
+
|
|
902
|
+
**Tasks** (`.agent/tasks.jsonl`) — Runtime work tracking:
|
|
903
|
+
- Create, list, and close tasks during orchestration
|
|
904
|
+
- Track dependencies between tasks
|
|
905
|
+
- Used for loop completion verification
|
|
906
|
+
|
|
907
|
+
When memories and tasks are enabled, they replace the scratchpad for state management. Set `memories.enabled: false` and `tasks.enabled: false` to use the legacy scratchpad-only mode.
|
|
908
|
+
|
|
909
|
+
### Scratchpad (Legacy Mode)
|
|
910
|
+
|
|
911
|
+
When memories/tasks are disabled, all hats share `.agent/scratchpad.md` — persistent memory across iterations. This enables hats to build on previous work rather than starting fresh.
|
|
402
912
|
|
|
403
913
|
The scratchpad is the primary mechanism for:
|
|
404
914
|
- Task tracking (with `[ ]`, `[x]`, `[~]` markers)
|
|
@@ -427,6 +937,7 @@ tests: pass, lint: pass, typecheck: pass
|
|
|
427
937
|
| `ralph init` | Initialize configuration file |
|
|
428
938
|
| `ralph clean` | Clean up `.agent/` directory |
|
|
429
939
|
| `ralph emit` | Emit an event to the event log |
|
|
940
|
+
| `ralph tools` | Runtime tools for memories and tasks (agent-facing) |
|
|
430
941
|
|
|
431
942
|
### Global Options
|
|
432
943
|
|
|
@@ -445,11 +956,12 @@ tests: pass, lint: pass, typecheck: pass
|
|
|
445
956
|
| `--max-iterations <N>` | Override max iterations |
|
|
446
957
|
| `--completion-promise <TEXT>` | Override completion trigger |
|
|
447
958
|
| `--dry-run` | Show what would execute |
|
|
448
|
-
| `--tui` |
|
|
959
|
+
| `--no-tui` | Disable TUI mode (TUI is enabled by default) |
|
|
449
960
|
| `-a, --autonomous` | Force headless mode |
|
|
450
961
|
| `--idle-timeout <SECS>` | TUI idle timeout (default: 30) |
|
|
451
962
|
| `--record-session <FILE>` | Record session to JSONL |
|
|
452
963
|
| `-q, --quiet` | Suppress output (for CI) |
|
|
964
|
+
| `--continue` | Resume from existing scratchpad |
|
|
453
965
|
|
|
454
966
|
### `ralph init` Options
|
|
455
967
|
|
|
@@ -474,9 +986,29 @@ tests: pass, lint: pass, typecheck: pass
|
|
|
474
986
|
| `<INPUT>` | Optional description text or path to PDD plan file |
|
|
475
987
|
| `-b, --backend <BACKEND>` | Backend to use (overrides config and auto-detection) |
|
|
476
988
|
|
|
989
|
+
### `ralph tools` Subcommands
|
|
990
|
+
|
|
991
|
+
The `tools` command provides agent-facing utilities for runtime state management:
|
|
992
|
+
|
|
993
|
+
```bash
|
|
994
|
+
# Memory management (persistent learning)
|
|
995
|
+
ralph tools memory add "content" -t pattern --tags tag1,tag2
|
|
996
|
+
ralph tools memory search "query"
|
|
997
|
+
ralph tools memory list
|
|
998
|
+
ralph tools memory show <id>
|
|
999
|
+
ralph tools memory delete <id>
|
|
1000
|
+
|
|
1001
|
+
# Task management (runtime tracking)
|
|
1002
|
+
ralph tools task add "Title" -p 2 # Create task (priority 1-5)
|
|
1003
|
+
ralph tools task add "X" --blocked-by Y # With dependency
|
|
1004
|
+
ralph tools task list # All tasks
|
|
1005
|
+
ralph tools task ready # Unblocked tasks only
|
|
1006
|
+
ralph tools task close <id> # Mark complete
|
|
1007
|
+
```
|
|
1008
|
+
|
|
477
1009
|
## Architecture
|
|
478
1010
|
|
|
479
|
-
Ralph is organized as a Cargo workspace with
|
|
1011
|
+
Ralph is organized as a Cargo workspace with seven crates:
|
|
480
1012
|
|
|
481
1013
|
| Crate | Purpose |
|
|
482
1014
|
|-------|---------|
|
|
@@ -485,6 +1017,7 @@ Ralph is organized as a Cargo workspace with six crates:
|
|
|
485
1017
|
| `ralph-adapters` | CLI backend integrations (Claude, Kiro, Gemini, etc.) |
|
|
486
1018
|
| `ralph-tui` | Terminal UI with ratatui |
|
|
487
1019
|
| `ralph-cli` | Binary entry point and CLI parsing |
|
|
1020
|
+
| `ralph-e2e` | End-to-end test harness for backend validation |
|
|
488
1021
|
| `ralph-bench` | Benchmarking harness (dev-only) |
|
|
489
1022
|
|
|
490
1023
|
## Building & Testing
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"hasInstallScript": true,
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"name": "@ralph-orchestrator/ralph-cli",
|
|
26
|
-
"version": "2.1
|
|
26
|
+
"version": "2.2.1"
|
|
27
27
|
},
|
|
28
28
|
"node_modules/@isaacs/balanced-match": {
|
|
29
29
|
"engines": {
|
|
@@ -515,5 +515,5 @@
|
|
|
515
515
|
}
|
|
516
516
|
},
|
|
517
517
|
"requires": true,
|
|
518
|
-
"version": "2.1
|
|
518
|
+
"version": "2.2.1"
|
|
519
519
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"artifactDownloadUrl": "https://github.com/mikeyobrien/ralph-orchestrator/releases/download/v2.1
|
|
2
|
+
"artifactDownloadUrl": "https://github.com/mikeyobrien/ralph-orchestrator/releases/download/v2.2.1",
|
|
3
3
|
"bin": {
|
|
4
4
|
"ralph": "run-ralph.js"
|
|
5
5
|
},
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"zipExt": ".tar.xz"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
-
"version": "2.1
|
|
65
|
+
"version": "2.2.1",
|
|
66
66
|
"volta": {
|
|
67
67
|
"node": "18.14.1",
|
|
68
68
|
"npm": "9.5.0"
|