You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add Mermaid diagrams to How It Works page for users who want to quickly understand the iteration lifecycle
Replace text-based ASCII diagrams with interactive Mermaid flowcharts
and sequence diagrams. Three diagrams added:
- Iteration lifecycle flowchart (color-coded by phase)
- Prompt assembly data-flow diagram
- Self-healing loop sequence diagram
Also enables Mermaid support in mkdocs.yml via pymdownx.superfences
custom fences.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/how-it-works.md
+80-22Lines changed: 80 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,44 @@ This page explains what ralphify does under the hood during each iteration, how
6
6
7
7
Each time the loop runs an iteration, ralphify follows these steps in order:
8
8
9
+
```mermaid
10
+
flowchart TD
11
+
A["📄 Read PROMPT.md from disk"] --> B["Run context commands"]
12
+
B --> C["Inject context output into prompt"]
13
+
C --> D["Inject instruction content"]
14
+
D --> E{"Check failures\nfrom previous\niteration?"}
15
+
E -- Yes --> F["Append failure output to prompt"]
16
+
E -- No --> G["🤖 Pipe assembled prompt\nto agent via stdin"]
17
+
F --> G
18
+
G --> H["Wait for agent to finish\n(or timeout)"]
19
+
H --> I["Run checks against\ncurrent project state"]
20
+
I --> J["Store check failures\nfor next iteration"]
21
+
J --> K{"More\niterations?"}
22
+
K -- Yes --> L{"Delay\nset?"}
23
+
K -- No --> M(["Print summary and exit"])
24
+
L -- Yes --> N["⏳ Wait --delay seconds"]
25
+
L -- No --> A
26
+
N --> A
27
+
28
+
style A fill:#7c4dff,color:#fff
29
+
style B fill:#7c4dff,color:#fff
30
+
style C fill:#7c4dff,color:#fff
31
+
style D fill:#7c4dff,color:#fff
32
+
style E fill:#7c4dff,color:#fff
33
+
style F fill:#7c4dff,color:#fff
34
+
style G fill:#00897b,color:#fff
35
+
style H fill:#00897b,color:#fff
36
+
style I fill:#1565c0,color:#fff
37
+
style J fill:#1565c0,color:#fff
9
38
```
10
-
1. Read PROMPT.md from disk
11
-
2. Run context commands and inject their output
12
-
3. Inject instruction content
13
-
4. Append check failures from the previous iteration
14
-
5. Pipe the assembled prompt to the agent via stdin
15
-
6. Wait for the agent to finish (or timeout)
16
-
7. Run checks against the current state of the project
17
-
8. Store any check failures for the next iteration
18
-
9. Wait (if --delay is set), then go to step 1
19
-
```
20
39
21
-
Steps 2-4 are the **prompt assembly** phase. Steps 5-6 are the **execution** phase. Steps 7-8 are the **validation** phase. The combination of validation and injection creates a self-healing feedback loop.
40
+
The lifecycle has three phases:
41
+
42
+
- :material-file-edit:{ .lg } **Prompt assembly** (purple) — read the prompt, resolve contexts and instructions, append check failures
43
+
- :material-play:{ .lg } **Execution** (green) — pipe the assembled prompt to the agent and wait
44
+
- :material-check-circle:{ .lg } **Validation** (blue) — run checks and store failures for the next iteration
45
+
46
+
The combination of validation and injection creates a self-healing feedback loop.
22
47
23
48
### What's fresh and what's fixed
24
49
@@ -44,6 +69,21 @@ This means:
44
69
45
70
Ralphify builds the final prompt in three layers, applied in this order:
46
71
72
+
```mermaid
73
+
flowchart LR
74
+
A["PROMPT.md"] --> B["1. Context\nresolution"]
75
+
B --> C["2. Instruction\nresolution"]
76
+
C --> D["3. Check failure\ninjection"]
77
+
D --> E["Assembled\nprompt"]
78
+
F[(".ralph/contexts/")] --> B
79
+
G[(".ralph/instructions/")] --> C
80
+
H["Previous iteration\nfailures"] --> D
81
+
E --> I["stdin → agent"]
82
+
83
+
style E fill:#00897b,color:#fff
84
+
style I fill:#00897b,color:#fff
85
+
```
86
+
47
87
### 1. Context resolution
48
88
49
89
For each enabled context, ralphify runs its command (if it has one) and combines the static content with the command output. Then it resolves placeholders in the prompt:
@@ -235,17 +275,35 @@ If a check fails, its output is stored and injected into the **next** iteration'
235
275
236
276
This is the core mechanism that makes autonomous loops productive:
237
277
238
-
```
239
-
Iteration N:
240
-
Agent makes a change → check fails (tests broken)
241
-
242
-
Iteration N+1:
243
-
Agent sees check failure output in prompt →
244
-
fixes the broken tests → checks pass
245
-
246
-
Iteration N+2:
247
-
No failures from previous iteration →
248
-
agent moves on to the next task
278
+
```mermaid
279
+
sequenceDiagram
280
+
participant P as Prompt
281
+
participant A as Agent
282
+
participant C as Checks
283
+
284
+
rect rgb(200, 230, 255)
285
+
note over P,C: Iteration N
286
+
P->>A: Assembled prompt (no failures)
287
+
A->>A: Makes a change
288
+
A->>C: Done — run checks
289
+
C-->>P: ✗ tests failed (output stored)
290
+
end
291
+
292
+
rect rgb(255, 245, 200)
293
+
note over P,C: Iteration N+1
294
+
P->>A: Prompt + check failure output
295
+
A->>A: Fixes the broken tests
296
+
A->>C: Done — run checks
297
+
C-->>P: ✓ All checks pass
298
+
end
299
+
300
+
rect rgb(200, 255, 200)
301
+
note over P,C: Iteration N+2
302
+
P->>A: Prompt (no failures)
303
+
A->>A: Moves on to the next task
304
+
A->>C: Done — run checks
305
+
C-->>P: ✓ All checks pass
306
+
end
249
307
```
250
308
251
309
The agent doesn't need to "remember" that it broke something. The check failure output tells it exactly what went wrong, and the failure instruction tells it how you want it handled.
0 commit comments