Skip to content

Commit 84f3b87

Browse files
malpouRalphify
authored andcommitted
docs: document context placeholders for name, iteration, and max_iterations
Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 26a7989 commit 84f3b87

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

docs/changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ keywords: ralphify changelog, release history, new features, version updates, br
88

99
All notable changes to ralphify are documented here.
1010

11+
## 0.2.5 — 2026-03-22
12+
13+
### Added
14+
15+
- **Context placeholders** — ralphs can now access runtime metadata via `{{ context.name }}` (ralph directory name), `{{ context.iteration }}` (current iteration, 1-based), and `{{ context.max_iterations }}` (total iterations if `-n` was set, empty otherwise). No frontmatter configuration needed.
16+
17+
---
18+
1119
## 0.2.4 — 2026-03-22
1220

1321
### Fixed

docs/contributing/codebase-map.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ src/ralphify/ # All source code
2222
├── cli.py # CLI commands (run, new, init) — delegates to engine for the loop
2323
├── engine.py # Core run loop orchestration with structured event emission
2424
├── manager.py # Multi-run orchestration (concurrent runs via threads)
25-
├── _resolver.py # Template placeholder resolution ({{ commands.* }}, {{ args.* }})
25+
├── _resolver.py # Template placeholder resolution ({{ commands.* }}, {{ args.* }}, {{ context.* }})
2626
├── _agent.py # Run agent subprocesses (streaming + blocking modes, log writing)
2727
├── _run_types.py # RunConfig, RunState, RunStatus, Command — shared data types
2828
├── _runner.py # Execute shell commands with timeout and capture output

docs/quick-reference.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,24 @@ Your instructions here. Use {{ args.dir }} for user arguments.
107107
- `--` ends flag parsing: `ralph run my-ralph -- --verbose ./src` treats `--verbose` as a positional value
108108
- Missing args resolve to empty string
109109

110+
### Context placeholders
111+
112+
```markdown
113+
{{ context.name }} # Ralph directory name (e.g. "my-ralph")
114+
{{ context.iteration }} # Current iteration number (1-based)
115+
{{ context.max_iterations }} # Total iterations if -n was set, empty otherwise
116+
```
117+
118+
- Automatically available — no frontmatter configuration needed
119+
- Useful for progress tracking, naming logs, or adjusting behavior near the end of a run
120+
110121
## The loop
111122

112123
Each iteration:
113124

114125
1. Re-read `RALPH.md` from disk
115126
2. Run all commands in order, capture output
116-
3. Resolve `{{ commands.* }}` and `{{ args.* }}` placeholders
127+
3. Resolve `{{ commands.* }}`, `{{ args.* }}`, and `{{ context.* }}` placeholders
117128
4. Pipe assembled prompt to agent via stdin
118129
5. Wait for agent to exit
119130
6. Repeat

docs/writing-prompts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ Rules of thumb:
341341
- **Commands:** Pick the 2-3 most useful signals. Don't add commands whose output the agent doesn't need.
342342
- **Command output:** Can be long. If your commands produce verbose output, consider using scripts that filter to the relevant lines.
343343
- **User args:** Use `{{ args.name }}` to make ralphs reusable — pass project-specific values from the CLI instead of hardcoding them in the prompt. Args also work in command `run` strings (e.g., `run: gh issue view {{ args.issue }}`).
344+
- **Context placeholders:** Use `{{ context.name }}`, `{{ context.iteration }}`, and `{{ context.max_iterations }}` to access runtime metadata — the ralph's directory name, which iteration this is, and the total number if `--n` was set.
344345
- **Working directory:** Commands run from the project root by default. Commands starting with `./` run from the ralph directory — handy for bundling helper scripts next to your `RALPH.md`.
345346

346347
## Next steps

src/ralphify/skills/new-ralph/SKILL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ If any tests are failing above, fix them before continuing.
8686

8787
#### Body
8888

89-
The body is the prompt. It supports two placeholder types:
89+
The body is the prompt. It supports three placeholder types:
9090
- `{{ commands.<name> }}` — replaced with command output each iteration
9191
- `{{ args.<name> }}` — replaced with CLI arguments
92+
- `{{ context.<name> }}` — replaced with runtime metadata (`name`, `iteration`, `max_iterations`)
9293

9394
HTML comments (`<!-- ... -->`) are automatically stripped before the prompt is assembled. They never reach the agent. Use them for notes about why rules exist or TODOs for prompt maintenance.
9495

0 commit comments

Comments
 (0)