---
description: Validate implementation against requirements, design, and tasks
allowed-tools: Bash, Glob, Grep, Read, LS
argument-hint: [feature-name] [task-numbers]
---

# Implementation Validation

<background_information>
- **Role**: Verify that completed implementation tasks satisfy the approved requirements, conform to the technical design, and leave the test suite in a passing state.
- **Success Criteria**:
  - Every validated task is marked complete in `tasks.md`
  - Tests exist, execute, and pass for all implemented functionality
  - Each EARS requirement is traceable to real implementation evidence
  - The implementation structure matches the design contracts
  - No regressions exist in previously working functionality
</background_information>

<instructions>
## Core Task
Validate the implementation for the specified feature(s) and task(s) against all approved specification artifacts.

## Execution Steps

### Step 1: Determine the Validation Target

**No arguments provided** (both `$1` and `$2` are empty):
- Parse conversation history to find prior `/sdd:spec-impl <feature> [tasks]` invocations
- Extract feature names and task numbers from each occurrence
- Aggregate all implemented tasks by feature
- Report what was auto-detected (e.g., "user-auth: tasks 1.1, 1.2, 1.3")
- If conversation history yields nothing, scan `{{SDD_DIR}}/specs/` for features with any `[x]` tasks

**Feature only** (`$1` present, `$2` absent):
- Validate the specified feature
- Treat all `[x]` tasks in `{{SDD_DIR}}/specs/$1/tasks.md` as the validation scope

**Feature and tasks** (both `$1` and `$2` present):
- Validate only the specified tasks (e.g., `user-auth 1.1,1.2`)

### Step 2: Load Context

For each feature in scope:
- Read `{{SDD_DIR}}/specs/<feature>/spec.json` for metadata and language
- Read `{{SDD_DIR}}/specs/<feature>/requirements.md` for the requirement set
- Read `{{SDD_DIR}}/specs/<feature>/design.md` for design contracts and component structure
- Read `{{SDD_DIR}}/specs/<feature>/tasks.md` for the full task list
- Read the entire `{{SDD_DIR}}/steering/` directory (core + all custom files)

### Step 3: Run Validation Checks

For each task in scope, perform all five checks:

#### Task Completion
- Confirm the checkbox is `[x]` in `tasks.md`
- Flag as "Task not marked complete" if unchecked

#### Test Coverage
- Locate tests for the functionality introduced by the task
- Execute the test suite (e.g., `npm test`, `pytest`, `go test`) via Bash
- Flag as "Test coverage issue" if tests are absent or failing

#### Requirements Traceability
- Identify the EARS requirements linked to the task (via `_Requirements:` annotations)
- Use Grep to find evidence of those requirements in the implementation
- Flag as "Requirement not implemented" if no evidence is found

#### Design Alignment
- Verify that key interfaces, components, and modules specified in `design.md` exist in the codebase
- Use Grep and LS to confirm file structure matches design expectations
- Flag as "Design deviation" if meaningful misalignment is discovered

#### Regression Check
- Run the full test suite and confirm all pre-existing tests still pass
- Flag as "Regression detected" if any previously passing test now fails

### Step 4: Generate Report

Produce a validation report in the language specified in `spec.json`:
- Per-feature summary with pass/fail counts
- Coverage analysis: tasks, requirements, and design alignment
- Prioritized issue list with severity (Critical / Warning) and location
- Final GO / NO-GO decision

## Important Constraints
- **Conversation-aware**: Auto-detection from conversation history takes priority over directory scanning
- **Non-blocking warnings**: Design deviations are warnings unless they indicate a critical contract breach
- **Test coverage is mandatory**: Missing or failing tests yield a NO-GO regardless of other results
- **Full traceability required**: Every requirement linked to a task must have traceable implementation evidence
</instructions>

## Tool Guidance
- **Parse history**: Scan for `/sdd:spec-impl` patterns to auto-detect scope when no arguments are given
- **Read context first**: Load all spec files and steering before running checks
- **Bash for test execution**: Run test commands and capture output for pass/fail determination
- **Grep for traceability**: Search the implementation for evidence of each requirement
- **LS and Glob for structure**: Verify file layout against design.md expectations

## Output Description

Report in the language specified in `spec.json`:

1. **Detected Scope**: Features and tasks being validated (especially useful when auto-detected)
2. **Validation Summary**: Per-feature pass/fail breakdown
3. **Issues Found**: Each issue with severity, description, and file location
4. **Coverage Report**: Requirements covered / total; design components verified / total; tasks complete / total
5. **Decision**: GO (implementation meets spec) or NO-GO (issues must be resolved first)

**Formatting Rules**:
- Use Markdown headings and tables for clarity
- Flag critical issues with ⚠️
- Keep the summary under 400 words

## Safety & Fallback

### Error Scenarios
- **No Implementation Detected**: If no `/sdd:spec-impl` history exists and no `[x]` tasks are found, report "No implemented tasks detected" and suggest running `/sdd:spec-impl` first
- **Test Framework Unknown**: If the test runner cannot be determined, warn and skip automated test validation — note that manual verification is required
- **Spec Files Missing**: If `spec.json`, `requirements.md`, or `design.md` are absent, halt with a specific error message identifying which file is missing
- **Language Not Set**: Default to English (`en`) if `spec.json` omits a language value

### Next Steps

**When Decision Is GO**:
- Implementation is validated and ready
- Proceed to deployment, review, or the next feature

**When Decision Is NO-GO**:
- Address each critical issue identified in the report
- Re-run the relevant tasks with `/sdd:spec-impl <feature> [tasks]`
- Re-validate with `/sdd:validate-impl [feature] [tasks]`

**Note**: Running validation after implementation confirms specification alignment and catches quality gaps before they reach production.
