|
| 1 | +# PRD: ticket.md Ralph Loop Integration |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Modify `.claude/commands/ralph/ticket.md` so that after the AI council produces its planning artifacts (REVIEW.md, TASKS.md, USER_STORIES.md via Phases 0-3 of `/team`), the workflow generates a PRD, converts it to `.ralph/prd.json`, and launches the Ralph autonomous loop for iterative implementation — replacing the current direct implementation approach (Phases 4-5). |
| 6 | + |
| 7 | +## Goals |
| 8 | + |
| 9 | +- Replace direct implementation (team Phases 4-5) with Ralph autonomous loop |
| 10 | +- Bridge council outputs to Ralph's prd.json format |
| 11 | +- Ensure branchName in prd.json matches the worktree branch (no `ralph/` prefix) |
| 12 | +- Provide clear error handling and reporting for the new workflow steps |
| 13 | +- Maintain all existing Steps 1-7 (issue extraction, worktree, user stories) |
| 14 | + |
| 15 | +## User Stories |
| 16 | + |
| 17 | +### US-001: Rewrite Step 8 to constrain /team to Phases 0-3 only |
| 18 | +**Description:** As a developer running `/ticket`, I want the team workflow to stop after council analysis so that implementation is handled by Ralph instead. |
| 19 | + |
| 20 | +**Acceptance Criteria:** |
| 21 | +- [ ] Step 8 in ticket.md explicitly instructs to execute only Phases 0-3 of /team |
| 22 | +- [ ] Step 8 includes verification that REVIEW.md and TASKS.md exist before proceeding |
| 23 | +- [ ] Phase 4 (implementation) and Phase 5 (validation) are NOT referenced as expected outputs |
| 24 | +- [ ] Typecheck passes |
| 25 | + |
| 26 | +### US-002: Add Step 9 — Generate PRD from council outputs |
| 27 | +**Description:** As a developer running `/ticket`, I want a PRD generated from the council's REVIEW.md, TASKS.md, and USER_STORIES.md so that Ralph has a structured input. |
| 28 | + |
| 29 | +**Acceptance Criteria:** |
| 30 | +- [ ] Step 9 reads council artifacts from the spec folder |
| 31 | +- [ ] Step 9 composes a PRD generation query that includes council context and Ralph sizing rules |
| 32 | +- [ ] Step 9 saves PRD to `tasks/prd-<feature-slug>.md` |
| 33 | +- [ ] Step 9 verifies the PRD file was created |
| 34 | +- [ ] Typecheck passes |
| 35 | + |
| 36 | +### US-003: Add Step 10 — Convert PRD to .ralph/prd.json |
| 37 | +**Description:** As a developer running `/ticket`, I want the PRD converted to Ralph's JSON format with the correct branch name so Ralph can execute. |
| 38 | + |
| 39 | +**Acceptance Criteria:** |
| 40 | +- [ ] Step 10 invokes the ralph skill to convert the PRD to `.ralph/prd.json` |
| 41 | +- [ ] Step 10 explicitly instructs setting branchName to the worktree branch (not `ralph/` prefix) |
| 42 | +- [ ] Step 10 validates that prd.json branchName matches the worktree branch |
| 43 | +- [ ] Step 10 handles mismatch by fixing branchName before proceeding |
| 44 | +- [ ] Typecheck passes |
| 45 | + |
| 46 | +### US-004: Add Step 11 — Launch Ralph autonomous loop |
| 47 | +**Description:** As a developer running `/ticket`, I want Ralph launched automatically so implementation proceeds without manual intervention. |
| 48 | + |
| 49 | +**Acceptance Criteria:** |
| 50 | +- [ ] Step 11 runs `bash ../../.ralph/ralph.sh` from the worktree directory |
| 51 | +- [ ] Step 11 monitors for Ralph's completion signal (`<promise>COMPLETE</promise>`) |
| 52 | +- [ ] Step 11 captures exit status (0 = complete, 1 = partial) |
| 53 | +- [ ] Step 11 reports Ralph execution status |
| 54 | +- [ ] Typecheck passes |
| 55 | + |
| 56 | +### US-005: Update Step 12 — Report workflow completion with Ralph status |
| 57 | +**Description:** As a developer running `/ticket`, I want a clear report showing council artifacts, Ralph status, and next steps. |
| 58 | + |
| 59 | +**Acceptance Criteria:** |
| 60 | +- [ ] Step 12 lists all council artifacts (USER_STORIES.md, PROPOSAL_*.md, REVIEW.md, TASKS.md) |
| 61 | +- [ ] Step 12 lists Ralph artifacts (prd.json, progress.txt) |
| 62 | +- [ ] Step 12 reports COMPLETE or PARTIAL status with story counts |
| 63 | +- [ ] Step 12 provides next steps (push + PR if complete, resume if partial) |
| 64 | +- [ ] Old PR creation steps are removed (user handles PR manually) |
| 65 | +- [ ] Typecheck passes |
| 66 | + |
| 67 | +### US-006: Update error handling section for new failure modes |
| 68 | +**Description:** As a developer running `/ticket`, I want clear error messages and recovery steps when any new step fails. |
| 69 | + |
| 70 | +**Acceptance Criteria:** |
| 71 | +- [ ] Error handling covers: council incomplete, PRD generation failure, prd.json conversion failure, branchName mismatch, Ralph loop failure, Ralph partial completion |
| 72 | +- [ ] Each error case provides a specific recovery command or instruction |
| 73 | +- [ ] Typecheck passes |
| 74 | + |
| 75 | +## Functional Requirements |
| 76 | + |
| 77 | +- FR-1: ticket.md Steps 1-7 remain unchanged |
| 78 | +- FR-2: Step 8 must explicitly stop after Phase 3 (no implementation or validation phases) |
| 79 | +- FR-3: Step 9 must archive previous prd.json/progress.txt before generating new PRD |
| 80 | +- FR-4: Step 9 must include Ralph story sizing rules (1-3 files per story, split by layer) |
| 81 | +- FR-5: Step 10 must set prd.json branchName to match the worktree branch exactly |
| 82 | +- FR-6: Step 11 must run ralph.sh from the worktree directory using `../../.ralph/ralph.sh` path |
| 83 | +- FR-7: Step 12 must NOT include automatic PR creation (deferred to user) |
| 84 | +- FR-8: Error handling must cover all 6 new failure modes with recovery instructions |
| 85 | + |
| 86 | +## Non-Goals |
| 87 | + |
| 88 | +- No modifications to `/team` command (team.md unchanged) |
| 89 | +- No modifications to `ralph.sh` or `prompt.md` |
| 90 | +- No modifications to the prd or ralph skills |
| 91 | +- No automatic PR creation after Ralph completes |
| 92 | +- No concurrent Ralph execution support (one ticket at a time) |
| 93 | + |
| 94 | +## Technical Considerations |
| 95 | + |
| 96 | +- ralph.sh resolves paths relative to SCRIPT_DIR (`.ralph/` at repo root), so prd.json always lives at `.ralph/prd.json` regardless of working directory |
| 97 | +- The worktree branch (e.g., `feat/707-ticket-md-ralph-loop`) does NOT use `ralph/` prefix, but ralph.sh's archival logic handles this gracefully |
| 98 | +- Ralph auto-archives previous runs when branchName changes (ralph.sh lines 14-37) |
| 99 | +- Only one Ralph run can execute at a time (shared `.ralph/prd.json` state) |
| 100 | + |
| 101 | +## Success Metrics |
| 102 | + |
| 103 | +- `/ticket` command successfully bridges from council analysis to Ralph loop without manual intervention |
| 104 | +- Ralph executes at least one user story autonomously from council-derived prd.json |
| 105 | +- Error states produce actionable recovery instructions |
| 106 | +- Workflow completion report accurately reflects Ralph's execution status |
| 107 | + |
| 108 | +## Open Questions |
| 109 | + |
| 110 | +- Should max iterations for ralph.sh be configurable via ticket.md arguments? |
| 111 | +- Should ticket.md support a `--no-ralph` flag to fall back to direct implementation? |
0 commit comments