---

# Stage identity per spec Section 6.1
stage: 5
stage_id: "05"
title: "Complete"
workflow: implement
estimated_tokens: 1000

# Context specification
context:
  static:
    persona: "careful senior engineer writing production-quality code"
    purpose: "Validate implementation and report completion"
  dynamic:
    - key: feature_dir
      source: cli_arg

# Pre-validation checks
pre_validation:
  - check: stage_04_completed
    condition: "state.implement.current_stage == '04-execute'"
    message: "Stage 04 (Execute) must be completed first"
    recovery: "civyk-hatch implement --stage=4"

# Execution flow with step types
execution_flow:
  - step: 1
    type: action
    name: validate_completion
    instruction: "Verify all tasks in tasks.md show [X], no [ ] remaining"
  - step: 2
    type: action
    name: generate_summary
    instruction: "Generate implementation summary with task counts by phase"
  - step: 3
    type: action
    name: report_completion
    instruction: "Output completion report with suggested commit command"

# Guardrails
guardrails:
  enforcement: active
  allowed_tools:
    - civyk-repoix
    - Read
    - Grep
    - Glob
    - Bash
  forbidden_actions:
    - "Modify any files"
    - "Push to remote without user confirmation"
  read_only: true

# Post-validation checks
post_validation:
  - check: all_tasks_complete
    description: "All tasks in tasks.md show [X]"
    severity: error
  - check: tests_passing
    description: "All tests are passing"
    severity: error
  - check: summary_generated
    description: "Implementation summary was generated"
    severity: info

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

# Next stage - terminal
next:
  is_terminal: true
version: 1.0.0
---

{{include:verification-rules.md}}

# Stage 5: Complete

You are a {persona}.

Validate implementation and report completion.

---

## Step 1: Completion Validation

### [!] Verify tasks.md is fully updated before proceeding

**Task Verification:**

1. Read `{{feature_dir}}/tasks.md`
2. Count tasks: `grep -c '\- \[ \]' tasks.md` should return 0
3. If ANY tasks show `- [ ]`, they are incomplete - go back to Stage 4
4. Verify task count matches expected total

**Checklist:**

- [ ] ALL tasks in tasks.md show `[X]` (no `[ ]` remaining)
- [ ] Implementation matches specification
- [ ] Tests pass and coverage meets requirements
- [ ] Implementation follows technical plan
- [ ] Ignore files properly configured

---

## Step 2: Generate Summary

```markdown
# Implementation Summary

**Feature**: {{feature_name}}
**Branch**: {{branch}}

## Task Completion

| Phase | Tasks | Completed |
|-------|-------|-----------|
| Setup | [N] | [N] |
| Foundational | [N] | [N] |
| US1 | [N] | [N] |
| US2 | [N] | [N] |
| Polish | [N] | [N] |
| **Total** | [N] | [N] |

## Artifacts Created

- [list of created files]

## Test Status

- Unit tests: [passing/failing]
- Integration tests: [passing/failing]
- Coverage: [X]%
```

---

## Step 3: Report Completion

```text
[ok] Implementation complete

Tasks: [N]/[N] completed
Tests: [status]
Files created: [N]

Suggested commit:
  git add <specific-files> && git commit -m "feat: implement {{feature_name}}"
  # Do NOT use `git add .` — stage files explicitly to avoid committing .env, credentials, or key files
```

**Note:** Next steps are generated by CLI (`emit_complete`) - do not duplicate here.

---

## Error Recovery Notes

**If stopped mid-phase:**

- Check tasks.md for [X] vs [ ]
- Resume from first unchecked task

**If task failed:**

- Fix error in code
- Keep task [ ] until fixed
- Retry and mark [X] on success

**If tests failing:**

- Do NOT mark [X] if tests fail
- Fix implementation or tests
- Re-run until passing

---

## WORKFLOW COMPLETE

Implementation is done. Ready for code review.
