1---2name: ralph-convert-prd3description: Converts PRDs into prd.json for Ralph. Use when preparing PRDs for Ralph or breaking features into atomic stories.4---56<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>910<quick_start>111. Read the user's PRD or feature requirements122. 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 checks166. Set `blockedBy` dependencies177. Order stories by dependency (schema → backend → UI → dashboard)188. Output valid `tasks/prd.json`19</quick_start>2021<essential_principles>22<principle name="story_size">23**Critical Rule**: Each story must be completable in ONE Ralph iteration (one context window).2425Stories that are too large cause the LLM to run out of context before completion, resulting in broken code.2627**Right-sized stories**:28- Add a database column29- Create a UI component30- Update server actions31- Implement a filter3233**Too large (split these)**:34- Build entire dashboards35- Add authentication systems36- Refactor entire APIs37</principle>3839<principle name="story_ordering">40Stories must execute sequentially without forward dependencies:41421. Schema/database changes432. Server actions and backend logic443. UI components454. Dashboard/summary views4647Never reference something that doesn't exist yet.48</principle>4950<principle name="acceptance_criteria">51Each criterion must be verifiable and specific. Avoid vague language.5253**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"5758**Bad criteria** (too vague):59- "Works correctly"60- "Good UX"61- "Handles edge cases"62</principle>6364<principle name="mandatory_criteria">65Every story MUST include: `"Typecheck passes"`6667UI-focused stories MUST also include: `"Verify in browser using Playwright e2e test"`68</principle>6970<principle name="real_verification">71Every story MUST include `verificationCommands` with real runtime checks — not just static analysis.7273**By storyType:**7475| 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` |8384Static checks (typecheck) are always included as baseline. Runtime validation is **additionally required**.85</principle>86</essential_principles>8788<output_format>89```json90{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 "Typecheck passes"109 ],110 "verificationCommands": [111 { "command": "npm run typecheck", "expect": "exit_code:0" },112 { "command": "curl -s http://localhost:3000/api/tasks | jq length", "expect": "not_empty" }113 ],114 "status": "pending",115 "priority": 1,116 "attempts": 0,117 "maxAttempts": 3,118 "notes": "",119 "blockedBy": [],120 "docsToUpdate": ["README.md"],121 "completedAt": null,122 "lastAttemptLog": ""123 }124 ]125}126```127128**Field requirements**:129- `id`: Sequential US-001, US-002, etc.130- `title`: Short, descriptive action131- `description`: User story format (As a... I want... so that...)132- `storyType`: One of `"backend"` | `"frontend"` | `"database"` | `"api"` | `"infra"` | `"test"`133- `acceptanceCriteria`: Array of specific, verifiable criteria134- `verificationCommands`: Array of `{command, expect}` with real runtime checks135- `status`: Always `"pending"` initially136- `priority`: Execution order (1 = first)137- `attempts`: Always `0` initially138- `maxAttempts`: Default `3` (increase for complex stories)139- `blockedBy`: Array of story IDs that must be `"done"` first140- `docsToUpdate`: Array of file paths to documentation that must be updated141- `completedAt`: Always `null` initially142- `lastAttemptLog`: Empty string initially143144**Expect matchers for verificationCommands:**145- `exit_code:0` — command exits with code 0146- `exit_code:N` — command exits with specific code N147- `contains:STRING` — stdout contains STRING148- `not_empty` — stdout is non-empty149- `matches:REGEX` — stdout matches regex pattern150</output_format>151152<workflow>1531. **Understand the PRD**: Read the full requirements document or feature request1542. **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` object1553. **Identify components**: List all database changes, backend logic, UI elements1564. **Decompose into stories**: Break each component into atomic, one-iteration tasks1575. **Classify storyType**: Assign `database`, `backend`, `api`, `frontend`, `infra`, or `test` to each story1586. **Order by dependency**: Schema first, then backend, then UI, then dashboards1597. **Set blockedBy**: Each story should list IDs of stories it depends on1608. **Write acceptance criteria**: Make each criterion specific and verifiable1619. **Generate verificationCommands**: Add real runtime checks per storyType (curl, Playwright, DB queries)16210. **Add mandatory criteria**: Ensure every story has "Typecheck passes"16311. **Generate tasks/prd.json**: Output the complete JSON structure to `tasks/prd.json`16412. **Run pre-save checklist**: Verify all requirements before finalizing165</workflow>166167<pre_save_checklist>168Before outputting the final prd.json, verify:169170- [ ] Each story completable in one iteration171- [ ] Each story has a `storyType` assigned172- [ ] Stories ordered by dependency (no forward references)173- [ ] `blockedBy` dependencies are set correctly174- [ ] All stories include "Typecheck passes" in acceptanceCriteria175- [ ] UI stories include Playwright verification176- [ ] Every story has `verificationCommands` with at least one runtime check177- [ ] Acceptance criteria are verifiable, not vague178- [ ] `docsToUpdate` lists relevant docs for each story179- [ ] `status` is `"pending"`, `attempts` is `0`, `maxAttempts` is set180</pre_save_checklist>181182<examples>183<example name="database_story">184```json185{186 "id": "US-001",187 "title": "Add task status column to database",188 "description": "As a developer, I want a status column on tasks so that we can track task progress",189 "storyType": "database",190 "acceptanceCriteria": [191 "Add status column to tasks table with type enum('pending', 'in_progress', 'done')",192 "Default value is 'pending'",193 "Migration runs without errors",194 "Typecheck passes"195 ],196 "verificationCommands": [197 { "command": "npx prisma migrate deploy", "expect": "exit_code:0" },198 { "command": "npx prisma db execute --stdin <<< \"SELECT column_name FROM information_schema.columns WHERE table_name='tasks' AND column_name='status'\"", "expect": "contains:status" },199 { "command": "npm run typecheck", "expect": "exit_code:0" }200 ],201 "status": "pending",202 "priority": 1,203 "attempts": 0,204 "maxAttempts": 3,205 "notes": "",206 "blockedBy": [],207 "docsToUpdate": ["README.md"],208 "completedAt": null,209 "lastAttemptLog": ""210}211```212</example>213214<example name="api_story">215```json216{217 "id": "US-002",218 "title": "Create task CRUD API endpoints",219 "description": "As a developer, I want REST endpoints for tasks so that the frontend can manage tasks",220 "storyType": "api",221 "acceptanceCriteria": [222 "GET /api/tasks returns array of tasks",223 "POST /api/tasks creates a new task and returns 201",224 "PATCH /api/tasks/:id updates task and returns 200",225 "DELETE /api/tasks/:id removes task and returns 204",226 "Typecheck passes"227 ],228 "verificationCommands": [229 { "command": "npm run typecheck", "expect": "exit_code:0" },230 { "command": "curl -s -o /dev/null -w '%{http_code}' http://localhost:3000/api/tasks", "expect": "contains:200" },231 { "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" }232 ],233 "status": "pending",234 "priority": 2,235 "attempts": 0,236 "maxAttempts": 3,237 "notes": "",238 "blockedBy": ["US-001"],239 "docsToUpdate": ["README.md", "docs/api.md"],240 "completedAt": null,241 "lastAttemptLog": ""242}243```244</example>245246<example name="frontend_story">247```json248{249 "id": "US-003",250 "title": "Add status filter dropdown to task list",251 "description": "As a user, I want to filter tasks by status so that I can focus on relevant tasks",252 "storyType": "frontend",253 "acceptanceCriteria": [254 "Filter dropdown appears above task list",255 "Options: All, Pending, In Progress, Done",256 "Selecting option filters displayed tasks",257 "Typecheck passes",258 "Verify in browser using Playwright e2e test"259 ],260 "verificationCommands": [261 { "command": "npm run typecheck", "expect": "exit_code:0" },262 { "command": "npx playwright test tests/e2e/task-filter.spec.ts", "expect": "exit_code:0" }263 ],264 "status": "pending",265 "priority": 3,266 "attempts": 0,267 "maxAttempts": 3,268 "notes": "",269 "blockedBy": ["US-002"],270 "docsToUpdate": ["README.md"],271 "completedAt": null,272 "lastAttemptLog": ""273}274```275</example>276</examples>277278<success_criteria>279Conversion is complete when:280281- [ ] All features from PRD are captured as user stories282- [ ] Each story is atomic (one context window)283- [ ] Each story has a `storyType` assigned284- [ ] Stories are properly ordered by dependency with `blockedBy` set285- [ ] All acceptance criteria are specific and verifiable286- [ ] Mandatory criteria ("Typecheck passes") present on all stories287- [ ] Every story has `verificationCommands` with real runtime checks288- [ ] UI stories include Playwright verification289- [ ] Valid JSON structure with all required fields290- [ ] Pre-save checklist passes291</success_criteria>