---
description: Review codebase for quality, security, or task compliance
argument-hint: "[path or task-id]"
agent: code-auditor
---

# Codebase Review: $ARGUMENTS

## For General Code Review (No Task)

**Proceed if:**

- General code quality review
- Security audit
- Performance analysis

Steps:

1. Define review scope (which files/areas)
2. Run code analysis (linting, security checks, tests)
3. Review findings
4. Create report with recommendations
5. Share feedback

---

## For Task-Constrained Review (With Task Files)

## Phase 1: Task Validation

### Check Task Exists

Check task exists via backlog_task_view({ id: "$ARGUMENTS" }), then verify files in `@backlog/tasks/$ARGUMENTS/`: prd.md + spec.md

**If missing:** Create with `/task-with-spec "$ARGUMENTS"` first.

### Load Review Constraints

From PRD:

- Scope (in-scope items)
- Success criteria

From Spec:

- Constraints (rules to follow)
- Edge cases to validate

## Phase 2: Bounded Codebase Analysis

### Review Only Within Task Scope

**Review Focus:** [From PRD goal]
**Review Boundaries:** [From PRD scope]
**Review Constraints:** [From spec constraints]

### Code Analysis Areas (Task-Specific):

1. **Architecture Compliance** (spec architecture section)
2. **Constraint Adherence** (spec constraints section)
3. **Success Criteria Progress** (PRD success criteria)
4. **Edge Case Handling** (spec edge cases)

### Forbidden Review Areas:

- ❌ Code outside PRD scope
- ❌ Patterns violating spec constraints
- ❌ Features not in success criteria
- ❌ Architecture deviations from spec

## Phase 3: Constraint-Based Review

### Review Against Task Requirements

```
Review codebase for task $ARGUMENTS

ANTI-HALLUCINATION REVIEW REQUIREMENTS:
1. Read $TASK_DIR/prd.md and spec.md FIRST
2. Review only code within PRD scope
3. Check compliance with all spec constraints
4. Validate against PRD success criteria
5. Verify edge case handling from spec
6. Report only task-relevant findings
7. Stop if scope violation detected
8. Complete review.md with findings
9. Mark relevant success criteria

REVIEW BOUNDARIES:
- Scope: [From PRD scope section]
- Constraints: [From spec constraints section]
- Success Criteria: [From PRD success criteria]
- Edge Cases: [From spec edge cases]

NO EXCEPTIONS: Review must serve task constraints only
```

### Review Validation:

- **Scope compliance:** Only review code within PRD boundaries
- **Constraint adherence:** Check all spec constraints are followed
- **Success criteria:** Verify progress toward PRD goals
- **Edge cases:** Confirm spec edge cases are handled

## Phase 4: Task-Specific Reporting

### Review Report Structure

```
# Codebase Review: Task $ARGUMENTS

**Task:** $ARGUMENTS
**Scope:** [From PRD scope]
**Constraints:** [From spec constraints]

## Compliance Analysis

### PRD Scope Compliance
- [ ] Code stays within defined scope
- [ ] No off-scope features found
- [ ] User flow implementation correct

### Spec Constraint Adherence
- [ ] All constraints followed
- [ ] Naming conventions correct
- [ ] Architecture plan respected

### Success Criteria Progress
- [ ] Criteria 1: [Status]
- [ ] Criteria 2: [Status]
- [ ] Criteria 3: [Status]

### Edge Case Handling
- [ ] All spec edge cases addressed
- [ ] Error handling appropriate
- [ ] Performance considerations met

## Findings (Task-Only)
[Only issues within task scope]

## Recommendations (Constraint-Aligned)
[Only suggestions that respect constraints]
```

## Phase 5: Review Completion

Update task review.md with findings and mark complete if all criteria met.

---

**ANTI-HALLUCINATION: Task reviews validate against constraints; general reviews are unrestricted**
