---
name: step-01-task
description: Load or create tasks from prd.json
next_step: steps/step-02-execute.md
---

# Step 1: Load Task

## YOUR TASK:

Load the current task from prd.json or create initial task breakdown.

**ULTRA THINK about task decomposition.**

---

## EXECUTION SEQUENCE:

### 1. Check for Existing prd.json

**If `.ralph/prd.json` exists:**
- Read and parse the file
- Find the next task with `passes: false`
- Load into state
- Skip to step 4

**If `.ralph/prd.json` does NOT exist:**
- Continue to step 2 (create tasks)

### 2. Analyze Task Description

**ULTRA THINK about the task:**

- What are the logical subtasks?
- What order should they be executed?
- What are the success criteria for each?
- What files will be modified?

**Generate task breakdown:**

For `{task_description}`, identify 3-10 subtasks.

**Example for "implement user authentication":**
```json
{
  "tasks": [
    { "id": 1, "description": "Create User entity in Domain layer", "passes": false },
    { "id": 2, "description": "Add User DbSet to ApplicationDbContext", "passes": false },
    { "id": 3, "description": "Create EF Core migration", "passes": false },
    { "id": 4, "description": "Implement IPasswordService", "passes": false },
    { "id": 5, "description": "Implement IJwtService", "passes": false },
    { "id": 6, "description": "Create AuthController with login endpoint", "passes": false },
    { "id": 7, "description": "Add authentication middleware", "passes": false },
    { "id": 8, "description": "Write integration tests", "passes": false }
  ]
}
```

### 3. Create prd.json

**Write `.ralph/prd.json`:**

```json
{
  "feature": "{task_description}",
  "created": "{timestamp}",
  "max_iterations": {max_iterations},
  "completion_promise": "{completion_promise}",
  "current_iteration": 1,
  "tasks": [
    { "id": 1, "description": "...", "passes": false },
    { "id": 2, "description": "...", "passes": false }
  ]
}
```

**Initialize `.ralph/progress.txt`:**

```markdown
# Ralph Loop Progress

## Task: {task_description}
## Started: {timestamp}

---

## Iteration 1

### Context
Starting fresh implementation.

### Learnings
(To be updated after each iteration)
```

### 4. Find Current Task

**Find the next task with `passes: false`:**

```javascript
const currentTask = tasks.find(t => !t.passes);
```

**If all tasks are `passes: true`:**
- This shouldn't happen in step-01
- If it does, skip to step-05 (report)

**Store in state:**
```
{current_task_id}          = currentTask.id
{current_task_description} = currentTask.description
{tasks_completed}          = tasks.filter(t => t.passes).length
{tasks_total}              = tasks.length
```

### 5. Read Previous Progress

**If iteration > 1:**

Read `.ralph/progress.txt` to understand:
- What was done in previous iterations
- Key learnings and context
- Files that were modified
- Issues encountered

**This provides context for the current iteration.**

### 6. Show Task Status

**Display current state:**

```
╔══════════════════════════════════════════════════════════════════╗
║  ITERATION {current_iteration} / {max_iterations}                 ║
╠══════════════════════════════════════════════════════════════════╣
║  Progress: {tasks_completed} / {tasks_total} tasks complete       ║
║                                                                    ║
║  Current Task:                                                     ║
║  [{current_task_id}] {current_task_description}                   ║
╠══════════════════════════════════════════════════════════════════╣
║  Previous Learnings:                                               ║
║  {summary from progress.txt}                                       ║
╚══════════════════════════════════════════════════════════════════╝

-> Executing task...
```

---

## OUTPUT FORMAT:

```
Task Loaded:

| Field | Value |
|-------|-------|
| Iteration | {current_iteration} / {max_iterations} |
| Task ID | {current_task_id} |
| Task | {current_task_description} |
| Progress | {tasks_completed} / {tasks_total} |

-> Executing...
```

---

## NEXT STEP:

After task loaded, proceed to `./step-02-execute.md`
