---
name: step-00-validate
description: Detect input, validate BA readiness with flat-file support, AC gate
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", "specified", "designed", or "reviewed" for all modules before proceeding
- **ALWAYS** validate **input** acceptance criteria (AC-01 to AC-07) per module
- **ALWAYS** load flat files (entities.json, usecases.json, etc.) from module directories
- **BLOCKING** if any module has readiness score < 100% on input ACs
- **NEVER** proceed to transform if any module fails readiness gate
- **NEVER** check output ACs (AC-08+) here — those are checked after step-01 transform

## YOUR TASK

Detect the BA feature input, verify all modules are consolidated/specified, validate input 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 in ["consolidated", "specified", "designed", "reviewed"]
  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 ready BA feature found (expected status: consolidated, specified, designed, or reviewed). Run /business-analyse first."
    STOP
```

### 2. Load Feature & Resolve Module Paths

```
// Read application-level index.json
appIndex = READ(featurePath/index.json)

// Resolve module directories
// Modules are stored in: docs/{AppCode}/{ModuleCode}/business-analyse/v{X.Y}/
FOR each module in appIndex.modules:
  moduleDir = docs/{appIndex.metadata.applicationCode}/{module.code}/business-analyse/v{version}/
  IF moduleDir/index.json exists:
    module.baDir = moduleDir
  ELSE:
    BLOCKING ERROR: "Module {module.code} directory not found at {moduleDir}"
```

### 3. Verify Module Status

```
FOR each module:
  moduleIndex = READ(module.baDir/index.json)
  IF moduleIndex.metadata.status NOT IN ["consolidated", "specified", "designed", "reviewed"]:
    BLOCKING ERROR: "Module {module.code} status: {status}, expected consolidated, specified, designed, or reviewed"
    -> Run /business-analyse to complete specification first
```

### 4. Load Flat Files Per Module

For each module, load the separate JSON files directly (index.json may not exist at module level):

```javascript
// Load thematic files directly from module directory
const entitiesData = READ(moduleDir + '/entities.json') || {};
const usecasesData = READ(moduleDir + '/usecases.json') || {};
const rulesData = READ(moduleDir + '/rules.json') || {};
const permissionsData = READ(moduleDir + '/permissions.json') || {};
const screensData = READ(moduleDir + '/screens.json') || {};

// NORMALISATION: tolerate ba-writer + LLM field name variants
// See acceptance-criteria.md for the full extraction functions
const moduleData = {
  entities: entitiesData.entities || [],
  hasReferencedEntities: (entitiesData.referencedEntities || []).length > 0,
  useCases: usecasesData.useCases || usecasesData.usecases || [],
  rules: rulesData.rules || rulesData.businessRules || [],
  permissions: extractPermissions(permissionsData),
    // tries: permissionPaths > permissionSet.permissions > basePermissions > actions > permissions
  screens: extractScreens(screensData),
    // tries: screens > sections[].resources > sections > wireframes
};
```

### 5. Validate Input Acceptance Criteria Per Module

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

```bash
MODULE_DIR="{module_ba_dir}"
node -e "
const fs = require('fs');
const path = require('path');
const dir = process.argv[1];
// ... (full input AC script from references/acceptance-criteria.md)
" "$MODULE_DIR"
```

Collect results per module: PASS count, FAIL count.

### 6. Calculate Readiness Score

> **Reference:** See loaded context `readiness-scoring.md` for the full algorithm.

For each module:
- Count input ACs passed vs total (7 input ACs)
- Score = (passed / 7) x 100

### 7. Apply Readiness Gate

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

### 8. Display Readiness Table

```
================================================================
  DERIVE-PRD -- BA READINESS VALIDATION
================================================================

Feature: {feature_name}
Modules: {module_count}

+--------------+----------+-----------+-------+---------+
| Module       | Status   | Score     | Ready | Details |
+--------------+----------+-----------+-------+---------+
| {module1}    | specif.  | 7/7 100%  | YES   | E:2 UC:6 BR:8 S:4 P:5 |
| {module2}    | specif.  | 7/7 100%  | YES   | E:3 UC:8 BR:10 S:6 P:6 |
+--------------+----------+-----------+-------+---------+

-> All modules READY -- proceeding to transform...
================================================================
```

---

## NEXT STEP

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