---
name: execute-task
description: Implement a planned task using strict TDD methodology. Use when executing tasks with planned:true and executed:false. Reads the task plan, writes tests first, implements code, and commits.
---

# Execute Task

Implement everything described in a planned task file using strict Test-Driven Development.

## Inputs

You will receive:
- **Task file path** (inside the active initiative's tasks directory)
- **Task ID and title**
- **Already-executed tasks** (what's been built)
- **Environment variables** available in `.env`
- **Constraints** (hard rules to follow)

## Methodology — Strict TDD

Follow this cycle for every piece of functionality:

1. **Write a failing test** that describes the expected behavior
2. **Implement the minimum code** to make the test pass
3. **Refactor** if needed while keeping tests green
4. **Repeat** for the next piece of functionality

Write unit/integration tests for backend logic, component tests for UI, and Playwright e2e tests that exercise the app through a real browser.

## Workflow

### Step 1 — Read the task plan

Read the task file. Understand:
- What needs to be built (overview, acceptance criteria)
- Architecture decisions (if any)
- Constraints and out-of-scope items

### Step 2 — Understand the existing codebase

If this is not the first task:
- Explore the existing project structure
- Understand established patterns (routing, components, styling, state, data layer)
- Build on top of existing code — do NOT recreate or overwrite files unless the plan explicitly says to

### Step 3 — Implement via TDD

For each acceptance criterion:
1. Write a failing test
2. Implement the code to pass it
3. Verify the test passes
4. Move to the next criterion

For UI changes:
- Provide a polished, modern look and feel
- Ensure responsive layout
- Handle loading, error, and empty states
- Use existing component patterns and design system

### Step 4 — Verify

1. **All tests must pass** — run the full test suite
2. **The project must build cleanly** — no build errors
3. **Manual verification** — if it's a UI change, verify it looks correct
4. **Run react-doctor** — use the `react-doctor` skill (`.cursor/skills/autobuilder/react-doctor/SKILL.md`):
   ```bash
   npx -y react-doctor@latest . --verbose --diff
   ```
   Fix all errors. Target score 75+. Do NOT commit if score is below 50.

### Step 5 — Commit

```bash
git add -A && git commit -m "<NNNN>: <short description>"
```

Where `<NNNN>` is the task's 4-digit number prefix (e.g. `0007`).

Do NOT run `git push` — pushing is handled externally by the build loop.

## Rules

- Follow the task plan precisely — it is your specification.
- Build on existing code. Do not recreate files that already exist.
- If the task has dependencies, they should already be implemented. Use their code.
- Use the `.env` credentials for real API testing when available.
- NEVER modify task files — they are read-only to you.
- NEVER run `git push`.
