---
stage: script_execution
requires: 01b-input-collection
outputs: file_manifest_generated
version: 3.6.0
estimated_tokens: 2000

guardrails:
  enforcement: active
  allowed_tools:
    - civyk-repoix
    - Read
    - Grep
    - Glob
    - Bash
  forbidden_actions:
    - "Delete any files"
    - "Modify any source files"
  read_only: true
---
# Stage 1C: Project Enumeration via civyk-repoix

## Purpose

Run deterministic discovery scan using civyk-repoix CLI to generate file manifest and technology stack detection.

---

{{include:analyze-state-management.md}}

{{include:analyze-file-write-policy.md}}

---

## AI Context Cache: Session Start

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

At the beginning of analysis, check for existing cached understanding:

```text
# Check what's already cached from previous sessions
understand(action="stats", limit=50)

# If this project was analyzed before:
understand(action="recall", target="project")

# IF found AND fresh: Review cached overview before proceeding
# IF not found OR stale: Proceed with full discovery
```

**Note:** This stage primarily runs CLI commands, not deep file analysis. Full AI cache enforcement applies in stages 02a-02d where source files are read.

---

## Step 1: Run Repoix Scan

Execute the deterministic repoix-scan CLI command:

```bash
civyk-hatch repoix-scan "{project_path}" --analysis-dir "{analysis_dir}"
```

This single command performs:

1. Checks civyk-repoix CLI availability
2. Verifies index is ready
3. Enumerates all indexed files
4. Detects technology stack
5. Gets architectural components

**Outputs:**

- `{data_dir}/repoix-status.json` - civyk-repoix status and discovery cache
- `{data_dir}/file-manifest.json` - File list from index
- `{data_dir}/tech-stack.json` - Detected technology stack

---

**[STOP: ENUMERATION]**

Execute the command and verify output.

**IF successful:** All three JSON files will be created in `{data_dir}/`
**IF fails with "civyk-repoix not available":**

- Install: `pip install civyk-repoix`
- Start daemon: `civyk-repoix daemon start`
- Retry

**IF fails with "Index not ready":**

- Wait for indexing: `civyk-repoix daemon status`
- Retry when status is "ready"

---

## Step 2: Verify Discovery Results

Read the generated files to understand what was discovered:

```bash
# Check repoix status
Read file: {data_dir}/repoix-status.json
```

Verify:

- `mode` is "cli"
- `indexed_files` > 0
- `components` list is populated

```bash
# Check tech stack
Read file: {data_dir}/tech-stack.json
```

Extract for summary:

- `primary_language`
- `frameworks.backend` and `frameworks.frontend`
- `indicators_found`

---

## Step 3: Display Summary

```text
===========================================================
  PROJECT ENUMERATION COMPLETE
===========================================================

  Project: {project_path}
  Analysis Folder: {analysis_dir}

  ---------------------------------------------------------
  CIVYK-REPOIX STATUS
  ---------------------------------------------------------

  Mode: cli (deterministic CLI-based discovery)
  Indexed Files: {count from repoix-status.json}
  Indexed Symbols: {count from repoix-status.json}
  Components: {count from repoix-status.json}

  ---------------------------------------------------------
  TECHNOLOGY STACK DETECTED
  ---------------------------------------------------------

  Primary Language: {from tech-stack.json}
  Backend: {frameworks or "None detected"}
  Frontend: {frameworks or "None detected"}
  Indicators: {list from tech-stack.json}

  ---------------------------------------------------------
  FILES ENUMERATED
  ---------------------------------------------------------

  Total Files: {count from file-manifest.json}

  ---------------------------------------------------------
  ANALYSIS CONFIGURATION
  ---------------------------------------------------------

  Scope: {scope} ({A=Full Application | B=Cross-Cutting})
  {IF scope=B: Concern: {concern_type}}
  {IF scope=B: Migration: {current_impl} -> {target_impl}}

===========================================================
  [ok] civyk-repoix: cli mode
  [ok] File manifest generated
  [ok] Tech stack detected
  [ok] Ready for Stage 2: Category Scan
===========================================================
```

---

## Generated Files

After this stage, the analysis folder structure should be:

```text
{analysis_dir}/
+-- state.json              # Created by CLI (tracks workflow progress)
+-- data/
|   +-- repoix-status.json  # civyk-repoix detection result
|   +-- file-manifest.json  # Generated by civyk-repoix
|   +-- tech-stack.json     # Technology stack detection
+-- reports/                # Empty (reports created in later stages)
```

---

---

## Next Stage

**[AUTO-CONTINUE]** Run the CLI command below NOW. Do NOT generate content without the next stage prompt.

```bash
civyk-hatch analyze-project
```

The CLI auto-detects current stage and emits the next prompt. **Do NOT analyze or generate artifacts until you run this command.**
