Skip to content

Commit 4579fac

Browse files
Kasper Jungeclaude
authored andcommitted
docs: add full assembled prompt walkthrough for users who want to understand or debug what their agent receives
- Add "Full example: what the agent receives" section to how-it-works.md showing a complete PROMPT.md → assembled output transformation with contexts, instructions, and check failure injection - Document that HTML comments in primitive files are stripped before prompt injection - Document that scripts and commands run with the project root as working directory Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ad6c006 commit 4579fac

2 files changed

Lines changed: 110 additions & 2 deletions

File tree

docs/how-it-works.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,97 @@ Fix all failing tests. Do not skip or delete tests.
9090

9191
On the **first** iteration, no check failures are injected (there's no previous iteration to have failed).
9292

93+
## Full example: what the agent receives
94+
95+
Here's a concrete example showing how all three layers combine into the final prompt. Given these files:
96+
97+
**`PROMPT.md`**
98+
99+
```markdown
100+
# Prompt
101+
102+
{{ contexts.git-log }}
103+
104+
You are an autonomous coding agent. Each iteration starts fresh.
105+
106+
Read PLAN.md and implement the next task.
107+
108+
## Rules
109+
{{ instructions.code-style }}
110+
111+
- One task per iteration
112+
- Commit with a descriptive message
113+
```
114+
115+
**`.ralph/contexts/git-log/CONTEXT.md`**
116+
117+
```markdown
118+
---
119+
command: git log --oneline -5
120+
timeout: 10
121+
enabled: true
122+
---
123+
## Recent commits
124+
```
125+
126+
**`.ralph/instructions/code-style/INSTRUCTION.md`**
127+
128+
```markdown
129+
---
130+
enabled: true
131+
---
132+
<!-- Internal note: agreed on these rules in sprint retro -->
133+
- Use type hints on all function signatures
134+
- Keep functions under 30 lines
135+
```
136+
137+
And suppose the previous iteration's test check failed with exit code 1.
138+
139+
The **assembled prompt** piped to the agent as stdin:
140+
141+
````markdown
142+
# Prompt
143+
144+
## Recent commits
145+
a1b2c3d feat: add user model
146+
e4f5g6h fix: database connection timeout
147+
i7j8k9l docs: update API reference
148+
m0n1o2p refactor: extract validation logic
149+
q3r4s5t test: add integration tests
150+
151+
You are an autonomous coding agent. Each iteration starts fresh.
152+
153+
Read PLAN.md and implement the next task.
154+
155+
## Rules
156+
- Use type hints on all function signatures
157+
- Keep functions under 30 lines
158+
159+
- One task per iteration
160+
- Commit with a descriptive message
161+
162+
## Check Failures
163+
164+
The following checks failed after the last iteration. Fix these issues:
165+
166+
### tests
167+
**Exit code:** 1
168+
169+
```
170+
FAILED tests/test_api.py::test_create_user - AssertionError: expected 201, got 400
171+
```
172+
173+
Fix all failing tests.
174+
````
175+
176+
Notice:
177+
178+
- `{{ contexts.git-log }}` was replaced with the static content ("## Recent commits") plus the live `git log` output
179+
- `{{ instructions.code-style }}` was replaced inline with the instruction body
180+
- The HTML comment in the instruction file was stripped — you can leave notes in your primitive files that won't appear in the agent's prompt
181+
- Check failures from the previous iteration were appended at the end automatically
182+
- On the first iteration, the "Check Failures" section would not be present
183+
93184
## Execution
94185

95186
The assembled prompt is piped to the agent command as **stdin**. The agent command is configured in `ralph.toml`:

docs/primitives.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,24 @@ Instead of a `command` in frontmatter, you can place an executable script named
6161
└── run.sh
6262
```
6363

64-
If both a `command` and a `run.*` script exist, the script takes precedence.
64+
If both a `command` and a `run.*` script exist, the script takes precedence. Scripts and commands always run with the **project root** as the working directory, not the primitive's directory.
65+
66+
### HTML comments are stripped
67+
68+
You can use HTML comments in any primitive file for internal notes — they're stripped before the content is injected into the prompt:
69+
70+
```markdown
71+
---
72+
command: pytest -x
73+
timeout: 120
74+
enabled: true
75+
---
76+
<!-- TODO: consider adding --tb=short flag -->
77+
<!-- Agreed on this policy in sprint retro 2025-01-10 -->
78+
Fix all failing tests. Do not skip or delete tests.
79+
```
80+
81+
The agent never sees the comments. This is useful for documenting why a check exists or what you've tried.
6582

6683
### How check failures appear in the prompt
6784

@@ -139,7 +156,7 @@ Just like checks, you can place an executable script named `run.*` (e.g. `run.sh
139156
└── run.sh
140157
```
141158

142-
If both a `command` and a `run.*` script exist, the script takes precedence.
159+
If both a `command` and a `run.*` script exist, the script takes precedence. Scripts and commands always run with the **project root** as the working directory.
143160

144161
This is useful for contexts that need more complex logic than a single shell command — for example, querying an API, combining multiple data sources, or running a Python script that formats output.
145162

0 commit comments

Comments
 (0)