---
# Stage identity per spec Section 6.1
stage: 2
stage_id: "02"
title: "Setup"
workflow: tasks
estimated_tokens: 2000

# Context specification
context:
  static:
    persona: "experienced tech lead breaking down features into clear tasks"
    purpose: "Run setup scripts and load design documents"
  dynamic:
    - key: feature_dir
      source: cli_arg
    - key: preferences
      source: cli_arg

# Pre-validation checks
pre_validation:
  - check: stage_01_completed
    condition: "state.tasks.current_stage == '01-initialization'"
    message: "Stage 01 (Initialization) must be completed first"
    recovery: "civyk-hatch tasks --stage=1"

# Execution flow with step types
execution_flow:
  - step: 1
    type: conditional
    name: check_preferences
    instruction: "Check if preferences were provided via CLI"
    condition: "preferences is not empty and preferences != '$NONE' and preferences != '$SKIP'"
  - step: 2
    type: input_required
    id: collect_preferences
    prompt: "Task preferences? (size, grouping, priority)\nExamples: '< 2 hours', 'by user story', 'backend first'\nType 'none' for standard breakdown."
    blocking: true
    condition: "preferences == '$NONE'"
  - step: 3
    type: action
    name: run_setup
    instruction: "Execute civyk-hatch check --json and parse output"
    output_variable: setup_result
  - step: 4
    type: action
    name: load_docs
    instruction: "Load design documents from FEATURE_DIR (plan.md, spec.md, data-model.md, etc.)"
    output_variable: design_docs

# Guardrails
guardrails:
  enforcement: active
  allowed_tools:
    - civyk-repoix
    - Read
    - Bash
    - Glob
  forbidden_actions:
    - "Delete production source files"
    - "Modify source code"
  read_only: true

# Post-validation checks
post_validation:
  - check: setup_executed
    description: "Setup script was executed successfully"
    severity: error
  - check: docs_loaded
    description: "Design documents were loaded"
    severity: error

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

# Next stage
next:
  stage: 3
  stage_id: "03"
  command: "civyk-hatch tasks --stage=3"
  is_terminal: false
version: 1.0.0
---
# Stage 2: Setup

You are a {persona}.

Run setup scripts and load design documents.

---

## Step 1: Collect Preferences

**Arguments provided:**

```text
PREFERENCES: {preferences:$NONE}
```

**IF preferences show "$SKIP"**: User explicitly chose no preferences. Use standard task breakdown by user story with default sizing.

**IF preferences show "$NONE"**: Prompt user:

**[STOP: USER_INPUT_REQUIRED]**

```text
Task preferences? (size, grouping, priority)
Examples: "< 2 hours", "by user story", "backend first"
Type "none" for standard breakdown.
```

Wait for response before proceeding.

**IF preferences have actual value** (not "$NONE" or "$SKIP"): Use them directly and skip prompting.

---

## Step 2: Run Setup Script

Execute from repo root (cross-platform):

```bash
civyk-hatch check --json
```

Parse: `FEATURE_DIR`, `AVAILABLE_DOCS`

---

## Step 3: Load Design Documents

From FEATURE_DIR:

- **Required**: `plan.md` (tech stack, libraries), `spec.md` (user stories)
- **Optional**: `data-model.md`, `contracts/`, `research.md`, `quickstart.md`

Note: Not all projects have all documents. Generate tasks from available docs.

---

## Output

```text

[ok] Setup complete
  - Feature dir: {{feature_dir}}
  - Docs available: [list]
  - Preferences: [N] loaded
```

---

## NEXT

```bash
civyk-hatch tasks --stage=3 --feature-dir="{FEATURE_DIR}"
```

**Note:** State is persisted to `{{feature_dir}}/.state/` throughout the workflow.
