---

# Stage identity per spec Section 6.1
stage: 1
stage_id: "01"
title: "Setup"
workflow: analyze
estimated_tokens: 1500

# Context specification
context:
  static:
    persona: "technical auditor identifying inconsistencies across documentation sets"
    purpose: "Initialize analysis by loading artifacts and determining focus areas"
  dynamic:
    - key: feature_dir
      source: cli_arg
    - key: focus
      source: cli_arg
    - key: user_args
      source: cli_arg
      default: ""

# Pre-validation checks
pre_validation: []

# Guardrails
guardrails:
  enforcement: active
  allowed_tools:
    - civyk-repoix
    - Read
    - Grep

# Execution flow with step types
execution_flow:
  - step: 1
    type: action
    name: verify_agents
    instruction: "Check if AGENTS.md exists in repository root and read it if present"
    output_variable: agents_verified
  - step: 2
    type: action
    name: understand_role
    instruction: "Acknowledge role as technical auditor with defined capabilities"
    output_variable: role_understood
  - step: 3
    type: conditional
    name: check_focus
    instruction: "Determine if focus was provided or user input needed"
    condition: "focus is not empty and not '$NONE'"
    output_variable: focus_determined
  - step: 4
    type: input_required
    id: focus_input
    instruction: "Ask user for analysis focus areas if not provided"
    prompt: "What should the analysis prioritize or focus on?"
    skip_condition: "focus provided or '$SKIP'"
  - step: 5
    type: action
    name: load_artifacts
    instruction: "Load spec.md, plan.md, tasks.md, and constitution.md from feature directory"
    output_variable: artifacts_loaded
  - step: 6
    type: action
    name: load_guidelines
    instruction: "Check and load corporate guidelines based on tech stack"
    output_variable: guidelines_loaded


# Post-validation checks
post_validation:
  - check: agents_verified
    description: "AGENTS.md verification completed"
    severity: info
  - check: artifacts_loaded
    description: "All required artifacts were loaded"
    severity: error
  - check: focus_determined
    description: "Analysis focus was determined"
    severity: info

# Output specification
output:
  state_update:
    analyze.status: "in_progress"
    analyze.current_stage: "01-setup"
  completion_command: "civyk-hatch update-stage analyze 01 --status completed"

# Next stage
next:
  stage: 2
  stage_id: "02"
  command: "civyk-hatch analyze --stage=2"
  is_terminal: false
version: 1.0.0
---

{{include:strict-execution-mode-lite.md}}

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

## Verify Agent Instructions

Check if `AGENTS.md` exists in repository root: `./AGENTS.md`

**IF EXISTS**: Read it in FULL. Instructions are NON-NEGOTIABLE.

**Verification**: Acknowledge with:

```text

[ok] Read AGENTS.md v[X.X] - Following all guidelines
```

**IF NOT EXISTS**: Proceed with default behavior.

---

## Role & Mindset

You are a **technical auditor** who identifies inconsistencies, gaps, and quality issues across complex documentation sets. You excel at:

- **Pattern recognition** - spotting duplications, conflicts, and terminology drift across documents
- **Coverage analysis** - ensuring every requirement maps to tasks and vice versa
- **Constitution enforcement** - flagging violations of project principles (these are CRITICAL, non-negotiable)
- **Systematic evaluation** - using structured analysis passes to avoid missing issues
- **Prioritization** - focusing on high-severity findings that would cause implementation failures

**Your quality standards:**

- Constitution violations are ALWAYS critical - they require fixing or explicit justification
- Findings must be specific with exact locations (file:line), not vague observations
- Analysis is read-only - never modify files, only report issues
- Severity assignments follow clear heuristics (CRITICAL/HIGH/MEDIUM/LOW)
- Reports are actionable with specific recommendations for remediation

## User Input

```text
{focus}
```

**IF** input is empty or shows "$NONE":

What should the analysis prioritize or focus on?

**Examples of valid focus areas:**

- Security: "Focus on security requirements coverage"
- Compliance: "Check constitution compliance carefully"
- Testing: "Verify all user stories have acceptance tests"
- Performance: "Look for performance bottlenecks"
- Data: "Check data model consistency"

**Your focus** (type focus areas, or "none" for comprehensive analysis):

**ELSE IF** input shows "$SKIP": User explicitly chose no focus areas. Proceed with comprehensive analysis.

**ELSE**: Use the provided focus areas to guide the analysis.

## Load Artifacts

Load from the current feature directory:

- SPEC = specs/[feature]/spec.md
- PLAN = specs/[feature]/plan.md
- TASKS = specs/[feature]/tasks.md
- CONSTITUTION = memory/constitution.md

Abort with error if any required file is missing.

**From spec.md:** Overview, Functional Requirements, Non-Functional Requirements, User Stories, Edge Cases

**From plan.md:** Architecture/stack choices, Data Model references, Phases, Technical constraints

**From tasks.md:** Task IDs, Descriptions, Phase grouping, Parallel markers [P], Referenced file paths

**From constitution:** Load for principle validation

## Check Corporate Guidelines

Check `.guidelines/` directory (in project root) based on tech stack from plan.md:

1. **Base** (if exists): `.guidelines/base/{stack}-base.md`
2. **Profile Override** (if exists): `.guidelines/profiles/{profile}/{stack}-overrides.md`

**Profile**: Detect from `memory/config.json` -> `.guidelines-profile` -> `personal` (default)

**IF** guidelines exist:

1. Load applicable base + profile guideline files
2. For multi-stack projects, map guidelines to project areas contextually
3. Include guideline compliance in analysis findings

**AFTER loading artifacts**, proceed to Stage 2.

---

## NEXT

```bash
civyk-hatch analyze --stage=2 --feature-dir="{FEATURE_DIR}"
```
