1---2name: ralph-convert-prd3description: Converts Product Requirements Documents into prd.json format for the Ralph autonomous agent system. Use when preparing PRDs for Ralph execution, breaking down features into atomic user stories, or when the user mentions Ralph, prd.json, or autonomous agent workflows.4---5
6<objective>
7Transform existing Product Requirements Documents into the structured `prd.json` format used by the Ralph autonomous agent system. Each story must be completable in one LLM context window to prevent broken code from context overflow. Each story must include real runtime verification commands.
8</objective>
9
10<quick_start>
111. Read the user's PRD or feature requirements
122. Read SPEC.md if available (for verification environment info)
133. Break down into atomic user stories (one context window each)
144. Classify each story with `storyType`
155. Generate `verificationCommands` with real runtime checks
166. Set `blockedBy` dependencies
177. Order stories by dependency (schema → backend → UI → dashboard)
188. Output valid `tasks/prd.json`
19</quick_start>
20
21<essential_principles>
22<principle name="story_size">
23**Critical Rule**: Each story must be completable in ONE Ralph iteration (one context window).
24
25Stories that are too large cause the LLM to run out of context before completion, resulting in broken code.
26
27**Right-sized stories**:
28- Add a database column
29- Create a UI component
30- Update server actions
31- Implement a filter
32
33**Too large (split these)**:
34- Build entire dashboards
35- Add authentication systems
36- Refactor entire APIs
37</principle>
38
39<principle name="story_ordering">
40Stories must execute sequentially without forward dependencies:
41
421. Schema/database changes
432. Server actions and backend logic
443. UI components
454. Dashboard/summary views
46
47Never reference something that doesn't exist yet.
48</principle>
49
50<principle name="acceptance_criteria">
51Each criterion must be verifiable and specific. Avoid vague language.
52
53**Good criteria**:
54- "Add status column with values: 'pending' | 'in_progress' | 'done'"
55- "Filter dropdown includes: All, Active, Completed"
56- "Clicking delete shows confirmation dialog"
57
58**Bad criteria** (too vague):
59- "Works correctly"
60- "Good UX"
61- "Handles edge cases"
62</principle>
63
64<principle name="mandatory_criteria">
65Every story MUST include: `"Typecheck passes"`
66
67UI-focused stories MUST also include: `"Verify in browser using Playwright e2e test"`
68</principle>
69
70<principle name="real_verification">
71Every story MUST include `verificationCommands` with real runtime checks — not just static analysis.
72
73**By storyType:**
74
75| storyType | Required verification | Example |
76|-----------|----------------------|---------|
77| `database` | Run migration + query DB to confirm schema | `prisma migrate deploy`, SQL query for new column |
78| `backend` | Run tests + curl endpoint with real data | `curl -s http://localhost:3000/api/...` |
79| `api` | curl endpoint, check status code and response body | `curl -s -w '%{http_code}' ...` |
80| `frontend` | Playwright e2e test that interacts with real UI | `npx playwright test tests/e2e/...` |
81| `infra` | Health check, config validation, service startup | `curl -s http://localhost:3000/health` |
82| `test` | Run the test suite | `npm test` / `pytest` |
83
84Static checks (typecheck) are always included as baseline. Runtime validation is **additionally required**.
85</principle>
86</essential_principles>
87
88<output_format>
89```json
90{
91 "project": "[Project Name]",
92 "branchName": "ralph/[feature-name-kebab-case]",
93 "description": "[Feature description]",
94 "testCommands": {
95 "unit": "npm test",
96 "integration": "npm run test:integration",
97 "e2e": "npx playwright test",
98 "typecheck": "npm run typecheck"
99 },
100 "userStories": [
101 {
102 "id": "US-001",
103 "title": "[Story title]",
104 "description": "As a [user], I want [feature] so that [benefit]",
105 "storyType": "database",
106 "acceptanceCriteria": [
107 "Specific criterion 1",
108 "Specific criterion 2",
109 "Typecheck passes"
110 ],
111 "verificationCommands": [
112 { "command": "npm run typecheck", "expect": "exit_code:0" },
113 { "command": "curl -s http://localhost:3000/api/tasks | jq length", "expect": "not_empty" }
114 ],
115 "status": "pending",
116 "priority": 1,
117 "attempts": 0,
118 "maxAttempts": 3,
119 "notes": "",
120 "blockedBy": [],
121 "docsToUpdate": ["README.md"],
122 "completedAt": null,
123 "lastAttemptLog": ""
124 }
125 ]
126}
127```
128
129**Field requirements**:
130- `id`: Sequential US-001, US-002, etc.
131- `title`: Short, descriptive action
132- `description`: User story format (As a... I want... so that...)
133- `storyType`: One of `"backend"` | `"frontend"` | `"database"` | `"api"` | `"infra"` | `"test"`
134- `acceptanceCriteria`: Array of specific, verifiable criteria
135- `verificationCommands`: Array of `{command, expect}` with real runtime checks
136- `status`: Always `"pending"` initially
137- `priority`: Execution order (1 = first)
138- `attempts`: Always `0` initially
139- `maxAttempts`: Default `3` (increase for complex stories)
140- `notes`: Empty string initially
141- `blockedBy`: Array of story IDs that must be `"done"` first
142- `docsToUpdate`: Array of file paths to documentation that must be updated when story is done (e.g., `"README.md"`, `"docs/api.md"`, `"CHANGELOG.md"`)
143- `completedAt`: Always `null` initially
144- `lastAttemptLog`: Empty string initially
145
146**Expect matchers for verificationCommands:**
147- `exit_code:0` — command exits with code 0
148- `exit_code:N` — command exits with specific code N
149- `contains:STRING` — stdout contains STRING
150- `not_empty` — stdout is non-empty
151- `matches:REGEX` — stdout matches regex pattern
152</output_format>
153
154<workflow>
1551. **Understand the PRD**: Read the full requirements document or feature request
1562. **Read SPEC.md**: If available, extract verification environment info (dev server URL, DB type, test runners, commands). Use this to populate the root-level `testCommands` object
1573. **Identify components**: List all database changes, backend logic, UI elements
1584. **Decompose into stories**: Break each component into atomic, one-iteration tasks
1595. **Classify storyType**: Assign `database`, `backend`, `api`, `frontend`, `infra`, or `test` to each story
1606. **Order by dependency**: Schema first, then backend, then UI, then dashboards
1617. **Set blockedBy**: Each story should list IDs of stories it depends on
1628. **Write acceptance criteria**: Make each criterion specific and verifiable
1639. **Generate verificationCommands**: Add real runtime checks per storyType (curl, Playwright, DB queries)
16410. **Add mandatory criteria**: Ensure every story has "Typecheck passes"
16511. **Generate tasks/prd.json**: Output the complete JSON structure to `tasks/prd.json`
16612. **Run pre-save checklist**: Verify all requirements before finalizing
167</workflow>
168
169<pre_save_checklist>
170Before outputting the final prd.json, verify:
171
172- [ ] Previous runs archived (if applicable)
173- [ ] Each story completable in one iteration
174- [ ] Each story has a `storyType` assigned
175- [ ] Stories ordered by dependency (no forward references)
176- [ ] `blockedBy` dependencies are set correctly
177- [ ] All stories include "Typecheck passes" in acceptanceCriteria
178- [ ] UI stories include Playwright verification
179- [ ] Every story has `verificationCommands` with at least one runtime check
180- [ ] Acceptance criteria are verifiable, not vague
181- [ ] No story depends on later stories
182- [ ] `docsToUpdate` lists relevant docs for each story
183- [ ] `status` is `"pending"`, `attempts` is `0`, `maxAttempts` is set
184</pre_save_checklist>
185
186<examples>
187<example name="database_story">
188```json
189{
190 "id": "US-001",
191 "title": "Add task status column to database",
192 "description": "As a developer, I want a status column on tasks so that we can track task progress",
193 "storyType": "database",
194 "acceptanceCriteria": [
195 "Add status column to tasks table with type enum('pending', 'in_progress', 'done')",
196 "Default value is 'pending'",
197 "Migration runs without errors",
198 "Typecheck passes"
199 ],
200 "verificationCommands": [
201 { "command": "npx prisma migrate deploy", "expect": "exit_code:0" },
202 { "command": "npx prisma db execute --stdin <<< \"SELECT column_name FROM information_schema.columns WHERE table_name='tasks' AND column_name='status'\"", "expect": "contains:status" },
203 { "command": "npm run typecheck", "expect": "exit_code:0" }
204 ],
205 "status": "pending",
206 "priority": 1,
207 "attempts": 0,
208 "maxAttempts": 3,
209 "notes": "",
210 "blockedBy": [],
211 "docsToUpdate": ["README.md"],
212 "completedAt": null,
213 "lastAttemptLog": ""
214}
215```
216</example>
217
218<example name="api_story">
219```json
220{
221 "id": "US-002",
222 "title": "Create task CRUD API endpoints",
223 "description": "As a developer, I want REST endpoints for tasks so that the frontend can manage tasks",
224 "storyType": "api",
225 "acceptanceCriteria": [
226 "GET /api/tasks returns array of tasks",
227 "POST /api/tasks creates a new task and returns 201",
228 "PATCH /api/tasks/:id updates task and returns 200",
229 "DELETE /api/tasks/:id removes task and returns 204",
230 "Typecheck passes"
231 ],
232 "verificationCommands": [
233 { "command": "npm run typecheck", "expect": "exit_code:0" },
234 { "command": "npm test -- --grep 'tasks API'", "expect": "exit_code:0" },
235 { "command": "curl -s -o /dev/null -w '%{http_code}' http://localhost:3000/api/tasks", "expect": "contains:200" },
236 { "command": "curl -s -X POST http://localhost:3000/api/tasks -H 'Content-Type: application/json' -d '{\"title\":\"test task\"}' -o /dev/null -w '%{http_code}'", "expect": "contains:201" }
237 ],
238 "status": "pending",
239 "priority": 2,
240 "attempts": 0,
241 "maxAttempts": 3,
242 "notes": "",
243 "blockedBy": ["US-001"],
244 "docsToUpdate": ["README.md", "docs/api.md"],
245 "completedAt": null,
246 "lastAttemptLog": ""
247}
248```
249</example>
250
251<example name="ui_story">
252```json
253{
254 "id": "US-003",
255 "title": "Add status filter dropdown to task list",
256 "description": "As a user, I want to filter tasks by status so that I can focus on relevant tasks",
257 "storyType": "frontend",
258 "acceptanceCriteria": [
259 "Filter dropdown appears above task list",
260 "Options: All, Pending, In Progress, Done",
261 "Selecting option filters displayed tasks",
262 "Filter persists on page refresh",
263 "Typecheck passes",
264 "Verify in browser using Playwright e2e test"
265 ],
266 "verificationCommands": [
267 { "command": "npm run typecheck", "expect": "exit_code:0" },
268 { "command": "npx playwright test tests/e2e/task-filter.spec.ts", "expect": "exit_code:0" }
269 ],
270 "status": "pending",
271 "priority": 3,
272 "attempts": 0,
273 "maxAttempts": 3,
274 "notes": "",
275 "blockedBy": ["US-002"],
276 "docsToUpdate": ["README.md"],
277 "completedAt": null,
278 "lastAttemptLog": ""
279}
280```
281</example>
282</examples>
283
284<success_criteria>
285Conversion is complete when:
286
287- [ ] All features from PRD are captured as user stories
288- [ ] Each story is atomic (one context window)
289- [ ] Each story has a `storyType` assigned
290- [ ] Stories are properly ordered by dependency with `blockedBy` set
291- [ ] All acceptance criteria are specific and verifiable
292- [ ] Mandatory criteria ("Typecheck passes") present on all stories
293- [ ] Every story has `verificationCommands` with real runtime checks
294- [ ] UI stories include Playwright verification
295- [ ] Valid JSON structure with all required fields
296- [ ] Pre-save checklist passes
297</success_criteria>