---
# Stage identity per spec Section 6.1
stage: 4
stage_id: "04"
title: "Complete"
workflow: tasks
estimated_tokens: 2000

# Context specification
context:
  static:
    persona: "experienced tech lead breaking down features into clear tasks"
    purpose: "Validate and report task generation results"
  dynamic:
    - key: feature_dir
      source: cli_arg

# Pre-validation checks
pre_validation:
  - check: stage_03_completed
    condition: "state.tasks.current_stage == '03-generate'"
    message: "Stage 03 (Generate) must be completed first"
    recovery: "civyk-hatch tasks --stage=3"
  - check: tasks_file_exists
    condition: "tasks.md exists in feature_dir"
    message: "tasks.md must exist"
    recovery: "civyk-hatch tasks --stage=3"

# Execution flow with step types
execution_flow:
  - step: 1
    type: action
    name: validate_format
    instruction: "Verify all tasks follow required format (checkbox, ID, Story label, file paths)"
  - step: 2
    type: action
    name: validate_organization
    instruction: "Verify tasks are properly organized by phase and user stories map to spec.md"
  - step: 3
    type: action
    name: generate_summary
    instruction: "Generate task summary with counts by phase and parallel opportunities"

# Guardrails
guardrails:
  enforcement: active
  allowed_tools:
    - civyk-repoix
    - Read
    - Grep
    - Glob
  forbidden_actions:
    - "Modify any files"
  read_only: true

# Post-validation checks
post_validation:
  - check: format_validated
    description: "Task format was validated"
    severity: error
  - check: organization_validated
    description: "Task organization was validated"
    severity: error
  - check: summary_generated
    description: "Task summary was generated"
    severity: info

# Output specification
output:
  state_update:
    tasks.status: "completed"
    tasks.current_stage: "04-complete"
  completion_command: "civyk-hatch update-stage tasks 04 --status completed"

# Next stage - terminal
next:
  is_terminal: true
version: 1.0.0
---
{{include:verification-rules.md}}

{{include:ai-cache-enforcement.md}}

# Stage 4: Complete

You are a {persona}.

Validate and report task generation results.

---

## Step 1: Validate Format

Verify all tasks follow the required format:

- [ ] Every task has checkbox `- [ ]`
- [ ] Every task has ID (T001, T002...)
- [ ] User story tasks have `[USn]` label
- [ ] Tasks have file paths
- [ ] Parallel tasks correctly marked `[P]`

**Common issues:**

- Missing Task ID
- Missing file paths
- Incorrect [P] or [Story] markers

---

## Step 2: Validate Organization

- [ ] User stories map to spec.md priorities
- [ ] Foundational phase contains blocking tasks
- [ ] Parallel tasks are truly independent
- [ ] Dependencies are explicit

---

## Step 3: Generate Summary

```markdown
# Task Summary

**Total Tasks**: [N]
**Phases**: [N]

| Phase | Tasks | Parallel |
|-------|-------|----------|
| Setup | [N] | [N] |
| Foundational | [N] | [N] |
| US1: [name] | [N] | [N] |
| US2: [name] | [N] | [N] |
| Polish | [N] | [N] |

**MVP Scope**: User Story 1 (P1)
**Parallel Opportunities**: [N] tasks
```

---

## Output

```text

[ok] Task generation complete

File: {{feature_dir}}/tasks.md
Tasks: [N] total across [N] phases

Format validation: PASSED
Organization: PASSED
```

---

## WORKFLOW COMPLETE

Tasks are ready. Proceed to implementation.

**Recovery note**: Task generation is repeatable. Delete tasks.md and re-run if needed.
