---
name: step-00-validate
description: Detect input, validate BA readiness, acceptance criteria gate
model: sonnet
next_step: steps/step-01-transform.md
---

> **Context files:** `references/acceptance-criteria.md` | `references/readiness-scoring.md`

# Step 00: Validate BA Readiness

## MANDATORY EXECUTION RULES

- **ALWAYS** verify status = "consolidated" for all modules before proceeding
- **ALWAYS** validate acceptance criteria (AC-01 to AC-17) per module
- **BLOCKING** if any module has readiness score < 100% on blocking ACs
- **NEVER** proceed to transform if any module fails readiness gate

## YOUR TASK

Detect the BA feature input, verify all modules are consolidated, validate acceptance criteria as a pre-gate, calculate readiness scores, and display the readiness table.

---

## EXECUTION SEQUENCE

### 1. Detect Input

```
IF --feature <path> provided:
  featurePath = <path>
ELSE:
  // Auto-detect from docs/
  Scan docs/ for index.json files with status = "consolidated"
  IF found exactly 1:
    featurePath = found path
  ELSE IF found > 1:
    Display list and ask user to specify --feature <path>
    STOP
  ELSE:
    BLOCKING ERROR: "No consolidated BA feature found. Run /business-analyse first."
    STOP
```

### 2. Load Feature & Verify Consolidation

```
// Determine workflow mode
IF project-level index.json exists:
  projectFeature = ba-reader.findProjectFeature()
  FOR each app in projectFeature.applications:
    appFeature = ba-reader.findFeature(app.featureJsonPath)
    IF appFeature.status !== "consolidated":
      BLOCKING ERROR: "Application {app.code} not consolidated (status: {appFeature.status})"
      → Run /business-analyse step-04 first
  feature = projectFeature
  modules = projectFeature.applications.flatMap(app => app.modules)
ELSE:
  feature = ba-reader.findFeature(featurePath)
  IF feature.status !== "consolidated":
    BLOCKING ERROR: "Feature status: {feature.status}, expected consolidated"
    → Run /business-analyse step-04 first
  modules = feature.modules
```

### 3. Validate Acceptance Criteria Per Module

For **EACH module**, run the acceptance criteria bash script from `references/acceptance-criteria.md`:

```bash
MODULE_JSON="{module_feature_json_path}"
node -e "
const fs = require('fs');
const data = JSON.parse(fs.readFileSync(process.argv[1], 'utf-8'));
// ... (full AC-01 to AC-17 script from references/acceptance-criteria.md)
" "$MODULE_JSON"
```

Collect results per module: PASS count, FAIL count, WARNING count.

### 4. Calculate Readiness Score

> **Reference:** Read `references/readiness-scoring.md` for the full algorithm.

For each module:
- Count blocking ACs passed vs total blocking ACs
- Score = (blocking passed / blocking total) x 100
- Non-blocking score = (non-blocking passed / non-blocking total) x 100

### 5. Apply Readiness Gate

```
FOR each module:
  IF readiness_score < 100%:
    BLOCKING ERROR: "Module {moduleCode} readiness: {score}% — {failed_count} blocking ACs failed"
    Display failed ACs with recovery actions
    → Run /business-analyse to fix, then retry /derive-prd
    STOP

  IF non_blocking_score < 80%:
    WARNING: "Module {moduleCode} non-blocking score: {score}% — consider fixing before handoff"
```

### 6. Display Readiness Table

```
══════════════════════════════════════════════════════════════
  DERIVE-PRD — BA READINESS VALIDATION
══════════════════════════════════════════════════════════════

Feature: {feature_name}
Applications: {app_count} (project mode only)
Modules: {module_count}

┌──────────────┬──────────┬────────────┬──────────────┬────────┐
│ Module       │ Status   │ Blocking   │ Non-blocking │ Ready  │
├──────────────┼──────────┼────────────┼──────────────┼────────┤
│ {module1}    │ consol.  │ 16/16 100% │ 1/1 100%     │ YES    │
│ {module2}    │ consol.  │ 16/16 100% │ 1/1 100%     │ YES    │
└──────────────┴──────────┴────────────┴──────────────┴────────┘

→ All modules READY — proceeding to transform...
══════════════════════════════════════════════════════════════
```

---

## NEXT STEP

Load: `steps/step-01-transform.md`
