---
# Stage identity per spec Section 6.1
stage: 3
stage_id: "03"
title: "Complete"
workflow: clarify
estimated_tokens: 2000

# Context specification
context:
  static:
    persona: "skilled business analyst uncovering hidden assumptions"
    purpose: "Finalize clarification and report results"
  dynamic:
    - key: feature_dir
      source: cli_arg
    - key: spec_path
      source: state

# Pre-validation checks
pre_validation:
  - check: stage_02_completed
    condition: "state.clarify.current_stage == '02-analyze'"
    message: "Stage 02 (Analyze) must be completed first"
    recovery: "civyk-hatch clarify --stage=2"

# Execution flow with step types
execution_flow:
  - step: 1
    type: action
    name: validate_updates
    instruction: "Verify spec updates: Clarifications section, question count, no placeholders, no contradictions"
  - step: 2
    type: action
    name: generate_coverage_report
    instruction: "Generate coverage report showing status of each category (Resolved/Clear/Deferred)"
  - step: 3
    type: action
    name: report_completion
    instruction: "Output completion summary with questions asked, sections updated, outstanding items"

# 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: updates_validated
    description: "Spec updates were validated"
    severity: error
  - check: coverage_reported
    description: "Coverage report was generated"
    severity: info

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

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

# Stage 3: Complete

You are a {persona}.

Finalize clarification and report results.

---

## Step 1: Validate Updates

Verify spec updates:

- [ ] Clarifications section has one bullet per answer
- [ ] Total questions <= 5
- [ ] Updated sections have no lingering placeholders
- [ ] No contradictory statements remain
- [ ] Terminology consistent across sections

---

## Step 2: Generate Coverage Report

```markdown
# Clarification Coverage

| Category | Status |
|----------|--------|
| Functional Scope | [Resolved/Clear/Deferred] |
| Domain & Data | [Resolved/Clear/Deferred] |
| Interaction & UX | [Resolved/Clear/Deferred] |
| Non-Functional | [Resolved/Clear/Deferred] |
| Edge Cases | [Resolved/Clear/Deferred] |

**Resolved**: Was Partial/Missing, now addressed
**Clear**: Already sufficient
**Deferred**: Low impact or better for planning phase
```

---

## Step 3: Report Completion

```text

[ok] Clarification complete

Questions asked: [N]
Sections updated: [list]
Spec path: {spec_path}

Outstanding items: [list or "None"]
```

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

---

## Behavior Notes

- **If no ambiguities found**: Report "No critical ambiguities detected" and suggest proceeding
- **If spec missing**: Instruct user to run `civyk-hatch specify --feature "<desc>"` first
- **Multiple sessions supported**: Can run `civyk-hatch clarify` again later
- **If validation discovers issues** (contradictions, lingering placeholders, inconsistent terminology): This stage is read-only and cannot apply fixes directly. Report all findings clearly and recommend re-running stage 02 to address them:
  ```bash
  civyk-hatch clarify --stage=2 --feature-dir="{FEATURE_DIR}"
  ```

---

## WORKFLOW COMPLETE

Spec is clarified. Proceed to planning.
