---
name: step-00-init
description: Initialize review workflow — locate ba-review.json, detect feature, set variables
next_step: steps/step-01-apply.md
---

# Step 00: Initialize Review

## YOUR TASK

Locate `ba-review.json`, identify the target feature, and initialize variables for step-01-apply.

---

## EXECUTION SEQUENCE

### 1. Locate ba-review.json

```javascript
// Search order:
// 1. Project root: ./ba-review.json
// 2. docs/ subdirectories: docs/**/ba-review.json
const candidates = [
  './ba-review.json',
  ...glob('docs/**/ba-review.json')
];

const review_json_path = candidates.find(p => existsSync(p));
if (!review_json_path) {
  BLOCKING_ERROR("ba-review.json not found. Export it from the interactive HTML document first.");
}
```

### 2. Read Review Metadata

```javascript
const review = readJSON(review_json_path);

// Validate structure
if (!review._reviewMeta) {
  BLOCKING_ERROR("ba-review.json missing _reviewMeta — not a valid review export");
}
if (!review.metadata?.applicationId) {
  BLOCKING_ERROR("ba-review.json missing metadata.applicationId");
}

const application_name = review.metadata.applicationName || review.metadata.applicationId;
const application_id = review.metadata.applicationId;
const source_version = review._reviewMeta.sourceVersion || "1.0";
```

### 3. Locate Feature Docs Directory

```javascript
// Find the matching BA feature directory
const docs_dir = glob(`docs/**/business-analyse/v*/index.json`)
  .map(p => dirname(p))
  .find(dir => {
    const index = readJSON(join(dir, 'index.json'));
    return index.id === application_id || index.metadata?.application === application_name;
  });

if (!docs_dir) {
  BLOCKING_ERROR("Cannot find BA feature directory for application: " + application_name);
}
```

### 4. Verify BA Status

```javascript
const masterIndex = readJSON(join(docs_dir, 'index.json'));
const status = masterIndex.metadata?.status || masterIndex.status;

if (!['consolidated', 'reviewed', 'specified'].includes(status)) {
  BLOCKING_ERROR("Feature status is '" + status + "' — expected 'consolidated', 'reviewed', or 'specified'");
}
```

### 5. Set Variables

```javascript
const workflow_type = "review";

// Variables available to step-01-apply:
// {workflow_type}     = "review"
// {review_json_path}  = path to ba-review.json
// {application_name}  = application display name
// {docs_dir}          = path to BA feature directory
// {source_version}    = version the review was exported from
```

### 6. Display Summary

```
REVIEW INITIALIZED
Application: {application_name}
Review file: {review_json_path}
Source version: {source_version}
Has changes: {review._reviewMeta.hasChanges}
Changes: {review._reviewMeta.changeSummary}
→ Applying corrections...
```

## NEXT STEP

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