---

# Stage identity per spec Section 6.1
stage: 4
stage_id: "04"
title: "Complete"
workflow: generate-guidelines
status: EXPERIMENTAL
estimated_tokens: 1000

# Context specification
context:
  static:
    persona: "technical writer providing summary and next steps"
    purpose: "Display summary, handle errors, and provide next steps"
  dynamic:
    - key: tech_stack
      source: state
    - key: guideline_file
      source: state
    - key: analysis_report
      source: state

# Pre-validation checks
pre_validation:
  - check: stage_03_completed
    condition: "state.generate-guidelines.current_stage == '03-generate'"
    message: "Stage 03 (Generate) must be completed first"
    recovery: "civyk-hatch generate-guidelines --stage=3"
  - check: guideline_exists
    condition: "guideline file was created in stage 03"
    message: "Guideline file must exist from stage 03"
    recovery: "civyk-hatch generate-guidelines --stage=3"

# Execution flow with step types
execution_flow:
  - step: 1
    type: action
    name: display_summary
    instruction: "Display comprehensive summary of guideline generation"
    output_variable: summary
  - step: 2
    type: action
    name: provide_next_steps
    instruction: "Provide actionable next steps for the user"
    output_variable: next_steps

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

# Post-validation checks
post_validation:
  - check: summary_displayed
    description: "Summary was displayed to user"
    severity: error

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

{{include:verification-rules.md}}

# Stage 4: Complete

## Purpose

Display summary, handle errors, and provide next steps.

---

## Step 1: Display Summary

```text
[ok] GUIDELINE GENERATION COMPLETE

Generated: .guidelines/{{stack}}-guidelines.md
Version: {{version}} (updated from {{previous_version}})
Update Mode: {{update_mode}}
Backup: {{backup_file}}

Sources Analyzed:
- Documents: {{doc_count}} files
- Reference Projects: {{project_count}} projects
- Total Files Scanned: {{file_count}} files

Principles Extracted:
- From Documents: {{doc_principles}} explicit principles
- From Code: {{code_high}} HIGH confidence, {{code_medium}} MEDIUM confidence
- Total Synthesized: {{total}} principles ({{must}} MUST, {{should}} SHOULD, {{never}} NEVER, {{may}} MAY)

Conflicts Resolved: {{conflict_count}}

Sections Updated:
1. Scaffolding [ok]
2. Package Registry [ok]
3. Mandatory Libraries [ok]
4. Banned Libraries [ok]
5. Architecture [ok]
6. Security [ok]
7. Coding Standards [ok]
8. Dependency Management [ok]
9. Testing [ok]
10. Build & Deployment [ok]
11. Observability [ok]

Analysis Report: .guidelines-analysis/{{stack}}-analysis-report.md
```

---

## Step 2: Provide Next Steps

```text
Next Steps:
1. Review generated guideline: .guidelines/{{stack}}-guidelines.md
2. Review detailed analysis: .guidelines-analysis/{{stack}}-analysis-report.md
3. Commit updated guidelines to version control
4. Share with development teams
5. Update any project-specific constitution if needed
```

---

## Error Recovery

**Note:** If errors occurred during stages 1-3, re-run the failed stage directly. Stage 4 is validation-only and does not perform error recovery.

- Stage 1 errors (sources path, setup): `civyk-hatch generate-guidelines --stage=1`
- Stage 2 errors (tech stack detection, analysis): `civyk-hatch generate-guidelines --stage=2`
- Stage 3 errors (conflict resolution, file writing): `civyk-hatch generate-guidelines --stage=3`

---

## Notes

- RFC 2119 keywords: MUST, SHOULD, MAY, MUST NOT, SHOULD NOT, NEVER
- Version management follows semantic versioning (MAJOR.MINOR.PATCH)
- Multi-stack support: Generate separate guideline files for each detected stack

---

## WORKFLOW COMPLETE

Guideline generation workflow is complete. No further stages.
