# PRD: Ralph Loop Router Hardwiring

## Overview
Hardwire automatic task routing so complex tasks ALWAYS go through Ralph Loop.

---

## Sprint 1: Router Infrastructure

#### **US-001: Task Complexity Detector**
**Goal:** Create a module that analyzes task descriptions and returns a complexity score to determine RWL routing

**Acceptance Criteria:**
- [ ] Analyzes task description for step count indicators
- [ ] Detects complexity keywords: setup, install, configure, migrate, build, integrate
- [ ] Checks for external dependencies (API, downloads, multi-file changes)
- [ ] Returns complexity score 1-10
- [ ] Score >= 5 returns routing recommendation for RWL

**Files to Create:**

/mnt/e/genesis-system/core/task_complexity_detector.py

---

#### **US-002: Pre-Mortem Template Generator**
**Goal:** Create a pre-mortem template that is auto-generated before each RWL run to anticipate failures

**Acceptance Criteria:**
- [ ] Template section: What could fail?
- [ ] Template section: What assumptions are we making?
- [ ] Template section: What do we not fully understand?
- [ ] Template section: Rollback plan
- [ ] Function to generate filled template from PRD content

**Files to Create:**

/mnt/e/genesis-system/core/pre_mortem_generator.py

---

#### **US-003: Verification Stamp Generator**
**Goal:** Create cryptographic verification stamps for all RWL outputs to make claims provable

**Acceptance Criteria:**
- [ ] Generates SHA256 hash of output files
- [ ] Includes UTC timestamp
- [ ] Links to run report path
- [ ] Returns formatted stamp string
- [ ] Function to verify existing stamps

**Files to Create:**

/mnt/e/genesis-system/core/verification_stamp.py

---

#### **US-004: Router Decision Logger**
**Goal:** Log all routing decisions for audit trail of manual vs RWL execution choices

**Acceptance Criteria:**
- [ ] Logs task description and complexity score
- [ ] Logs routing decision (RWL or manual)
- [ ] Logs override reason if manual chosen
- [ ] Logs agent ID and timestamp
- [ ] Writes to JSONL format for queryability

**Files to Create:**

/mnt/e/genesis-system/core/router_decision_logger.py

---

#### **US-005: CLAUDE.md Router Integration**
**Goal:** Update CLAUDE.md to include mandatory routing check protocol

**Acceptance Criteria:**
- [ ] Add ROUTING PROTOCOL section after RALPH WIGGUM TRIGGER
- [ ] Define complexity threshold (score >= 5 = RWL)
- [ ] Document override procedure with logging requirement
- [ ] Reference task_complexity_detector.py usage
- [ ] Include pre-mortem requirement for all RWL runs

**Files to Create:**

/mnt/e/genesis-system/CLAUDE.md

---

## Constraints
- Model: Gemini Flash 2.0
- Max iterations: 5 per story
- Must work with existing gemini_ralph_orchestrator.py
